jt
2021-06-10 5d0d028456874576560552f5a5c4e8b801786f11
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
using HH.Redis.ReisModel;
using HH.WMS.BLL;
using HH.WMS.BLL.Algorithm;
using HH.WMS.BLL.External;
using HH.WMS.BLL.InStock;
using HH.WMS.BLL.MoveStock;
using HH.WMS.BLL.SysMgr;
using HH.WMS.Common;
using HH.WMS.Common.Algorithm;
using HH.WMS.Common.External;
using HH.WMS.Common.Para;
using HH.WMS.Common.Response;
using HH.WMS.DAL;
using HH.WMS.DAL.Algorithm;
using HH.WMS.DAL.Basic;
using HH.WMS.DAL.InStock;
using HH.WMS.Entitys;
using HH.WMS.Entitys.Basic;
using HH.WMS.Entitys.Entitys;
using HH.WMS.Entitys.External;
using HH.WMS.Entitys.MoveStock;
using HH.WMS.TaskService.Dto;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
 
namespace HH.WMS.TaskService.Jobs
{
    /// <summary>
    /// 巨星同步数据(货位、托盘)Job
    /// </summary>
    public class JxSyncDataJob
    {
        private readonly LockDto _lockDto = new LockDto { IsLock = false };
 
        public void Run()
        {
 
            var logPara = LogType.LogPara("巨星同步数据");
            if (_lockDto.IsLock)
            {
                Log.Detail(logPara, "当前同步数据任务正在被锁定,还存在未执行结束的任务");
                return;
            }
            _lockDto.Lock("");
            try
            {
                SyncDataTask(logPara);
            }
            catch (Exception ex)
            {
                Log.Detail(logPara, "异常:" + ex.Message);
 
            }
            _lockDto.Unlock();
        }
 
 
 
        //获取移库管理中未执行的数据,只取一条,且将状态变为执行中
        private void SyncDataTask(LogPara logPara)
        {
 
            List<TN_WM_TASKEntity> lstTasks = BLLCreator.Create<TN_WM_TASKBLL>().GetTask(" AND CN_S_EXT1 = 'NeedSync' ");
            if (lstTasks.Count == 0)
            {
                Log.Detail(logPara, "当前没有需要执行的同步数据!");
                return;
            }
            else
            {
 
                foreach (TN_WM_TASKEntity entity in lstTasks)
                {
 
                    JXJobReference.WebServiceSoapClient jxService = new JXJobReference.WebServiceSoapClient();
                    string returnFromJuxing = jxService.SetAGVJobStatus("GreatStar", "HNWSRFID", entity.CN_S_TRAY_CODE, entity.CN_S_END_BIT, "", "");
 
                    //调用巨星接口回报托盘所入货位及库区
                    if (string.IsNullOrEmpty(returnFromJuxing))
                    {
                        DALCreator.Create<DapperDAL<TN_WM_TASKEntity>>().Update(new
                        {
                            CN_S_EXT1 = "Y"
                        }, new
                        {
                            CN_S_TASK_NO = entity.CN_S_TASK_NO
                        }, null);
                        Log.Detail(logPara, "调用巨星WMS返回结果:" + "调用成功");
                    }
                }
            }
 
        }
 
