using Newtonsoft.Json;
|
using OfficeOpenXml.FormulaParsing.Excel.Functions.Logical;
|
using System;
|
using System.Collections.Generic;
|
using System.Threading.Tasks;
|
using System.Xml.Linq;
|
using WIDESEA_Comm;
|
using WIDESEA_Comm.LogInfo;
|
using WIDESEA_Comm.MES_Info;
|
using WIDESEA_Comm.MES_Info.Request;
|
using WIDESEA_Comm.TaskNo;
|
using WIDESEA_Common;
|
using WIDESEA_Core.EFDbContext;
|
using WIDESEA_Core.ManageUser;
|
using WIDESEA_Core.Utilities;
|
using WIDESEA_Entity.DomainModels;
|
using WIDESEA_Entity.DomainModels.Mes;
|
using WIDESEA_WMS.Common;
|
using WIDESEA_WMS.IRepositories;
|
using WIDESEA_WMS.Repositories;
|
using static WIDESEA_Comm.MES_Info.BasicSN;
|
|
namespace WIDESEA_WMS
|
{
|
public partial class ToMesServer
|
{
|
/// <summary>
|
/// PDA移库交接
|
/// </summary>
|
/// <param name="requestTemp"></param>
|
/// <returns></returns>
|
public WebResponseContent agvTransferList(SaveModel saveModel)
|
{
|
|
WebResponseContent content = new WebResponseContent();
|
string postJson = "";
|
string mesData = "";
|
try
|
{
|
string sn = saveModel.MainData["sn"].ToString();
|
string user = saveModel.MainData["creator"].ToString();
|
VOLContext Context = new VOLContext();
|
Idt_stationinfoRepository stationinfoRepository = new dt_stationinfoRepository(Context);
|
Idt_inventoryRepository inventoryRepository = new dt_inventoryRepository(Context);
|
Idt_agvtaskRepository agvtaskRepository = new dt_agvtaskRepository(Context);
|
//return content.Error($"{user}无操作权限!");
|
//工单号生成
|
string jobID = "TW" + DateTime.Now.ToString("HH-mm-ss-ff");
|
|
//根据库存查询车轮信息
|
dt_inventory inventory = inventoryRepository.Find(x => x.SN.Contains(sn)).FirstOrDefault();
|
if (inventory == null)
|
{
|
return content.Error($"无此车轮{sn}SN号,请核查库存记录!");
|
}
|
var station = stationinfoRepository.Find(x => x.stationCode == inventory.stationCode).FirstOrDefault();
|
//if (!station.enable) return content.Error($"库位{station.stationCode}未启用,请核实!");
|
if (agvtaskRepository.Find(x => x.agv_fromaddress == station.stationCode || x.agv_toaddress == station.stationCode).Any())
|
return content.Error($"库位{station.stationCode}存在AGV任务,请核实!");
|
List<detail> list = new List<detail>(); //车轮信息
|
foreach (var item in station.bindSN.Split(","))
|
{
|
detail detail = new detail();
|
detail.sn = item;
|
list.Add(detail);
|
}
|
|
agvTransferListPara listPara = new agvTransferListPara
|
{
|
details = list,
|
transferListID = jobID,// station.Number,
|
toWarehouse = "毛轮库",
|
fromWarehouse = "AGV库",
|
updateTime = DateTime.Now.ToString(),
|
drawingNoVer = inventory.drawingNoVer,
|
materialCode = inventory.materialCode,
|
Operator = user == null ? "admin" : user
|
};
|
|
postJson = JsonConvert.SerializeObject(listPara);
|
mesData = Request.RequestData(postJson, MESAPIAddress.IPAddress_MES + "agvTransferList");
|
if (mesData.Contains("连接尝试失败"))
|
throw new Exception(mesData);
|
var requestMes = JsonConvert.DeserializeObject<MES_Response>(mesData);
|
|
if (requestMes.code == "200" && requestMes.Type == "success")
|
{
|
dt_agvtask agvtask = new dt_agvtask()
|
{
|
agv_fromaddress = station.stationCode,
|
agv_id = Guid.NewGuid(),
|
agv_tasknum = IdenxManager.GetTaskNo("KH-", "WMS"),
|
agv_grade = 1,
|
agv_createtime = DateTime.Now,
|
agv_taskstate = "Queue",
|
agv_materielid = station.stationType,
|
agv_qty = station.quantity,
|
agv_tasktype = "TaskType_OutsourceCarry",
|
agv_toaddress = "",
|
agv_userid = user,//"系统",
|
jobID = jobID,// mes_head.jobID,
|
bindSN = station.bindSN,
|
agv_worktype = 101, //Convert.ToInt32(mes_head.processCode),
|
agv_materbarcode = inventory.materialCode,
|
agv_Traytype = station.tray_type,
|
agv_TrayStatus = station.tray_status
|
};
|
agvtaskRepository.Add(agvtask, true);
|
station.location_state = LocationStateEnum.OutBusy.ToString();
|
stationinfoRepository.Update(station, true);
|
content.OK("下发移库外协成功!");
|
//日志记录上传数据成功
|
WriteWMSLog.LogAdd("", "成功", "MES", "WMS", postJson, mesData, "AB库移库外协", "agvTransferList", requestMes.message);
|
}
|
else
|
throw new Exception(requestMes.message);
|
|
}
|
catch (Exception ex)
|
{
|
content.Error(ex.Message);
|
WriteWMSLog.LogAdd("", "失败", "MES", "WMS", postJson, mesData, "AB库移库外协", "agvTransferList", ex.Message);
|
}
|
return content;
|
}
|
}
|
}
|