using iWareCommon.Utils;
using iWareModel;
using iWareSql.DBModel;
using Newtonsoft.Json;
using System;
using System.Threading.Tasks;
using XiGang.Core.Model;
namespace iWareSql.DataAccess
{
public class MesService
{
public static string xiGang_WMSApi = ConfigHelper.GetConfigString("XiGang_WMSApi");
public static string xiGang_WMSApi_OutStoreToMes = ConfigHelper.GetConfigString("XiGang_WMSApi_OutStoreToMes");
///
/// MES上线接口
///
///
///
public static void UpdateIsNeedOnLineForMainTask(Task_Main mainTask)
{
try
{
if ((mainTask.TaskType == (int)MainTaskTypeEnum.手动出库 || mainTask.TaskType == (int)MainTaskTypeEnum.自动出库)
&& mainTask.MaterialType == (int)MaterialTypeEnum.一般物料)
{//不管是本体机还是改制机,都要给MES推送出库
mainTask.IsNeedOnLine = true;
}
else
{
mainTask.IsNeedOnLine = false;
}
}
catch (Exception ex)
{
Log4NetHelper.WriteErrorLog(LogType.MesService, "UpdateIsNeedOnLineForMainTask出现异常:" + ex.Message, ex);
throw;
}
}
///
/// MES上线接口
///
///
///
public static MesRetModel updateOnlineStatus(Task_Main mainTask)
{
//Task.Run(() =>
//{
return updateOnlineStatusWithNoTask(mainTask);
//});
}
///
/// MES上线接口
///
///
///
public static MesRetModel updateOnlineStatusWithNoTask(Task_Main mainTask)
{
MesRetModel retModel = null;
try
{
if ((mainTask.TaskType == (int)MainTaskTypeEnum.手动出库 || mainTask.TaskType == (int)MainTaskTypeEnum.自动出库)
&& mainTask.MaterialType == (int)MaterialTypeEnum.一般物料)
{//不管是本体机还是改制机,都要给MES推送出库
HTTPService service = new HTTPService(xiGang_WMSApi);
var res = service.postContentForString(xiGang_WMSApi_OutStoreToMes + "?mainId=" + mainTask.Id, "", "");
if (!string.IsNullOrEmpty(res))
{
Log4NetHelper.WriteInfoLog(LogType.MesService, "MES上线接口updateOnlineStatus,传递参数:mainId=" + mainTask.Id + ",接收的返回值res:" + res);
retModel = JsonConvert.DeserializeObject>(res);
}
if (retModel != null)
{
}
else
{
retModel = new MesRetModel()
{
code = 400,
msg = "MES返回为NULL"
};
}
}
else
{
retModel = new MesRetModel()
{
code = 400,
msg = "任务类型不是出库类型,不允许下发给MES上线"
};
}
return retModel;
}
catch (Exception ex)
{
Log4NetHelper.WriteErrorLog(LogType.MesService, "updateOnlineStatus出现异常:" + ex.Message, ex);
retModel = new MesRetModel()
{
code = 400,
msg = "出现异常:" + ex.Message
};
return retModel;
}
}
}
}