        private void MoveTrayFromTmpArea(LogPara logPara)
        {
            List<AutoBomStockAreaEntity> lstArea = DALCreator.Create<TN_WMS_AREADAL>().GetAreaCodeByClass("缓存区");
            if (lstArea.Count == 0)
            {
                return;
            }
            List<outAssignLocation> lstCanOutL = DALCreator.Create<Out_AlgorDAL>().GetAssignFlatItemQtyJX(lstArea[0].CN_S_AREA_CODE);
            List<AutoBomLocationAbbreEntity> lstTrueLocation = DALCreator.Create<TN_WMS_LOCATIONDAL>().GetLocationByLocationCode(lstCanOutL.Select(o => o.locationCode).ToList());
            lstCanOutL = lstCanOutL.Join(lstTrueLocation, u => u.locationCode, d => d.CN_S_LOCATION_CODE, (u, d) => new { u, d }).Select(o => new outAssignLocation
            {
                trayCode = o.u.trayCode,
                locationCode = o.u.locationCode,
                stockAreaCode = o.u.stockAreaCode,
                useState = o.u.useState,
                opTime = o.u.opTime,
                productDate = o.u.productDate,
                lotNo = o.u.lotNo,
                CN_S_STOCK_CODE = o.d.CN_S_STOCK_CODE,
                CN_S_ROADWAY = o.d.CN_S_ROADWAY,
                CN_S_ROW = o.d.CN_S_ROW,
                CN_S_COL = o.d.CN_S_COL,
                CN_S_FLOOR = o.d.CN_S_FLOOR,
                CN_S_LOCATION_STATE = o.d.CN_S_LOCATION_STATE
            }).ToList();
            List<TN_WM_LOCATIONCODE_EXT_Entity> locationInLock = DALCreator.Create<TN_WM_LOCATION_EXTDAL>().GetLockLocationByState("", lstArea[0].CN_S_AREA_CODE, null, Constants.Location_State_InLock);
            Log.AlgorInfo("OutAssign-FlatAreaOutLocation", "locationInLock数据:" + JsonConvert.SerializeObject(locationInLock));
            foreach (TN_WM_LOCATIONCODE_EXT_Entity lEntity in locationInLock)
            {
                lstCanOutL.RemoveAll(o => o.CN_S_ROW == lEntity.CN_S_ROW && o.CN_S_COL == lEntity.CN_S_COL);
            }
            lstCanOutL = lstCanOutL.OrderBy(o => o.CN_S_ROW).ThenByDescending(a => a.CN_S_COL).ToList();
            string jxWebUrl = string.Empty;
            foreach (outAssignLocation outAL in lstCanOutL)
            {
                InWorkAreaEntity inWorkAreaEntity = new InWorkAreaEntity();
                inWorkAreaEntity.trayCode = outAL.trayCode;
                inWorkAreaEntity.startBit = outAL.locationCode;
                inWorkAreaEntity.locationGear = "";
                inWorkAreaEntity.endArea = "";
                inWorkAreaEntity.endBit = "";
                inWorkAreaEntity.isTransport = "Y";
                inWorkAreaEntity.needCreateAMSTask = "Y";
                List<InWorkAreaEntity> lstInWork = new List<InWorkAreaEntity>();
                lstInWork.Add(inWorkAreaEntity);
                //调用巨星接口获取入库库区
                DataSet ds = new DataSet();
                string clientKey1 = string.Empty;
                string clientKey2 = string.Empty;
                //调用巨星接口获取托盘入库库区
                try
                {
                    try
                    {
                        jxWebUrl = System.Configuration.ConfigurationManager.AppSettings["jxWebUrl"].ToString();
                    }
                    catch (Exception ep)
                    {
                        ExternalResponse eResponse = new ExternalResponse { success = false, errMsg = "异常:获取webconfig中jxWebUrl配置异常!" + ep.Message };
                        Log.Detail(logPara, "InWorkArea接口返回结果:" + JsonConvert.SerializeObject(eResponse));
                        return;
                    }
                    try
                    {
                        clientKey1 = System.Configuration.ConfigurationManager.AppSettings["clientKey1"].ToString();
                    }
                    catch (Exception ep)
                    {
                        ExternalResponse eResponse = new ExternalResponse { success = false, errMsg = "异常:获取webconfig中clientKey1配置异常!" + ep.Message };
                        Log.Detail(logPara, "InWorkArea接口返回结果:" + JsonConvert.SerializeObject(eResponse));
                        return;
                    }
                    try
                    {
                        clientKey2 = System.Configuration.ConfigurationManager.AppSettings["clientKey2"].ToString();
                    }
                    catch (Exception ep)
                    {
                        ExternalResponse eResponse = new ExternalResponse { success = false, errMsg = "异常:获取webconfig中clientKey2配置异常!" + ep.Message };
                        Log.Detail(logPara, "InWorkArea接口返回结果:" + JsonConvert.SerializeObject(eResponse));
                        return;
                    }
                    WebServiceAgent jxAgent = new WebServiceAgent(jxWebUrl);
                    object[] para = { clientKey1, clientKey2, "AGV", inWorkAreaEntity.trayCode, "", "I", "N", null, null };
                    Log.Detail(logPara, "调用巨星接口获取托盘入库库区输入参数:" + JsonConvert.SerializeObject(para));
                    object returnObject = jxAgent.Invoke("GetJobDetail", para);
                    ds = (DataSet)returnObject;
                    Log.Detail(logPara, "调用巨星接口获取托盘入库库区:" + JsonConvert.SerializeObject(ds));
                    if (ds.Tables[0].Rows.Count == 0)
                    {
                        ExternalResponse eResponse = new ExternalResponse { success = false, errMsg = string.Format("托盘号{0}调用巨星WMS的GetJobDetail未获取到数据!", inWorkAreaEntity.trayCode) };
                        Log.Detail(logPara, "InWorkArea接口返回结果:" + JsonConvert.SerializeObject(eResponse));
                        return;
                    }
                    object[] para1 = { clientKey1, clientKey2, ds.Tables[0].Rows[0]["TrnSeqNo"].ToString(), inWorkAreaEntity.trayCode, "", "80", "8", "hh" };
                    Log.Detail(logPara, "调用巨星接口SetAGVJobStatus输入参数:" + JsonConvert.SerializeObject(para1));
                    object returnObject1 = jxAgent.Invoke("SetAGVJobStatus", para);
                    // HH.WMS.JX.JXWMSServices.WebServiceSoapClient jxServices = new JX.JXWMSServices.WebServiceSoapClient();
                    // jxServices.SetAGVJobStatus("GreatStar", "HNWSRFID", transportTask.CN_S_TRAY_CODE, transportTask.CN_S_END_BIT, "", "");
                    Log.Detail(logPara, "returnFromJuxing,SetAGVJobStatus,8:" + returnObject1.ToString());
                }
                catch (Exception ex)
                {
                    ExternalResponse eResponse = new ExternalResponse { success = false, errMsg = string.Format("调用巨星WMS的GetJobDetail接口异常:{0}!", ex.Message) };
                    Log.Detail(logPara, "InWorkArea接口返回结果:" + JsonConvert.SerializeObject(eResponse));
                    return;
                }
                if (string.IsNullOrEmpty(inWorkAreaEntity.endBit))
                {
                    inWorkAreaEntity.endArea = ds.Tables[0].Rows[0]["ToAreaCode"].ToString();
                    inWorkAreaEntity.remark = ds.Tables[0].Rows[0]["TrnSeqNo"].ToString();
                }
                else
                {
                    inWorkAreaEntity.remark = ds.Tables[0].Rows[0]["TrnSeqNo"].ToString();
                }
                string needCreateAMSTask = string.Empty;
                try
                {
                    needCreateAMSTask = System.Configuration.ConfigurationManager.AppSettings["needCreateAMSTask"].ToString();
                }
                catch (Exception ep)
                {
                    ExternalResponse eResponse = new ExternalResponse { success = false, errMsg = "异常:获取webconfig中needCreateAMSTask配置异常!" + ep.Message };
                    Log.Detail(logPara, "InWorkArea接口返回结果:" + JsonConvert.SerializeObject(eResponse));
                    return;
                }
                inWorkAreaEntity.needCreateAMSTask = needCreateAMSTask;
                List<InWorkAreaEntity> inWorkAreaEntitys = new List<InWorkAreaEntity>();
                inWorkAreaEntitys.Add(inWorkAreaEntity);
                ExternalResponse resultJX = BLLCreator.Create<WmsApiForJxhnBLL>().InWorkAreaJX(inWorkAreaEntitys);
                try
                {
                    if (resultJX.success)
                    {
                        Log.Detail(logPara, "调用巨星WebService接口反馈托盘搬运货位异动");
                        //更新是否传递给巨星任务完成     
                        WebServiceAgent jxAgent = new WebServiceAgent(jxWebUrl);
                        object[] para = { clientKey1, clientKey2, inWorkAreaEntitys[0].remark, resultJX.okList[0].trayCode, resultJX.okList[0].startBit, "", "I", "hh" };
                        object returnObject = jxAgent.Invoke("SetLocation", para);
                    }
                }
                catch (Exception ex)
                {
                    Log.Detail(LogType.LogPara("调用巨星WMS接口反馈状态"), "调用巨星WMS接口反馈托盘搬运货位异动:" + ex.Message + ex.StackTrace);
                }
                string result = JsonConvert.SerializeObject(resultJX);
                if (result.IndexOf("false") > 0)
                {
                    break;
                }
            }
        }
 
    }
}