Tiandele
2026-03-20 daea1a90c2fa1b5cc2f52e62be15bd95cc4155f6
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
159
160
using AngleSharp.Common;
using Masuit.Tools;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WIDESEA_Common;
using WIDESEA_Common.MES;
using WIDESEA_Common.MES.Request;
using WIDESEA_Core;
using WIDESEA_Core.Const;
using WIDESEA_Core.Enums;
using WIDESEA_Core.Helper;
using WIDESEA_DTO.WMS;
using WIDESEA_Model.Models;
using WIDESEAWCS_BasicInfoService;
using WIDESEAWCS_Model.Models;
 
namespace WIDESEA_StoragIntegrationServices
{
    /// <summary>
    /// 车身绑定工单(焊装直通涂装)
    /// </summary>
    public partial class MESService
    {
        public WebResponseContent pullLock(object jsondata)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                if (string.IsNullOrEmpty(jsondata.ToString())) throw new Exception("请求参数为空");
                Console.WriteLine(jsondata);
                var result = JsonConvert.DeserializeObject<List<pullLockInfo>>(jsondata.ToString());
 
                foreach (var item in result)
                {
                    var assemblyOrderInfo = _assemblyOrderInfoRepository.QueryFirst(x => x.workOrderNo == item.workOrderNo && x.orderType == item.workOrderType);
                    if (assemblyOrderInfo == null) throw new Exception($"拉动锁车失败:未知总装工单号{item.workOrderNo}");
 
                    //Dt_PalletStockInfo carinfo = null;
                    VV_StockInfo OutStock = new VV_StockInfo();
                    //Dt_CarBodyInfo carbodyinfo = null;
                    if (!string.IsNullOrEmpty(item.pvi))
                    {
                        // carinfo = _palletStockInfoRepository.QueryFirst(x => x.PVI == item.pvi && x.pbMaterial == item.pbMaterial);
                        //carbodyinfo = _carBodyRepository.QueryFirst(x => x.pbMaterial == item.pbMaterial && x.PVI == item.pvi);
                        OutStock = _VVStockInfoRepository.QueryFirst(x => x.PVI == item.pvi && x.pbMaterial == item.pbMaterial && x.StockStatus == 0 && x.LockOrder == 0 && x.StayStatus == 0);
                        if (OutStock == null)
                        {
                            throw new Exception($"未找到指定PVI车身信息{item.pvi}");
                        }
                    }
                    else
                    {
                        //carinfo = _palletStockInfoRepository.QueryData(x => x.pbMaterial == item.pbMaterial).OrderBy(x => x.biwInPassTime).FirstOrDefault();
                        //carbodyinfo = _carBodyRepository.QueryData(x => x.pbMaterial == item.pbMaterial && x.BodyStatus == 0).OrderBy(x => x.biwInPassTime).FirstOrDefault();
                        OutStock = _VVStockInfoRepository.QueryData(x => x.pbMaterial == item.pbMaterial && x.StockStatus == 0 && x.LockOrder == 0 && x.StayStatus == 0 && x.workOrderType == item.workOrderType).OrderBy(x => x.biwInPassTime).FirstOrDefault();
                    }
 
                    if (OutStock == null)
                    {
                        throw new Exception("未匹配到车身,拉动锁定失败");
                    }
                    var stockInfo = _palletStockInfoRepository.QueryFirst(x => x.CarBodyInfo.PVI == OutStock.PVI);
 
                    var carBody = _carBodyRepository.QueryFirst(x => x.PVI == OutStock.PVI);
 
                    var lockInfo = _MESLockInfoRepository.QueryData().OrderByDescending(x => x.sequenceNo).FirstOrDefault();
                    int serial = 1;
                    if (lockInfo != null)
                    {
                        serial = lockInfo.sequenceNo + 1;
                    }
 
                    Dt_MESLockInfo mESLockInfo = new Dt_MESLockInfo
                    {
                        carBodyID = stockInfo.carBodyID,
                        CarBodyInfo = carBody,
                        CreateDate = DateTime.Now,
                        Creater = "System",
                        LockStatue = 0,
                        sequenceNo = serial,
                        TCLine = OutStock.RoadwayNo
                    };
 
                    #region 任务下发
                    //Dt_Task task = new Dt_Task()
                    //{
                    //    CreateDate = DateTime.Now,
                    //    Creater = "System",
                    //    CurrentAddress = carinfo.LocationCode,
                    //    Grade = 5,
                    //    PalletCode = carinfo.PalletCode,
                    //    PVI = item.pvi,
                    //    Roadway = carinfo.RoadwayNo,
                    //    SourceAddress = carinfo.LocationCode,
                    //    TaskNum = _taskRepository.GetTaskNo().Result,
                    //    TaskType = (int)TaskOutboundTypeEnum.Outbound,
                    //    TaskState = (int)TaskOutStatusEnum.OutNew,
                    //    TargetAddress = ""
                    //};
 
                    //WMSTaskDTO taskDTO = new WMSTaskDTO()
                    //{
                    //    Grade = task.Grade.Value,
                    //    PalletCode = task.PalletCode,
                    //    SourceAddress = task.SourceAddress,
                    //    TargetAddress = task.TargetAddress,
                    //    RoadWay = task.Roadway,
                    //    TaskState = task.TaskState.Value,
                    //    TaskType = task.TaskType,
                    //    TaskNum = task.TaskNum.Value
                    //};
 
                    //var configs = _configService.GetConfigsByCategory(CateGoryConst.CONFIG_SYS_IPAddress);
                    //var wmsBase = configs.FirstOrDefault(x => x.ConfigKey == SysConfigConst.WCSIPAddress)?.ConfigValue;
                    //var ipAddress = configs.FirstOrDefault(x => x.ConfigKey == SysConfigConst.ReceiveTask)?.ConfigValue;
                    //if (wmsBase == null || ipAddress == null)
                    //{
                    //    throw new InvalidOperationException("WMS IP 未配置");
                    //}
                    //var wmsIpAddress = wmsBase + ipAddress; 
                    #endregion
 
                    _unitOfWorkManage.BeginTran();
                    //var WCSresult = HttpHelper.PostAsync(wmsIpAddress, taskDTO.ToJsonString()).Result;
                    //content = JsonConvert.DeserializeObject<WebResponseContent>(WCSresult);
                    //if (content != null && content.Status)
                    //{
                    stockInfo.StockStatus = 0;
                    stockInfo.LockOrder = 1;
                    carBody.BodyStatus = 1;
 
                    _MESLockInfoRepository.AddData(mESLockInfo);
                    //_taskRepository.AddData(task);
                    _palletStockInfoRepository.UpdateData(stockInfo);
                    //_carBodyRepository.UpdateData(carbodyinfo);
                    _unitOfWorkManage.CommitTran();
                    //}
 
                    LogFactory.GetLog("MES拉动锁车").Info(true, $"\r\r--------------------------------------");
                    LogFactory.GetLog("MES拉动锁车").Info(true, jsondata.ToJsonString());
                    LockResult lockResult = new LockResult { result = "1", lockPvi = carBody.PVI };
                    content.OK(data: lockResult);
                }
            }
            catch (Exception ex)
            {
                LogFactory.GetLog("MES拉动锁车").Info(true, $"锁车失败:{ex.Message};请求参数{jsondata.ToJsonString()}; ");
                _unitOfWorkManage.RollbackTran();
                content.result = "2";
                LockResult result = new LockResult { result = "2", lockPvi = "" };
                content.Error(ex.Message, result);
            }
            return content;
        }
    }
}