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;
|
}
|
}
|
}
|
|
}
|
}
|