using System;
|
using System.Collections.Generic;
|
using System.Text;
|
using WIDESEA_WCS.WCSClient;
|
using WIDESEA_Entity.DomainModels;
|
using WIDESEA_Services.Repositories;
|
using System.Linq;
|
using System.Threading;
|
using WIDESEA_Core.Utilities;
|
using System.Diagnostics;
|
using Quartz.Impl;
|
using WIDESEA_Common.CutomerModel;
|
using WIDESEA_Common;
|
using WIDESEA_Services.IRepositories;
|
using WIDESEA_Common.Tools;
|
using WIDESEA_Services.Services;
|
using WIDESEA_Services;
|
using WIDESEA_Core.EFDbContext;
|
using System.Threading.Tasks;
|
using WIDESEA_WCS.SchedulerExecute;
|
using Newtonsoft.Json;
|
using HslCommunication;
|
using WIDESEA_Core.ManageUser;
|
using WIDESEA_WCS.Jobs;
|
|
namespace WIDESEA_WCS
|
{
|
public class WCSService
|
{
|
public static bool iswlx = true;
|
public static bool choose = true;
|
public static string type = "";
|
/// <summary>
|
/// PLC连接集合
|
/// </summary>
|
public static List<PLCClient> Clients;
|
|
/// <summary>
|
/// PLC连接失败集合
|
/// </summary>
|
public static List<PLCClient> ClientsNoConn;
|
|
/// <summary>
|
/// 调度中心
|
/// </summary>
|
public static ISchedulerCenterServer scheduler;
|
|
/// <summary>
|
/// Job集合
|
/// </summary>
|
static List<JobOptions> jobs = new List<JobOptions>();
|
|
#region 开启服务
|
/// <summary>
|
/// 开启服务
|
/// </summary>
|
/// <returns></returns>
|
public static WebResponseContent StartService()
|
{
|
WebResponseContent responseContent = new WebResponseContent();
|
try
|
{
|
if (!CheckServerState().Status)//开启服务之前检查调度是否已开启及PLC是否已连接
|
{
|
WIDESEA.Helper.GetToken();
|
WebResponseContent content = ConnectServer();
|
if (content.Status)
|
{
|
responseContent = StartSchedule();
|
if (!responseContent.Status)
|
{
|
DisconnectServer();
|
}
|
}
|
else
|
{
|
DisconnectServer();
|
responseContent = content;
|
}
|
}
|
else
|
{
|
responseContent = WebResponseContent.Instance.Error("服务已开启");
|
}
|
}
|
catch (Exception ex)
|
{
|
responseContent = responseContent.Error(ex.Message);
|
}
|
return responseContent;
|
}
|
#endregion
|
|
#region 关闭服务
|
/// <summary>
|
/// 关闭服务(调度及PLC连接)
|
/// </summary>
|
/// <returns></returns>
|
public static WebResponseContent CloseService()
|
{
|
WebResponseContent content = new WebResponseContent();
|
try
|
{
|
if (scheduler != null)
|
{
|
CloseSchedule();
|
DisconnectServer();
|
scheduler = null;
|
content = content.OK();
|
}
|
else
|
{
|
content = WebResponseContent.Instance.Error("任务调度已停止");
|
}
|
}
|
catch (Exception ex)
|
{
|
content = WebResponseContent.Instance.Error(ex.Message);
|
}
|
return content;
|
}
|
#endregion
|
|
#region 检查服务状态
|
/// <summary>
|
/// 检查服务状态
|
/// </summary>
|
/// <returns></returns>
|
public static WebResponseContent CheckServerState()
|
{
|
WebResponseContent content = new WebResponseContent();
|
try
|
{
|
if (scheduler != null && Clients.Any())
|
{
|
content = content.OK(message: "");
|
}
|
else
|
{
|
CloseService();
|
content = content.Error(message: "服务已关闭");
|
}
|
//if (ClientsNoConn!=null && ClientsNoConn.Count>0)
|
//{
|
// foreach (var item in ClientsNoConn)
|
// {
|
// string msg = item.Connect();
|
// if (msg.Contains("连接成功"))
|
// {
|
// ClientsNoConn.Remove(item);
|
// Clients.Add(item);
|
// }
|
// }
|
//}
|
}
|
catch (Exception ex)
|
{
|
content = WebResponseContent.Instance.Error(ex.Message);
|
}
|
return content;
|
}
|
#endregion
|
|
#region 暂停或恢复指定的计划任务
|
/// <summary>
|
/// 暂停或恢复指定的计划任务
|
/// </summary>
|
/// <param name="job"></param>
|
/// <returns></returns>
|
public static WebResponseContent PauseOrResumeJob(SaveModel saveModel)
|
{
|
return dt_equipmentinfoRepository.Instance.DbContextBeginTransaction(() =>
|
{
|
Idt_equipmentinfoRepository repository = new dt_equipmentinfoRepository(new WIDESEA_Core.EFDbContext.VOLContext());
|
dt_equipmentinfo equipmentinfo = repository.FindFirst(x => x.equipment_name == saveModel.MainData["equipNum"].ToString());
|
if (equipmentinfo == null)
|
return WebResponseContent.Instance.Error($"未找到该设备【{saveModel.MainData["equipNum"]}】");
|
if (equipmentinfo.equipment_state == EquipmentState.Enable.ToString())
|
equipmentinfo.equipment_state = EquipmentState.Disenable.ToString();
|
else
|
equipmentinfo.equipment_state = EquipmentState.Enable.ToString();
|
if (dt_equipmentinfoRepository.Instance.Update(equipmentinfo, true) <= 0)
|
return WebResponseContent.Instance.Error("设备状态修改失败");
|
JobOptions options = new JobOptions { JobName = equipmentinfo.equipment_name, JobGroup = equipmentinfo.equipment_type };
|
if (scheduler == null)
|
return WebResponseContent.Instance.OK("设备状态修改成功");
|
|
if (!scheduler.IsExistScheduleJobAsync(options).Result)
|
{
|
return WebResponseContent.Instance.OK("设备状态修改成功");
|
}
|
if (saveModel.MainData["equipStatus"].ToString() == EquipmentState.Enable.ToString())
|
{
|
return scheduler.PauseJob(options).Result;
|
}
|
else
|
{
|
return scheduler.ResumeJob(options).Result;
|
}
|
});
|
|
}
|
#endregion
|
|
#region 开启调度
|
/// <summary>
|
/// 开启调度
|
/// </summary>
|
/// <returns></returns>
|
public static WebResponseContent StartSchedule()
|
{
|
WebResponseContent responseContent = new WebResponseContent();
|
try
|
{
|
StdSchedulerFactory factory = new StdSchedulerFactory();
|
scheduler = new SchedulerCenterServer(factory);
|
List<JobOptions> jobOptions = VV_DispatchRepository.Instance.FindToJobOptions(x => true && x.Enable == EquipmentState.Enable.ToString()
|
&& x.JobName!="正极1号AGV" && x.JobName != "正极2号AGV" && x.JobName != "负极2号AGV" && x.JobGroup != "EquipmentType_Stacker");
|
jobOptions.ForEach(x => { x.JobParams = Clients.Where(y => y.PLCName == x.JobName).FirstOrDefault(); });
|
if (!jobOptions.Any())
|
{
|
responseContent = WebResponseContent.Instance.Error("当前未配置调度");
|
return responseContent;
|
}
|
|
for (int i = 0; i < jobOptions.Count; i++)
|
{
|
WebResponseContent content = scheduler.AddScheduleJobAsync(jobOptions[i]).Result;
|
if (!content.Status)
|
{
|
factory = null;
|
scheduler = null;
|
return content;
|
}
|
}
|
|
responseContent = scheduler.StartScheduleAsync().Result;
|
|
}
|
catch (Exception ex)
|
{
|
responseContent = responseContent.Error(ex.Message);
|
scheduler = null;
|
}
|
return responseContent;
|
}
|
#endregion
|
|
#region 停止调度
|
/// <summary>
|
/// 停止调度
|
/// </summary>
|
/// <returns></returns>
|
public static WebResponseContent CloseSchedule()
|
{
|
WebResponseContent content = new WebResponseContent();
|
try
|
{
|
content = scheduler.StopScheduleAsync().Result;
|
}
|
catch (Exception ex)
|
{
|
content = content.Error(ex.Message);
|
}
|
return content;
|
}
|
#endregion
|
|
#region 连接PLC
|
/// <summary>
|
/// 连接PLC
|
/// </summary>
|
/// <returns></returns>
|
public static WebResponseContent ConnectServer()
|
{
|
WebResponseContent content = new WebResponseContent();
|
try
|
{
|
if (Clients != null)
|
{
|
DisconnectServer();
|
}
|
//if (ClientsNoConn==null)
|
//{
|
// ClientsNoConn = new List<PLCClient>();
|
//}
|
jobs = new List<JobOptions>();
|
jobs = VV_DispatchRepository.Instance.FindJobOptions(x => true);
|
List<string> plcNames = VV_DispatchRepository.Instance.FindToJobOptions(x => true && x.Enable == EquipmentState.Enable.ToString() && x.JobName != "正机2号分切机5012").Select(x => x.JobName).ToList();
|
// List<string> plcNames = VV_DispatchRepository.Instance.FindToJobOptions(v=>).ToList(); http://192.168.12.251:8099
|
if (plcNames.Count == 0)
|
return content = WebResponseContent.Instance.Error("当前无PLC连接配置或设备被禁用");
|
Clients = new List<PLCClient>();
|
|
List<dt_plcinfohead> plcinfoheads = dt_plcinfoheadRepository.Instance.Find(x => plcNames.Contains(x.plcinfo_name));
|
|
foreach (dt_plcinfohead item in plcinfoheads)
|
{
|
PLCClient client = new PLCClient(item.plcinfo_type, item)
|
{
|
PLCName = item.plcinfo_name,
|
PLCDescroption = item.plcinfo_remark,
|
PLCDownLoc = item.plcinfo_down
|
};
|
string msg = client.Connect();
|
if (msg.Contains("连接成功"))
|
{
|
jobs.Where(x => x.JobName == item.plcinfo_name).FirstOrDefault().PLCConnectState = msg;
|
Clients.Add(client);
|
}
|
//else
|
//{
|
// ClientsNoConn.Add(client);
|
//}
|
}
|
content = WebResponseContent.Instance.OK("PLC连接成功!");
|
}
|
catch (Exception ex)
|
{
|
content = WebResponseContent.Instance.Error(ex.Message);
|
Clients = null;
|
}
|
return content;
|
}
|
#endregion
|
|
#region 断开与PLC的连接
|
/// <summary>
|
/// 断开与PLC的连接
|
/// </summary>
|
/// <returns></returns>
|
public static WebResponseContent DisconnectServer()
|
{
|
WebResponseContent content = new WebResponseContent();
|
try
|
{
|
if (Clients.Any() && Clients != null)
|
{
|
for (int i = 0; i < Clients.Count; i++)
|
{
|
Clients[i]?.Disconnect();
|
}
|
content = WebResponseContent.Instance.OK(message: "已断开与PLC的连接!");
|
}
|
else
|
{
|
content = WebResponseContent.Instance.Error("当前与PLC无连接!");
|
}
|
Clients = null;
|
}
|
catch (Exception ex)
|
{
|
content = WebResponseContent.Instance.Error(ex.Message);
|
}
|
return content;
|
}
|
#endregion
|
|
#region ThreadMethod PLC连接内置线程 方法
|
static void Read(PLCClient client)
|
{
|
//Console.Out.WriteLine(client.Read("DB3.0", "INT"));
|
}
|
#endregion
|
|
#region 获取任务触发器状态
|
/// <summary>
|
/// 获取任务触发器状态
|
/// </summary>
|
/// <returns></returns>
|
public static WebResponseContent GetTaskStaus()
|
{
|
WebResponseContent responseContent = new WebResponseContent();
|
List<TaskInfoDto> taskInfoDtos = new List<TaskInfoDto>();
|
if (jobs.FirstOrDefault() == null)
|
jobs = VV_DispatchRepository.Instance.FindJobOptions(x => true);
|
|
for (int i = 0; i < jobs.Count; i++)
|
{
|
List<TaskInfoDto> temp = new List<TaskInfoDto>();
|
if (scheduler == null)
|
{
|
temp = new List<TaskInfoDto>
|
{
|
new TaskInfoDto()
|
{
|
JobId = jobs[i].JobName.ObjToString(),
|
JobGroup = jobs[i].JobGroup,
|
TriggerId = "",
|
TriggerGroup = "",
|
TriggerStatus = "不存在",
|
IsConnected = Clients.Where(x=>x.PLCName == jobs[i].JobName).FirstOrDefault()?.IsConnected??false
|
}
|
};
|
}
|
else
|
{
|
temp = scheduler.GetTaskStaus(jobs[i]).Result;
|
}
|
|
taskInfoDtos.AddRange(temp);
|
}
|
return WebResponseContent.Instance.OK(data: taskInfoDtos);
|
}
|
#endregion
|
|
#region 立即执行 一个任务
|
/// <summary>
|
/// 立即执行 一个任务
|
/// </summary>
|
/// <param name="jobName"></param>
|
/// <returns></returns>
|
public static WebResponseContent ExecuteJobAsync(string jobName)
|
{
|
WebResponseContent result = new WebResponseContent();
|
try
|
{
|
JobOptions job = jobs.Where(x => x.JobName == jobName).FirstOrDefault();
|
if (job == null)
|
{
|
result = WebResponseContent.Instance.Error($"立即执行计划任务失败:未找到该任务计划,任务计划:{jobName}");
|
}
|
else
|
{
|
result = scheduler.ExecuteJobAsync(job).Result;
|
}
|
|
}
|
catch (Exception ex)
|
{
|
result.Message = $"立即执行计划任务失败:【{ex.Message}】";
|
}
|
|
return result;
|
}
|
#endregion
|
|
#region 获取任务触发器状态
|
/// <summary>
|
/// 获取任务触发器状态
|
/// </summary>
|
/// <returns></returns>
|
public static PageGridData<TaskInfoDto> GetPageData()
|
{
|
try
|
{
|
List<TaskInfoDto> taskInfoDtos = new List<TaskInfoDto>();
|
if (jobs.FirstOrDefault() == null)
|
jobs = VV_DispatchRepository.Instance.FindJobOptions(x => true);
|
|
for (int i = 0; i < jobs.Count; i++)
|
{
|
List<TaskInfoDto> temp = new List<TaskInfoDto>();
|
if (scheduler == null)
|
{
|
|
temp = new List<TaskInfoDto>
|
{
|
new TaskInfoDto()
|
{
|
JobId = jobs[i].JobName.ObjToString(),
|
JobGroup = jobs[i].JobGroup,
|
TriggerId = "",
|
TriggerGroup = "",
|
TriggerStatus = "不存在",
|
PLCConnetState = jobs[i].PLCConnectState,
|
IsConnected = false
|
}
|
};
|
}
|
else
|
{
|
temp = scheduler.GetTaskStaus(jobs[i]).Result;
|
if (Clients != null)
|
{
|
for (int j = 0; j < temp.Count; j++)
|
{
|
temp[j].IsConnected = Clients.Where(x => x.PLCName == temp[j].JobId).FirstOrDefault()?.IsConnected ?? false;
|
}
|
}
|
}
|
|
taskInfoDtos.AddRange(temp);
|
}
|
return new PageGridData<TaskInfoDto> { rows = taskInfoDtos, total = taskInfoDtos?.Count ?? 0 };
|
}
|
catch (Exception ex)
|
{
|
return new PageGridData<TaskInfoDto> { rows = null, total = 0, status = 404, msg = ex.Message };
|
}
|
|
}
|
#endregion
|
|
public static JobOptions GetJobOptions(string jobName)
|
{
|
return jobs.Where(x => x.JobName == jobName).FirstOrDefault();
|
}
|
private static int _MESCallLock = 0;
|
public static ResultMaterstateUp Updatestockstate(MESupdateMaterStateRequest request)
|
{
|
WriteLog.Info("更新物料信息MES调我们的接口").Write("开始,缓存架编号:" + request.Devid + "\t" + "物料条码:" + request.BarCode + "\t" + "物料状态:" + request.MaterialStatus + "\t" + DateTime.Now, "更新物料信息");
|
if (Interlocked.Exchange(ref _MESCallLock, 1) == 0)
|
{
|
ResultMaterstateUp result = new ResultMaterstateUp();
|
try
|
{
|
VOLContext Context = new VOLContext();
|
Ibase_ware_locationRepository locRepository = new base_ware_locationRepository(Context);
|
Ibill_group_stockRepository groupRepository = new bill_group_stockRepository(Context);
|
Idt_agvtaskRepository agvRepository = new dt_agvtaskRepository(Context);
|
WebResponseContent responseContent = new WebResponseContent();
|
responseContent = locRepository.DbContextBeginTransaction(() =>
|
{
|
var stockisexist = groupRepository.FindFirst(v=>v.BarCode== request.BarCode);
|
if (stockisexist!=null)
|
{
|
throw new Exception("当前条码已存在库存"+ request.BarCode);
|
}
|
var location = locRepository.FindFirst(v => v.down_code == request.Devid || v.upper_code == request.Devid);
|
if (string.IsNullOrEmpty(request.MaterialStatus))
|
{
|
throw new Exception("物料状态不能为空");
|
}
|
var task = agvRepository.FindFirst(f => f.agv_fromaddress == location.upper_code || f.agv_fromaddress == location.down_code);
|
if (task != null)
|
{
|
result.Message = "该货位有正在进行的任务,不能绑定";
|
result.Code = 1;
|
MESAPIInvoke.GetInterfaceInfo("Updatestockstate", "物料条码:" + request.BarCode, request.Devid, result.Code, result.Message);
|
WriteLog.Info("更新物料信息MES调我们的接口").Write("异常,缓存架编码:" + request.Devid + "\t" + "反馈结果" + result.Code + "\t" + "反馈信息" + result.Message + "\t" + DateTime.Now, "更新物料信息");
|
return WebResponseContent.Instance.Error(result.Message);
|
}
|
var stock = groupRepository.Find(v => v.location_id == location.id).OrderByDescending(v => v.created_time).FirstOrDefault();
|
string materialtype = request.BarCode.Split('*')[2];
|
if (stock == null)
|
{
|
bill_group_stock bill_Group = new bill_group_stock()
|
{
|
first_tb = 1,
|
BarCode = request.BarCode,
|
created_time = DateTime.Now,
|
created_user = "admin",
|
stock_id = new Guid(),
|
location_id = location.id,
|
MaterialType = materialtype,
|
MaterialStatus = request.MaterialStatus,
|
updated_time = DateTime.Now,
|
updated_user = "admin"
|
};
|
if (request.Devid.Contains("JJK"))
|
{
|
bill_Group.FQ_Status = "";
|
bill_Group.GY_Status = "";
|
bill_Group.QX_Status = "";
|
bill_Group.FQ_Status = "";
|
}
|
else
|
{
|
bill_Group.TB_Status = request.Devid.Contains("TB") ? request.MaterialStatus : "nou";
|
bill_Group.GY_Status = request.Devid.Contains("GY") ? request.MaterialStatus : "nou";
|
bill_Group.FQ_Status = request.Devid.Contains("FQ") || request.Devid.Contains("ZZLJ") ? request.MaterialStatus : "nou";
|
bill_Group.QX_Status = request.Devid.Contains("QX") ? request.MaterialStatus : "nou";
|
}
|
groupRepository.Add(bill_Group, true);
|
location.location_state = LocationStateEnum.LocationState_Stored.ToString();
|
locRepository.Update(location, true);
|
for (int i = 0; i < 10; i++)
|
{
|
var st = groupRepository.FindFirst(f => f.BarCode == request.BarCode);
|
WriteLog.Info("货位id").Write(request.Devid + "\t" + st.location_id + "\t" + st.BarCode + "\t" + st.MaterialStatus + "\t" + DateTime.Now, "货位id");
|
if (string.IsNullOrEmpty(st.location_id.ToString()))
|
{
|
st.location_id = location.id;
|
groupRepository.Update(st, true);
|
}
|
if (st.MaterialStatus == "nou")
|
{
|
st.MaterialStatus = request.MaterialStatus;
|
groupRepository.Update(st, true);
|
}
|
else
|
{
|
break;
|
}
|
}
|
}
|
else
|
{
|
if (location.equipment_type == "TBHCJ")
|
{
|
stock.TB_Status = request.MaterialStatus;
|
}
|
else if (location.equipment_type == "GYHCJ" && location.area == "FJSL")
|
{
|
stock.TB_Status = request.MaterialStatus;
|
}
|
else if (location.equipment_type == "GYHCJ" && location.area == "ZJSL")
|
{
|
stock.QX_Status = request.MaterialStatus;
|
}
|
else if (location.equipment_type == "QXHCJ" && location.area == "FJSL")
|
{
|
stock.GY_Status = request.MaterialStatus;
|
}
|
else if (location.equipment_type == "QXHCJ" && location.area == "ZJSL")
|
{
|
stock.TB_Status = request.MaterialStatus;
|
}
|
else if (location.equipment_type == "FQHCJ" && location.area == "FJSL")
|
{
|
stock.QX_Status = request.MaterialStatus;
|
}
|
else if (location.equipment_type == "FQHCJ" && location.area == "ZJSL")
|
{
|
stock.GY_Status = request.MaterialStatus;
|
}
|
else if (location.equipment_type == "ZZLJ")
|
{
|
stock.FQ_Status = request.MaterialStatus;
|
}
|
else if (location.equipment_type == "JJK")
|
{
|
stock.TB_Status = "";
|
stock.FQ_Status = "";
|
stock.QX_Status = "";
|
stock.GY_Status = "";
|
}
|
if (stock.BarCode == request.BarCode)
|
{
|
result.Message = "请不要重复绑定该物料";
|
result.Code = 0;
|
MESAPIInvoke.GetInterfaceInfo("Updatestockstate", "物料条码:" + request.BarCode, request.Devid, result.Code, result.Message);
|
}
|
else
|
{
|
stock.BarCode = request.BarCode;
|
}
|
stock.MaterialStatus = request.MaterialStatus;
|
stock.MaterialType = materialtype;
|
stock.location_id = location.id;
|
stock.created_time = DateTime.Now;
|
stock.updated_time = DateTime.Now;
|
groupRepository.Update(stock, true);
|
for (int i = 0; i < 10; i++)
|
{
|
var st = groupRepository.FindFirst(f => f.BarCode == request.BarCode);
|
WriteLog.Info("货位id").Write(request.Devid + "\t" + st.location_id + "\t" + st.BarCode + "\t" + st.MaterialStatus + "\t" + DateTime.Now, "货位id");
|
if (string.IsNullOrEmpty(st.location_id.ToString()))
|
{
|
st.location_id = location.id;
|
groupRepository.Update(st, true);
|
}
|
if (st.MaterialStatus == "nou")
|
{
|
st.MaterialStatus = request.MaterialStatus;
|
groupRepository.Update(st, true);
|
}
|
else
|
{
|
break;
|
}
|
}
|
location.location_state = LocationStateEnum.LocationState_Stored.ToString();
|
locRepository.Update(location, true);
|
}
|
|
if (location.area == "ZJSL")
|
{
|
PLCClient plc = WCSService.Clients.Find(v => v.PLCName == "正极1号AGV");
|
if (plc == null)
|
{
|
result.Message = "正极1号AGVplc未连接上";
|
result.Code = 1;
|
MESAPIInvoke.GetInterfaceInfo("Updatestockstate", "物料条码:" + request.BarCode, request.Devid, result.Code, result.Message);
|
return WebResponseContent.Instance.Error(result.Message);
|
}
|
if (request.MaterialStatus == "OK")
|
{
|
plc.WriteValue(ConveyorLineInfoDBName.MaterOK.ToString(), request.Devid, 1);
|
}
|
else
|
{
|
plc.WriteValue(ConveyorLineInfoDBName.MaterNG.ToString(), request.Devid, 1);
|
}
|
}
|
else if (location.area == "FJSL")
|
{
|
PLCClient plc = WCSService.Clients.Find(v => v.PLCName == "负极1号AGV");
|
if (plc == null)
|
{
|
result.Message = "负极1号AGVplc未连接上";
|
result.Code = 1;
|
MESAPIInvoke.GetInterfaceInfo("Updatestockstate", "物料条码:" + request.BarCode, request.Devid, result.Code, result.Message);
|
return WebResponseContent.Instance.Error(result.Message);
|
}
|
if (request.MaterialStatus == "OK")
|
{
|
plc.WriteValue(ConveyorLineInfoDBName.MaterOK.ToString(), request.Devid, 1);
|
}
|
else
|
{
|
plc.WriteValue(ConveyorLineInfoDBName.MaterNG.ToString(), request.Devid, 1);
|
}
|
}
|
result.Code = 0;
|
return WebResponseContent.Instance.OK();
|
});
|
if (responseContent.Status == false)
|
{
|
throw new Exception(responseContent.Message);
|
}
|
WriteLog.Info("更新物料信息MES调我们的接口").Write("结束,缓存架编码:" + request.Devid + "\t" + "物料条码" + request.BarCode + "\t" + "物料状态" + request.MaterialStatus + "\t" + "反馈结果" + result.Code + "\t" + "反馈信息" + result.Message + "\t" + DateTime.Now, "更新物料信息");
|
return result;
|
}
|
catch (Exception ex)
|
{
|
result.Message = ex.Message;
|
result.Code = 1;
|
MESAPIInvoke.GetInterfaceInfo("Updatestockstate", "物料条码:" + request.BarCode, request.Devid, result.Code, result.Message);
|
WriteLog.Info("更新物料信息MES调我们的接口").Write("异常,缓存架编码:" + request.Devid + "\t" + "物料条码" + request.BarCode + "\t" + "物料状态" + request.MaterialStatus + "\t" + "反馈结果" + result.Code + "\t" + "反馈信息" + result.Message + "\t" + DateTime.Now, "更新物料信息");
|
}
|
finally
|
{
|
Interlocked.Exchange(ref _MESCallLock, 0);
|
}
|
return result;
|
}
|
else
|
{
|
ResultMaterstateUp result = new ResultMaterstateUp();
|
result.Message = "请勿重复调用";
|
result.Code = 1;
|
MESAPIInvoke.GetInterfaceInfo("Updatestockstate", "物料条码:" + request.BarCode, request.Devid, result.Code, result.Message);
|
WriteLog.Info("更新物料信息MES调我们的接口").Write("异常,缓存架编码:" + request.Devid + "\t" + "物料条码" + request.BarCode + "\t" + "物料状态" + request.MaterialStatus + "\t" + "反馈结果" + result.Code + "\t" + "反馈信息" + result.Message + "\t" + DateTime.Now, "更新物料信息");
|
return result;
|
}
|
}
|
/// <summary>
|
/// MES查看AGV库位状态
|
/// </summary>
|
/// <param name="request"></param>
|
/// <returns></returns>
|
public static List<ResultLocationState> GetLocationState(string Devid)
|
{
|
List<ResultLocationState> result = new List<ResultLocationState>();
|
try
|
{
|
if (Devid != null)
|
{
|
var Id = base_ware_locationRepository.Instance.FindFirst(v => v.down_code == Devid || v.upper_code == Devid);
|
var location = bill_group_stockRepository.Instance.FindFirst(v => v.location_id == Id.id);
|
ResultLocationState content = new ResultLocationState();
|
content.BarCode = location.BarCode;
|
content.MaterialStatus = location.MaterialStatus;
|
content.MaterialType = location.MaterialType;
|
content.Devid = Devid;
|
result.Add(content);
|
}
|
else
|
{
|
var IdList = base_ware_locationRepository.Instance.Find(v => 1 == 1).ToList();
|
for (int i = 0; i < IdList.Count; i++)
|
{
|
ResultLocationState content = new ResultLocationState();
|
var locationList = bill_group_stockRepository.Instance.FindFirst(v => v.location_id == IdList[i].id);
|
if (locationList != null)
|
{
|
content.BarCode = locationList.BarCode;
|
content.MaterialStatus = locationList.MaterialStatus;
|
content.MaterialType = locationList.MaterialType;
|
content.Devid = Devid;
|
}
|
else
|
{
|
content.BarCode = "";
|
content.MaterialStatus = "";
|
content.MaterialType = "";
|
content.Devid = IdList[i].down_code;//暂时不知道给那个
|
}
|
result.Add(content);
|
|
}
|
|
}
|
//
|
//result.Code = 0;
|
}
|
catch (Exception ex)
|
{
|
//result.Code = 1;
|
}
|
return result;
|
}
|
/// <summary>
|
/// 三楼卷绕上料请求逻辑
|
/// </summary>
|
/// <param name="request"></param>
|
/// <returns></returns>
|
public static ResultMaterstateUp Uprequest(UpThreerequest request)
|
{
|
|
VOLContext Context = new VOLContext();
|
ResultMaterstateUp result = new ResultMaterstateUp();
|
Idt_task_numberRepository tasknumberRep = new dt_task_numberRepository(Context);
|
dt_task_numberService tasknumber = new dt_task_numberService(tasknumberRep);
|
Ibase_ware_locationRepository locRepository = new base_ware_locationRepository(Context);
|
Ibase_routing_tableRepository routingRepository = new base_routing_tableRepository(Context);
|
Ibill_pda_groupdiskRepository pdaRepository = new bill_pda_groupdiskRepository(Context);
|
Idt_agvtaskRepository agvRepository = new dt_agvtaskRepository(Context);
|
IJROutBindRepository jrRepository = new JROutBindRepository(Context);
|
Ibill_group_stockRepository groupRepository = new bill_group_stockRepository(Context);
|
try
|
{
|
WriteLog.Info("卷绕上料").Write("开始,请求:" + request.Uprequest + "\t" + "设备编号:" + request.UpequipNo + "\t" + "工单号:" + request.UpbatchNo + DateTime.Now, "卷绕上料");
|
if (request.Uprequest == "1")
|
{
|
PLCClient plc = WCSService.Clients.Find(v => v.PLCName == "正极2号AGV");
|
var task = agvRepository.FindFirst(f => f.agv_toaddress == request.UpequipNo);
|
if (task == null)
|
{
|
string isWork = null;
|
|
//获取上料请求
|
if (request.UpequipNo == "ZJSL-JRSB003" || request.UpequipNo == "ZJSL-JRSB007" || request.UpequipNo == "ZJSL-JRSB010" || request.UpequipNo == "ZJSL-JRSB014" || request.UpequipNo == "ZJSL-JRSB019" || request.UpequipNo == "ZJSL-JRSB023" || request.UpequipNo == "ZJSL-JRSB026" || request.UpequipNo == "ZJSL-JRSB030" || request.UpequipNo == "ZJSL-JRSB035" || request.UpequipNo == "ZJSL-JRSB039")
|
{
|
isWork = plc.ReadValue(ConveyorLineInfoDBName.R_JRSB1_UPrequest.ToString(), request.UpequipNo).ToString();
|
}
|
else if (request.UpequipNo == "ZJSL-JRSB004" || request.UpequipNo == "ZJSL-JRSB008" || request.UpequipNo == "ZJSL-JRSB009" || request.UpequipNo == "ZJSL-JRSB013" || request.UpequipNo == "ZJSL-JRSB020" || request.UpequipNo == "ZJSL-JRSB024" || request.UpequipNo == "ZJSL-JRSB025" || request.UpequipNo == "ZJSL-JRSB029" || request.UpequipNo == "ZJSL-JRSB036" || request.UpequipNo == "ZJSL-JRSB040")
|
{
|
isWork = plc.ReadValue(ConveyorLineInfoDBName.R_JRSB2_UPrequest.ToString(), request.UpequipNo).ToString();
|
}
|
else if (request.UpequipNo == "FJSL-JRSB001" || request.UpequipNo == "FJSL-JRSB005" || request.UpequipNo == "FJSL-JRSB012" || request.UpequipNo == "FJSL-JRSB016" || request.UpequipNo == "FJSL-JRSB017" || request.UpequipNo == "FJSL-JRSB021" || request.UpequipNo == "FJSL-JRSB028" || request.UpequipNo == "FJSL-JRSB032" || request.UpequipNo == "FJSL-JRSB033" || request.UpequipNo == "FJSL-JRSB037")
|
{
|
isWork = plc.ReadValue(ConveyorLineInfoDBName.R_JRSB3_UPrequest.ToString(), request.UpequipNo).ToString();
|
}
|
else if (request.UpequipNo == "FJSL-JRSB002" || request.UpequipNo == "FJSL-JRSB006" || request.UpequipNo == "FJSL-JRSB011" || request.UpequipNo == "FJSL-JRSB015" || request.UpequipNo == "FJSL-JRSB018" || request.UpequipNo == "FJSL-JRSB022" || request.UpequipNo == "FJSL-JRSB027" || request.UpequipNo == "FJSL-JRSB031" || request.UpequipNo == "FJSL-JRSB034" || request.UpequipNo == "FJSL-JRSB038")
|
{
|
isWork = plc.ReadValue(ConveyorLineInfoDBName.R_JRSB4_UPrequest.ToString(), request.UpequipNo).ToString();
|
}
|
WriteLog.Info("卷绕上料口请求").Write(request.UpequipNo + "\t" + isWork + DateTime.Now, "卷绕上料口请求");
|
if (bool.Parse(isWork))
|
{
|
dt_agvtask agvtask = new dt_agvtask
|
{
|
agv_barcode = "",
|
agv_code = "正极2号AGV",
|
agv_createtime = DateTime.Now,
|
agv_fromaddress = "nou",
|
agv_grade = 1,
|
agv_materbarcode = "daiding",
|
agv_qty = 1,
|
agv_tasknum = "KH-" + tasknumber.GetTaskNumber(tasknumberRep),
|
agv_taskstate = "WaitStockOut",
|
agv_tasktype = "TaskType_Outbound",
|
agv_toaddress = request.UpequipNo,
|
agv_userid = "WCS",
|
agv_worktype = 1,
|
agv_materielid = request.UpbatchNo
|
};
|
List<string> StockList = new List<string> { "ZJXL-FBT001", "ZJXL-FBT002" };
|
MESback WMSbackresult = MESAPIInvoke.OutNeedStosk(agvtask.agv_tasknum, StockList, 4, request.UpbatchNo, "", agvtask.agv_toaddress);
|
if (WMSbackresult == null)
|
{
|
result.Code = 1;
|
result.Message = WMSbackresult.Message;
|
WriteLog.Info("卷绕上料").Write(request.UpequipNo + "要料失败" + WMSbackresult.Message + "\t" + DateTime.Now, "卷绕上料");
|
return result;
|
}
|
agvRepository.Add(agvtask, true);
|
result.Code = 0;
|
result.MaterialType = request.UpbatchNo;
|
result.BarCode = null;
|
WriteLog.Info("卷绕上料").Write("结束,任务号:" + agvtask.agv_tasknum + "\t" + "请求:" + request.Uprequest + "\t" + "设备编号:" + request.UpequipNo + "\t" + "工单号:" + request.UpbatchNo + "\t" + DateTime.Now, "卷绕上料");
|
}
|
else
|
{
|
result.Code = 1;
|
result.Message = "上料口请求是:" + isWork;
|
WriteLog.Info("卷绕上料").Write("结束,请求:" + request.Uprequest + "\t" + "设备编号:" + request.UpequipNo + "\t" + "工单号:" + request.UpbatchNo + "\t" + "上料口请求:" + isWork + DateTime.Now, "卷绕上料");
|
return result;
|
}
|
}
|
}
|
}
|
catch (Exception ex)
|
{
|
result.Code = 1;
|
result.Message = ex.Message;
|
WriteLog.Info("卷绕上料").Write("异常,请求:" + request.Uprequest + "\t" + "设备编号:" + request.UpequipNo + "\t" + "工单号:" + request.UpbatchNo + "\t" + "反馈结果:" + result.Code + "\t" + "反馈信息:" + result.Message + "\t" + DateTime.Now, "卷绕上料");
|
MESAPIInvoke.GetInterfaceInfo("Uprequest", request.Uprequest, request.UpequipNo, result.Code, result.Message);
|
}
|
return result;
|
}
|
/// <summary>
|
/// 入库物料确认搬走
|
/// </summary>
|
/// <param name="request"></param>
|
/// <returns></returns>
|
public static ResultMaterstateUp InStockMaterMove(MEStockMaterMoveRequest request)
|
{
|
VOLContext Context = new VOLContext();
|
ResultMaterstateUp result = new ResultMaterstateUp();
|
Ibase_ware_locationRepository locRepository = new base_ware_locationRepository(Context);
|
Ibill_group_stockRepository groupRepository = new bill_group_stockRepository(Context);
|
try
|
{
|
WriteLog.Info("入库物料确认搬走MES调我们的接口").Write("开始,缓存架编号:" + request.Devid + "\t" + "物料类型:" + request.MaterialType + "\t" + DateTime.Now, "入库物料确认搬走");
|
var location = locRepository.FindFirst(v => v.upper_code == request.Devid || v.down_code == request.Devid);
|
if (location == null)
|
{
|
result.Code = 0;
|
MESAPIInvoke.GetInterfaceInfo("InStockMaterMove", "物料类型:" + request.MaterialType, request.Devid, result.Code, result.Message);
|
WriteLog.Info("入库物料确认搬走MES调我们的接口结束").Write("结束,缓存架编号:" + request.Devid + "\t" + "物料类型:" + request.MaterialType + "\t" + "反馈结果:" + result.Code + "\t" + "反馈信息" + result.Message + "\t" + DateTime.Now, "入库物料确认搬走");
|
return result;
|
}
|
location.location_state = LocationStateEnum.LocationState_Empty.ToString();
|
location.created_time = DateTime.Now;
|
locRepository.Update(location, true);
|
var stock = groupRepository.FindFirst(v => v.MaterialType == request.MaterialType && v.location_id == location.id);
|
if (stock == null)
|
{
|
result.Code = 0;
|
MESAPIInvoke.GetInterfaceInfo("InStockMaterMove", "物料类型:" + request.MaterialType, request.Devid, result.Code, result.Message);
|
WriteLog.Info("入库物料确认搬走MES调我们的接口结束").Write("结束,缓存架编号:" + request.Devid + "\t" + "物料类型:" + request.MaterialType + "\t" + "反馈结果:" + result.Code + "\t" + "反馈信息" + result.Message + "\t" + DateTime.Now, "入库物料确认搬走");
|
return result;
|
}
|
stock.location_id = null;
|
groupRepository.Update(stock, true);
|
result.Code = 0;
|
MESAPIInvoke.GetInterfaceInfo("InStockMaterMove", "物料类型:" + request.MaterialType, request.Devid, result.Code, result.Message);
|
WriteLog.Info("入库物料确认搬走MES调我们的接口结束").Write("结束,缓存架编号:" + request.Devid + "\t" + "物料类型:" + request.MaterialType + "\t" + "反馈结果:" + result.Code + "\t" + "反馈信息" + result.Message + "\t" + DateTime.Now, "入库物料确认搬走");
|
}
|
catch (Exception ex)
|
{
|
result.Code = 1;
|
result.Message = ex.Message;
|
MESAPIInvoke.GetInterfaceInfo("InStockMaterMove", "物料类型:" + request.MaterialType, request.Devid, result.Code, result.Message);
|
WriteLog.Info("入库物料确认搬走MES调我们的接口异常").Write("异常,缓存架编号:" + request.Devid + "\t" + "物料类型:" + request.MaterialType + "\t" + "反馈结果:" + result.Code + "\t" + "反馈信息" + result.Message + "\t" + DateTime.Now, "入库物料确认搬走");
|
}
|
return result;
|
}
|
|
/// <summary>
|
/// 出库物料绑定 UpdateAGVTaskState
|
/// </summary>
|
/// <param name="request"></param>
|
/// <returns></returns>
|
public static ResultMaterstateUp OutStockMaterBind(MEStockMaterBindRequest request)
|
{
|
VOLContext Context = new VOLContext();
|
ResultMaterstateUp result = new ResultMaterstateUp();
|
Ibase_ware_locationRepository locRepository = new base_ware_locationRepository(Context);
|
Ibill_group_stockRepository groupRepository = new bill_group_stockRepository(Context);
|
Idt_agvtaskRepository agvRepository = new dt_agvtaskRepository(Context);
|
Idt_task_numberRepository tasknumberRep = new dt_task_numberRepository(Context);
|
IJROutBindRepository jrRepository = new JROutBindRepository(Context);
|
dt_task_numberService tasknumber = new dt_task_numberService(tasknumberRep);
|
try
|
{//2293.0
|
//WriteLog.Info("出库物料绑定MES调我们的接口").Write("开始,任务号:" + request.TaskID + "\t" + "物料类型:" + request.MaterialType + "\t" + "物料状态" + request.MaterialStatus + "\t" + "物料条码" + request.BarCode + "\t" + "缓存架编号:" + request.Devid + "\t" + request.CacheDevid + "\t" + choose + "\t" + type + "\t" + DateTime.Now, "出库物料绑定");
|
WriteLog.Info("出库物料绑定").Write($"\n{DateTime.Now}开始,{JsonConvert.SerializeObject(request)}\n", "出库物料绑定");
|
if (string.IsNullOrEmpty(request.TaskID))
|
{
|
dt_agvtask task = new dt_agvtask();
|
if (request.MaterialType == "空托盘")
|
{
|
PLCClient plc = WCSService.Clients.Find(v => v.PLCName == "正极提升机");
|
if (request.Devid.Contains("Z") && (choose == true || type == "空托盘"))
|
{
|
//空盘物流线001DB1002.1893.0 BOOL
|
string isZWork = plc.ReadValue(ConveyorLineInfoDBName.R_ZKPHLXLocation.ToString(), plc.PLCDescroption).ToString();
|
WriteLog.Info("空盘回流线的请求").Write("正极:" + isZWork + "物料条码" + request.BarCode + "\t" + "缓存架编号:" + request.Devid + "\t" + DateTime.Now, "空盘回流线的请求");
|
if (isZWork == "False")
|
{
|
choose = false;
|
type = request.MaterialType;
|
result.Code = 1;
|
result.Message = "正极空盘回流线没有请求";
|
MESAPIInvoke.GetInterfaceInfo("OutStockMaterBind", request.TaskID, request.Devid, result.Code, result.Message + "choose:" + choose + "type" + type);
|
WriteLog.Info("出库物料绑定MES调我们的接口").Write("结束," + "物料类型:" + request.MaterialType + "\t" + "物料状态" + request.MaterialStatus + "\t" + "物料条码" + request.BarCode + "\t" + "缓存架编号:" + request.Devid + "\t" + request.CacheDevid + "\t" + "反馈结果:" + result.Code + "\t" + "反馈信息:" + result.Message + "\t" + type + "\t" + DateTime.Now, "出库物料绑定");
|
return result;
|
}
|
|
//DB1002.93.0 BOOL
|
string ZWLXWork = plc.ReadValue(ConveyorLineInfoDBName.R_ZWLX2_UPrequest.ToString(), plc.PLCDescroption).ToString();
|
SchedulerExecuteBase.GetEquipmentInfo("WLX002", "正极物流线上料请求:" + ZWLXWork, "", "", "");
|
//获取空盘回流线负极货位是否有料
|
if (bool.Parse(ZWLXWork))
|
{
|
if (request.CacheDevid.Substring(0, 2) == "ZJ")
|
{
|
OperateResult<bool> isWork = plc.SiemensPLCClient.SiemensS7NetClient.ReadBool("DB1.102.1");
|
if (!isWork.Content)
|
{
|
WriteLog.Info("出库物料绑定").Write($"\n{DateTime.Now}开始:Z正极DB1.102.1结果为" + isWork.Content, "出库物料绑定");
|
result.Code = 1;
|
result.Message = "当前提升机有货";
|
return result;
|
}
|
var tasks = agvRepository.FindFirst(f => f.agv_toaddress == "ZJSL-WLX002" && f.agv_fromaddress == "ZJXL-KPHLX001");
|
if (tasks != null)
|
{
|
choose = false;
|
type = request.MaterialType;
|
result.Code = 1;
|
result.Message = "AGV有正极物流线的任务";
|
MESAPIInvoke.GetInterfaceInfo("OutStockMaterBind", request.TaskID, request.Devid, result.Code, result.Message + "choose:" + choose + "type" + type);
|
WriteLog.Info("出库物料绑定MES调我们的接口").Write("结束,任务号:" + task.agv_tasknum + "\t" + "物料类型:" + request.MaterialType + "\t" + "物料状态" + request.MaterialStatus + "\t" + "物料条码" + request.BarCode + "\t" + "缓存架编号:" + request.Devid + "\t" + request.CacheDevid + "\t" + "反馈结果:" + result.Code + "\t" + "反馈信息:" + result.Message + "\t" + type + "\t" + DateTime.Now, "出库物料绑定");
|
return result;
|
}
|
task = new dt_agvtask
|
{
|
agv_fromaddress = "ZJXL-KPHLX001",
|
agv_toaddress = "ZJSL-WLX002"
|
};
|
}
|
else if (request.CacheDevid.Substring(0, 2) == "FJ")
|
{
|
OperateResult<bool> isWork = plc.SiemensPLCClient.SiemensS7NetClient.ReadBool("DB1.114.1");
|
if (!isWork.Content)
|
{
|
WriteLog.Info("出库物料绑定").Write($"\n{DateTime.Now}开始:Z负极DB1.114.1结果为" + isWork.Content, "出库物料绑定");
|
result.Code = 1;
|
result.Message = "当前提升机有货";
|
return result;
|
}
|
var tasks = agvRepository.FindFirst(f => f.agv_toaddress == "FJSL-WLX002" && f.agv_fromaddress == "ZJXL-KPHLX001");
|
if (tasks != null)
|
{
|
choose = false;
|
type = request.MaterialType;
|
result.Code = 1;
|
result.Message = "AGV有负极物流线的任务";
|
MESAPIInvoke.GetInterfaceInfo("OutStockMaterBind", request.TaskID, request.Devid, result.Code, result.Message + "choose:" + choose + "type" + type);
|
WriteLog.Info("出库物料绑定MES调我们的接口").Write("结束,任务号:" + task.agv_tasknum + "\t" + "物料类型:" + request.MaterialType + "\t" + "物料状态" + request.MaterialStatus + "\t" + "物料条码" + request.BarCode + "\t" + "缓存架编号:" + request.Devid + "\t" + request.CacheDevid + "\t" + "反馈结果:" + result.Code + "\t" + "反馈信息:" + result.Message + "\t" + type + "\t" + DateTime.Now, "出库物料绑定");
|
return result;
|
}
|
task = new dt_agvtask
|
{
|
agv_fromaddress = "ZJXL-KPHLX001",
|
agv_toaddress = "FJSL-WLX002"
|
};
|
}
|
task.agv_materielid = request.MaterialType;
|
task.agv_qty = 1;
|
task.agv_tasknum = "KH-" + tasknumber.GetTaskNumber(tasknumberRep);
|
task.agv_grade = 1;
|
task.agv_materbarcode = "";
|
task.agv_barcode = "";
|
task.agv_code = "负极2号AGV";
|
task.agv_createtime = DateTime.Now;
|
task.agv_taskstate = "Create";
|
task.agv_tasktype = "TaskType_Outbound";
|
task.agv_userid = "WCS";
|
task.agv_worktype = 2;
|
agvRepository.Add(task, true);
|
choose = true;
|
type = "";
|
result.Code = 0;
|
MESAPIInvoke.GetInterfaceInfo("OutStockMaterBind", request.TaskID, request.Devid, result.Code, result.Message + "choose:" + choose + "type" + type);
|
WriteLog.Info("出库物料绑定MES调我们的接口").Write("结束,任务号:" + task.agv_tasknum + "\t" + "物料类型:" + request.MaterialType + "\t" + "物料状态" + request.MaterialStatus + "\t" + "物料条码" + request.BarCode + "\t" + "缓存架编号:" + request.Devid + "\t" + request.CacheDevid + "\t" + "反馈结果:" + result.Code + "\t" + "反馈信息:" + result.Message + "\t" + DateTime.Now, "出库物料绑定");
|
}
|
else
|
{
|
choose = false;
|
type = request.MaterialType;
|
result.Code = 1;
|
result.Message = "物流线没有请求";
|
MESAPIInvoke.GetInterfaceInfo("OutStockMaterBind", request.TaskID, request.Devid, result.Code, result.Message + "choose:" + choose + "type" + type);
|
WriteLog.Info("出库物料绑定MES调我们的接口").Write("结束,任务号:" + task.agv_tasknum + "\t" + "物料类型:" + request.MaterialType + "\t" + "物料状态" + request.MaterialStatus + "\t" + "物料条码" + request.BarCode + "\t" + "缓存架编号:" + request.Devid + "\t" + request.CacheDevid + "\t" + "反馈结果:" + result.Code + "\t" + "反馈信息:" + result.Message + "\t" + type + "\t" + DateTime.Now, "出库物料绑定");
|
}
|
}
|
else if (request.Devid.Contains("F") && (choose == true || type == "空托盘"))
|
{
|
//DB1002.2293.0 BOOL
|
string isZWork = plc.ReadValue(ConveyorLineInfoDBName.R_FKPHLXLocation.ToString(), plc.PLCDescroption).ToString();
|
WriteLog.Info("空盘回流线的请求").Write("负极:" + isZWork + "物料条码" + request.BarCode + "\t" + "缓存架编号:" + request.Devid + "\t" + DateTime.Now, "空盘回流线的请求");
|
if (isZWork == "False")
|
{
|
choose = false;
|
type = request.MaterialType;
|
result.Code = 1;
|
result.Message = "负极空盘回流线没有请求";
|
MESAPIInvoke.GetInterfaceInfo("OutStockMaterBind", request.TaskID, request.Devid, result.Code, result.Message + "choose:" + choose + "type" + type);
|
WriteLog.Info("出库物料绑定MES调我们的接口").Write("结束," + "物料类型:" + request.MaterialType + "\t" + "物料状态" + request.MaterialStatus + "\t" + "物料条码" + request.BarCode + "\t" + "缓存架编号:" + request.Devid + "\t" + request.CacheDevid + "\t" + "反馈结果:" + result.Code + "\t" + "反馈信息:" + result.Message + "\t" + type + "\t" + DateTime.Now, "出库物料绑定");
|
return result;
|
}
|
//DB1002.1293.0 BOOL
|
string FWLXWork = plc.ReadValue(ConveyorLineInfoDBName.R_FWLX2_UPrequest.ToString(), plc.PLCDescroption).ToString();
|
SchedulerExecuteBase.GetEquipmentInfo("WLX002", "负极物流线上料请求:" + FWLXWork, "", "", "");
|
//获取空盘回流线负极货位是否有料
|
if (bool.Parse(FWLXWork))
|
{
|
if (request.CacheDevid.Substring(0, 2) == "ZJ")
|
{
|
OperateResult<bool> isWork = plc.SiemensPLCClient.SiemensS7NetClient.ReadBool("DB1.102.1");
|
if (!isWork.Content)
|
{
|
WriteLog.Info("出库物料绑定").Write($"\n{DateTime.Now}开始:F正极DB1.102.1结果为" + isWork.Content, "出库物料绑定");
|
result.Code = 1;
|
result.Message = "当前提升机有货";
|
return result;
|
}
|
var tasks = agvRepository.FindFirst(f => f.agv_toaddress == "ZJSL-WLX002" && f.agv_fromaddress== "FJXL-KPHLX001");
|
if (tasks != null)
|
{
|
choose = false;
|
type = request.MaterialType;
|
result.Code = 1;
|
result.Message = "AGV有正极物流线的任务";
|
MESAPIInvoke.GetInterfaceInfo("OutStockMaterBind", request.TaskID, request.Devid, result.Code, result.Message + "choose:" + choose + "type" + type);
|
WriteLog.Info("出库物料绑定MES调我们的接口").Write("结束,任务号:" + task.agv_tasknum + "\t" + "物料类型:" + request.MaterialType + "\t" + "物料状态" + request.MaterialStatus + "\t" + "物料条码" + request.BarCode + "\t" + "缓存架编号:" + request.Devid + "\t" + request.CacheDevid + "\t" + "反馈结果:" + result.Code + "\t" + "反馈信息:" + result.Message + "\t" + type + "\t" + DateTime.Now, "出库物料绑定");
|
return result;
|
}
|
task = new dt_agvtask
|
{
|
agv_fromaddress = "FJXL-KPHLX001",
|
agv_toaddress = "ZJSL-WLX002"
|
};
|
}
|
else if (request.CacheDevid.Substring(0, 2) == "FJ")
|
{
|
OperateResult<bool> isWork = plc.SiemensPLCClient.SiemensS7NetClient.ReadBool("DB1.114.1");
|
if (!isWork.Content)
|
{
|
WriteLog.Info("出库物料绑定").Write($"\n{DateTime.Now}开始:F正极DB1.114.1结果为" + isWork.Content, "出库物料绑定");
|
result.Code = 1;
|
result.Message = "当前提升机有货";
|
return result;
|
}
|
var tasks = agvRepository.FindFirst(f => f.agv_toaddress == "FJSL-WLX002" && f.agv_fromaddress == "FJXL-KPHLX001");
|
if (tasks != null)
|
{
|
choose = false;
|
type = request.MaterialType;
|
result.Code = 1;
|
result.Message = "AGV有负极物流线的任务";
|
MESAPIInvoke.GetInterfaceInfo("OutStockMaterBind", request.TaskID, request.Devid, result.Code, result.Message + "choose:" + choose + "type" + type);
|
WriteLog.Info("出库物料绑定MES调我们的接口").Write("结束,任务号:" + task.agv_tasknum + "\t" + "物料类型:" + request.MaterialType + "\t" + "物料状态" + request.MaterialStatus + "\t" + "物料条码" + request.BarCode + "\t" + "缓存架编号:" + request.Devid + "\t" + request.CacheDevid + "\t" + "反馈结果:" + result.Code + "\t" + "反馈信息:" + result.Message + "\t" + type + "\t" + DateTime.Now, "出库物料绑定");
|
return result;
|
}
|
task = new dt_agvtask
|
{
|
agv_fromaddress = "FJXL-KPHLX001",
|
agv_toaddress = "FJSL-WLX002"
|
};
|
}
|
task.agv_materielid = request.MaterialType;
|
task.agv_qty = 1;
|
task.agv_tasknum = "KH-" + tasknumber.GetTaskNumber(tasknumberRep);
|
task.agv_grade = 1;
|
task.agv_materbarcode = "";
|
task.agv_barcode = "";
|
task.agv_code = "负极2号AGV";
|
task.agv_createtime = DateTime.Now;
|
task.agv_taskstate = "Create";
|
task.agv_tasktype = "TaskType_Outbound";
|
task.agv_userid = "WCS";
|
task.agv_worktype = 2;
|
agvRepository.Add(task, true);
|
choose = true;
|
type = "";
|
result.Code = 0;
|
MESAPIInvoke.GetInterfaceInfo("OutStockMaterBind", request.TaskID, request.Devid, result.Code, result.Message + "choose:" + choose + "type" + type);
|
WriteLog.Info("出库物料绑定MES调我们的接口").Write("结束,任务号:" + task.agv_tasknum + "\t" + "物料类型:" + request.MaterialType + "\t" + "物料状态" + request.MaterialStatus + "\t" + "物料条码" + request.BarCode + "\t" + "缓存架编号:" + request.Devid + "\t" + request.CacheDevid + "\t" + "反馈结果:" + result.Code + "\t" + "反馈信息:" + result.Message + "\t" + DateTime.Now, "出库物料绑定");
|
}
|
else
|
{
|
choose = false;
|
type = request.MaterialType;
|
result.Code = 1;
|
result.Message = "物流线没有请求 ";
|
MESAPIInvoke.GetInterfaceInfo("OutStockMaterBind", request.TaskID, request.Devid, result.Code, result.Message + "choose:" + choose + "type" + type);
|
WriteLog.Info("出库物料绑定MES调我们的接口").Write("结束,任务号:" + task.agv_tasknum + "\t" + "物料类型:" + request.MaterialType + "\t" + "物料状态" + request.MaterialStatus + "\t" + "物料条码" + request.BarCode + "\t" + "缓存架编号:" + request.Devid + "\t" + request.CacheDevid + "\t" + "反馈结果:" + result.Code + "\t" + "反馈信息:" + result.Message + "\t" + type + "\t" + DateTime.Now, "出库物料绑定");
|
}
|
}
|
}
|
else if (request.MaterialType == "隔膜空托盘")
|
{
|
PLCClient tsjplc = WCSService.Clients.Find(v => v.PLCName == "正极提升机");
|
if (request.Devid.Contains("Z") && (choose == true || type == "隔膜空托盘"))
|
{
|
string isZWork = tsjplc.ReadValue(ConveyorLineInfoDBName.R_ZKPHLXLocation.ToString(), tsjplc.PLCDescroption).ToString();
|
WriteLog.Info("空盘回流线的请求").Write("正极:" + isZWork + "物料条码" + request.BarCode + "\t" + "缓存架编号:" + request.Devid + "\t" + DateTime.Now, "空盘回流线的请求");
|
if (isZWork == "False")
|
{
|
choose = false;
|
type = request.MaterialType;
|
result.Code = 1;
|
result.Message = "正极空盘回流线没有请求";
|
MESAPIInvoke.GetInterfaceInfo("OutStockMaterBind", request.TaskID, request.Devid, result.Code, result.Message + "choose:" + choose + "type" + type);
|
WriteLog.Info("出库物料绑定MES调我们的接口").Write("结束," + "物料类型:" + request.MaterialType + "\t" + "物料状态" + request.MaterialStatus + "\t" + "物料条码" + request.BarCode + "\t" + "缓存架编号:" + request.Devid + "\t" + request.CacheDevid + "\t" + "反馈结果:" + result.Code + "\t" + "反馈信息:" + result.Message + "\t" + type + "\t" + DateTime.Now, "出库物料绑定");
|
return result;
|
}
|
string isZGMWork = tsjplc.ReadValue(ConveyorLineInfoDBName.R_ZGMWork.ToString(), tsjplc.PLCDescroption).ToString();
|
string isZState = tsjplc.ReadValue(ConveyorLineInfoDBName.R_ZGMState.ToString(), tsjplc.PLCDescroption).ToString();
|
//获取空盘回流线负极货位是否有料
|
if (bool.Parse(isZGMWork) && int.Parse(isZState) == 1)
|
{
|
task = new dt_agvtask
|
{
|
agv_fromaddress = "ZJXL-KPHLX001",
|
agv_toaddress = "GMSL-LJHCX001"
|
};
|
task.agv_materielid = request.MaterialType;
|
task.agv_qty = 1;
|
task.agv_tasknum = "KH-" + tasknumber.GetTaskNumber(tasknumberRep);
|
task.agv_grade = 1;
|
task.agv_materbarcode = "";
|
task.agv_barcode = "";
|
task.agv_code = "负极2号AGV";
|
task.agv_createtime = DateTime.Now;
|
task.agv_taskstate = "Create";
|
task.agv_tasktype = "TaskType_Outbound";
|
task.agv_userid = "WCS";
|
task.agv_worktype = 2;
|
agvRepository.Add(task, true);
|
result.Code = 0;
|
choose = true;
|
type = "";
|
MESAPIInvoke.GetInterfaceInfo("OutStockMaterBind", request.TaskID, request.Devid, result.Code, result.Message + "choose:" + choose + "type" + type);
|
WriteLog.Info("出库物料绑定MES调我们的接口").Write("结束,任务号:" + task.agv_tasknum + "\t" + "物料类型:" + request.MaterialType + "\t" + "物料状态" + request.MaterialStatus + "\t" + "物料条码" + request.BarCode + "\t" + "缓存架编号:" + request.Devid + "\t" + request.CacheDevid + "\t" + "反馈结果:" + result.Code + "\t" + "反馈信息:" + result.Message + "\t" + DateTime.Now, "出库物料绑定");
|
}
|
else
|
{
|
choose = false;
|
type = request.MaterialType;
|
result.Code = 1;
|
result.Message = "隔膜缓存线没有请求 ";
|
MESAPIInvoke.GetInterfaceInfo("OutStockMaterBind", request.TaskID, request.Devid, result.Code, result.Message + "choose:" + choose + "type" + type);
|
WriteLog.Info("出库物料绑定MES调我们的接口").Write("结束,任务号:" + task.agv_tasknum + "\t" + "物料类型:" + request.MaterialType + "\t" + "物料状态" + request.MaterialStatus + "\t" + "物料条码" + request.BarCode + "\t" + "缓存架编号:" + request.Devid + "\t" + request.CacheDevid + "\t" + "反馈结果:" + result.Code + "\t" + "反馈信息:" + result.Message + "\t" + type + "\t" + DateTime.Now, "出库物料绑定");
|
}
|
}
|
else if (request.Devid.Contains("F") && (choose == true || type == "隔膜空托盘"))
|
{
|
string isZWork = tsjplc.ReadValue(ConveyorLineInfoDBName.R_FKPHLXLocation.ToString(), tsjplc.PLCDescroption).ToString();
|
WriteLog.Info("空盘回流线的请求").Write("负极:" + isZWork + "物料条码" + request.BarCode + "\t" + "缓存架编号:" + request.Devid + "\t" + DateTime.Now, "空盘回流线的请求");
|
if (isZWork == "False")
|
{
|
choose = false;
|
type = request.MaterialType;
|
result.Code = 1;
|
result.Message = "负极空盘回流线没有请求";
|
MESAPIInvoke.GetInterfaceInfo("OutStockMaterBind", request.TaskID, request.Devid, result.Code, result.Message + "choose:" + choose + "type" + type);
|
WriteLog.Info("出库物料绑定MES调我们的接口").Write("结束," + "物料类型:" + request.MaterialType + "\t" + "物料状态" + request.MaterialStatus + "\t" + "物料条码" + request.BarCode + "\t" + "缓存架编号:" + request.Devid + "\t" + request.CacheDevid + "\t" + "反馈结果:" + result.Code + "\t" + "反馈信息:" + result.Message + "\t" + type + "\t" + DateTime.Now, "出库物料绑定");
|
return result;
|
}
|
string isFGMWork = tsjplc.ReadValue(ConveyorLineInfoDBName.R_FGMWork.ToString(), tsjplc.PLCDescroption).ToString();
|
string isFState = tsjplc.ReadValue(ConveyorLineInfoDBName.R_FGMState.ToString(), tsjplc.PLCDescroption).ToString();
|
//获取空盘回流线负极货位是否有料
|
if (bool.Parse(isFGMWork) && int.Parse(isFState) == 1)
|
{
|
task = new dt_agvtask
|
{
|
agv_fromaddress = "FJXL-KPHLX001",
|
agv_toaddress = "GMSL-LJHCX002",
|
};
|
task.agv_materielid = request.MaterialType;
|
task.agv_qty = 1;
|
task.agv_tasknum = "KH-" + tasknumber.GetTaskNumber(tasknumberRep);
|
task.agv_grade = 1;
|
task.agv_materbarcode = "";
|
task.agv_barcode = "";
|
task.agv_code = "负极2号AGV";
|
task.agv_createtime = DateTime.Now;
|
task.agv_taskstate = "Create";
|
task.agv_tasktype = "TaskType_Outbound";
|
task.agv_userid = "WCS";
|
task.agv_worktype = 2;
|
agvRepository.Add(task, true);
|
choose = true;
|
type = "";
|
result.Code = 0;
|
MESAPIInvoke.GetInterfaceInfo("OutStockMaterBind", request.TaskID, request.Devid, result.Code, result.Message + "choose:" + choose + "type" + type);
|
WriteLog.Info("出库物料绑定MES调我们的接口").Write("结束,任务号:" + task.agv_tasknum + "\t" + "物料类型:" + request.MaterialType + "\t" + "物料状态" + request.MaterialStatus + "\t" + "物料条码" + request.BarCode + "\t" + "缓存架编号:" + request.Devid + "\t" + request.CacheDevid + "\t" + "反馈结果:" + result.Code + "\t" + "反馈信息:" + result.Message + "\t" + DateTime.Now, "出库物料绑定");
|
}
|
else
|
{
|
choose = false;
|
type = request.MaterialType;
|
result.Code = 1;
|
result.Message = "隔膜缓存线没有请求";
|
MESAPIInvoke.GetInterfaceInfo("OutStockMaterBind", request.TaskID, request.Devid, result.Code, result.Message + "choose:" + choose + "type" + type);
|
WriteLog.Info("出库物料绑定MES调我们的接口").Write("结束,任务号:" + task.agv_tasknum + "\t" + "物料类型:" + request.MaterialType + "\t" + "物料状态" + request.MaterialStatus + "\t" + "物料条码" + request.BarCode + "\t" + "缓存架编号:" + request.Devid + "\t" + request.CacheDevid + "\t" + "反馈结果:" + result.Code + "\t" + "反馈信息:" + result.Message + "\t" + type + "\t" + DateTime.Now, "出库物料绑定");
|
}
|
}
|
}
|
else
|
{
|
if (choose == true)
|
{
|
task = new dt_agvtask()
|
{
|
agv_materbarcode = request.MaterialType,
|
agv_barcode = "",
|
agv_code = "负极2号AGV",
|
agv_createtime = DateTime.Now,
|
agv_fromaddress = request.Devid,
|
agv_grade = 1,
|
agv_materielid = "",
|
agv_qty = 1,
|
agv_tasknum = "KH-" + tasknumber.GetTaskNumber(tasknumberRep),
|
agv_taskstate = "Create",
|
agv_tasktype = "TaskType_Outbound",
|
agv_toaddress = request.BarCode,
|
agv_userid = "WCS",
|
agv_worktype = 1
|
};
|
agvRepository.Add(task, true);
|
choose = true;
|
result.Code = 0;
|
MESAPIInvoke.GetInterfaceInfo("OutStockMaterBind", request.TaskID, request.Devid, result.Code, result.Message + "choose:" + choose + "type" + type);
|
WriteLog.Info("出库物料绑定MES调我们的接口").Write("结束,任务号:" + task.agv_tasknum + "\t" + "物料类型:" + request.MaterialType + "\t" + "物料状态" + request.MaterialStatus + "\t" + "物料条码" + request.BarCode + "\t" + "缓存架编号:" + request.Devid + "\t" + request.CacheDevid + "\t" + "反馈结果:" + result.Code + "\t" + "反馈信息:" + result.Message + "\t" + DateTime.Now, "出库物料绑定");
|
}
|
else
|
{
|
choose = false;
|
result.Code = 1;
|
result.Message = "choose:" + choose.ToString();
|
MESAPIInvoke.GetInterfaceInfo("OutStockMaterBind", request.TaskID, request.Devid, result.Code, result.Message + "type" + type);
|
WriteLog.Info("出库物料绑定MES调我们的接口").Write("结束,任务号:" + task.agv_tasknum + "\t" + "物料类型:" + request.MaterialType + "\t" + "物料状态" + request.MaterialStatus + "\t" + "物料条码" + request.BarCode + "\t" + "缓存架编号:" + request.Devid + "\t" + request.CacheDevid + "\t" + "反馈结果:" + result.Code + "\t" + "反馈信息:" + result.Message + "\t" + type + "\t" + DateTime.Now, "出库物料绑定");
|
}
|
}
|
}
|
else
|
{
|
if (request.TaskID.Contains("GH-")) { request.TaskID = request.TaskID.Remove(0, 3); }
|
var agvtask = agvRepository.FindFirst(v => v.agv_tasknum == request.TaskID);
|
if (agvtask == null)
|
{
|
if (request.Devid.Contains("FBT"))
|
{
|
MESback WMSbackresult = new MESback();
|
WMSbackresult = MESAPIInvoke.OutStockMaterMove(request.Devid, request.MaterialType, 4, request.sum);
|
if (WMSbackresult.Code > 0) { result.Code = 1; result.Message = "分拨台出库确认搬走接口MES不通过"; return result; }
|
}
|
result.Code = 0;
|
result.Message = "未查询到当前任务号的信息";
|
MESAPIInvoke.GetInterfaceInfo("OutStockMaterBind", request.TaskID, request.Devid, result.Code, result.Message);
|
WriteLog.Info("出库物料绑定MES调我们的接口").Write("结束,任务号:" + request.TaskID + "\t" + "物料类型:" +
|
request.MaterialType + "\t" + "物料状态" + request.MaterialStatus + "\t" + "物料条码" + request.BarCode + "\t" +
|
"缓存架编号:" + request.Devid + "\t" + "反馈结果:" + result.Code + "\t" +
|
"反馈信息:" + result.Message + "\t" + DateTime.Now, "出库物料绑定");
|
return result;
|
}
|
|
if (agvtask.agv_toaddress == "nou" && agvtask.agv_fromaddress == "nou")
|
{
|
var location = locRepository.FindFirst(v => v.upper_code == request.Devid || v.down_code == request.Devid);
|
if (location == null)
|
{
|
result.Message = "未查询到当前任务的货位信息";
|
result.Code = 1;
|
MESAPIInvoke.GetInterfaceInfo("OutStockMaterBind", request.TaskID, request.Devid, result.Code, result.Message);
|
WriteLog.Info("出库物料绑定MES调我们的接口").Write("结束1,任务号:" + request.TaskID + "\t" + "物料类型:" + request.MaterialType + "\t" + "物料状态" + request.MaterialStatus + "\t" + "物料条码" + request.BarCode + "\t" + "缓存架编号:" + request.Devid + "\t" + "反馈结果:" + result.Code + "\t" + "反馈信息:" + result.Message + "\t" + DateTime.Now, "出库物料绑定");
|
return result;
|
}
|
location.location_state = LocationStateEnum.LocationState_Stored.ToString();
|
locRepository.Update(location, true);
|
if (request.Devid.Contains("Z"))
|
{
|
agvtask.agv_toaddress = "ZJSL-WLX001";
|
}
|
else
|
{
|
agvtask.agv_toaddress = "FJSL-WLX001";
|
}
|
var stock = groupRepository.FindFirst(v => v.BarCode == request.BarCode);
|
if (stock == null)
|
{
|
bill_group_stock bill_Group = new bill_group_stock()
|
{
|
Remark1 = agvtask.agv_remark,
|
first_tb = 1,
|
TB_Status = request.Devid.Contains("TB") ? request.MaterialStatus : "",
|
BarCode = request.BarCode,
|
GY_Status = request.Devid.Contains("GY") ? request.MaterialStatus : "",
|
created_time = DateTime.Now,
|
created_user = "admin",
|
stock_id = new Guid(),
|
FQ_Status = request.Devid.Contains("FQ") || request.Devid.Contains("ZZLJ") ? request.MaterialStatus : "",
|
location_id = location.id,
|
MaterialType = request.MaterialType,
|
MaterialStatus = request.MaterialStatus == null || request.MaterialStatus == "" ? "" : request.MaterialStatus,
|
QX_Status = request.Devid.Contains("QX") ? request.MaterialStatus : "",
|
updated_time = DateTime.Now,
|
updated_user = "admin"
|
};
|
groupRepository.Add(bill_Group, true);
|
}
|
else
|
{
|
stock.MaterialStatus = request.MaterialStatus;
|
stock.MaterialType = request.MaterialType;
|
stock.location_id = location.id;
|
stock.Remark1 = agvtask.agv_remark;
|
groupRepository.Update(stock, true);
|
}
|
agvtask.agv_fromaddress = request.Devid;
|
agvtask.agv_taskstate = "Create";
|
agvtask.agv_materbarcode = request.BarCode;
|
agvtask.agv_materielid = request.MaterialType;
|
agvRepository.Update(agvtask, true);
|
result.Code = 0;
|
MESAPIInvoke.GetInterfaceInfo("OutStockMaterBind", request.TaskID, request.Devid, result.Code, result.Message);
|
WriteLog.Info("出库物料绑定MES调我们的接口").Write("结束,任务号:" + request.TaskID + "\t" + "物料类型:" + request.MaterialType + "\t" + "物料状态" + request.MaterialStatus + "\t" + "物料条码" + request.BarCode + "\t" + "缓存架编号:" + request.Devid + "\t" + "反馈结果:" + result.Code + "\t" + "反馈信息:" + result.Message + "\t" + DateTime.Now, "出库物料绑定");
|
}
|
else if (agvtask.agv_toaddress.Contains("JR"))
|
{
|
string barcodes = "";
|
for (int i = 0; i < request.BarCodes.Count(); i++)
|
{
|
barcodes = request.BarCodes[i] + ",";
|
WriteLog.Info("MES卷绕绑定条码").Write("卷绕绑定条码:" + request.Devid + "\t" + request.BarCodes[i] + DateTime.Now, "MES卷绕绑定条码");
|
}
|
|
/*2023.8.2新增 冠宏传递卷绕长度*/
|
agvtask.size = request.size;
|
agvRepository.Update(agvtask, true);
|
WriteLog.Info("卷绕size").Write($"冠宏MES请求:{JsonConvert.SerializeObject(request)}", "卷绕size");
|
|
WebResponseContent content = new WebResponseContent();
|
jrRepository.DbContextBeginTransaction(() =>
|
{
|
var bind = jrRepository.FindFirst(f => f.Devid == request.Devid);
|
bind.barcode = request.BarCode;
|
bind.Devid = request.Devid;
|
bind.materialtype = request.MaterialType;
|
bind.sum = request.sum;
|
bind.taskid = request.TaskID;
|
bind.barcodes = barcodes;
|
bind.size = request.size;
|
jrRepository.Update(bind, true);
|
result.Code = 0;
|
MESAPIInvoke.GetInterfaceInfo("OutStockMaterBind", request.TaskID, request.Devid, result.Code, result.Message);
|
WriteLog.Info("出库物料绑定MES调我们的接口").Write("结束2,任务号:" + request.TaskID + "\t" + "物料类型:" + request.MaterialType + "\t" + "物料状态" + request.MaterialStatus + "\t" + "物料条码" + request.BarCode + "\t" + "缓存架编号:" + request.Devid + "\t" + "数量:" + request.sum + "\t" + "反馈结果:" + result.Code + "\t" + "反馈信息:" + result.Message + "\t" + DateTime.Now, "出库物料绑定");
|
return WebResponseContent.Instance.OK();
|
});
|
|
}
|
else if (agvtask.agv_toaddress.Contains("SB"))
|
{
|
var loc = locRepository.FindFirst(f => f.down_code == request.Devid || f.upper_code == request.Devid);
|
var stock = groupRepository.FindFirst(f => f.BarCode == request.BarCode);
|
if (stock == null)
|
{
|
bill_group_stock bill_Group_Stock = new bill_group_stock()
|
{
|
BarCode = request.BarCode,
|
created_time = DateTime.Now,
|
MaterialStatus = request.MaterialStatus,
|
MaterialType = request.MaterialType,
|
location_id = loc.id,
|
Remark1 = agvtask.agv_remark,
|
stock_id = new Guid(),
|
updated_time = DateTime.Now,
|
updated_user = "admin",
|
created_user = "admin",
|
GY_Status = "",
|
FQ_Status = "",
|
QX_Status = "",
|
TB_Status = "",
|
first_tb = 1
|
};
|
groupRepository.Add(bill_Group_Stock, true);
|
}
|
else
|
{
|
stock.GY_Status = "";
|
stock.FQ_Status = "";
|
stock.QX_Status = "";
|
stock.TB_Status = "";
|
stock.MaterialStatus = request.MaterialStatus;
|
stock.MaterialType = request.MaterialType;
|
stock.location_id = loc.id;
|
groupRepository.Update(stock, true);
|
}
|
agvtask.agv_fromaddress = request.Devid;
|
agvtask.agv_taskstate = "Create";
|
agvtask.agv_materbarcode = request.BarCode;
|
agvtask.agv_materielid = request.MaterialType;
|
agvRepository.Update(agvtask, true);
|
result.Code = 0;
|
MESAPIInvoke.GetInterfaceInfo("OutStockMaterBind", request.TaskID, request.Devid, result.Code, result.Message);
|
WriteLog.Info("出库物料绑定MES调我们的接口").Write("结束3,任务号:" + request.TaskID + "\t" + "物料类型:" + request.MaterialType + "\t" + "物料状态" + request.MaterialStatus + "\t" + "物料条码" + request.BarCode + "\t" + "缓存架编号:" + request.Devid + "\t" + "反馈结果:" + result.Code + "\t" + "反馈信息:" + result.Message + "\t" + DateTime.Now, "出库物料绑定");
|
}
|
else if (agvtask.agv_toaddress.Contains("HCJ") || agvtask.agv_toaddress.Contains("ZZLJ"))
|
{
|
var location = locRepository.FindFirst(v => v.down_code == agvtask.agv_toaddress || v.upper_code == agvtask.agv_toaddress);
|
var loc = locRepository.FindFirst(f => f.down_code == request.Devid || f.upper_code == request.Devid);
|
if (location == null)
|
{
|
result.Message = "未查询到当前任务的货位信息";
|
result.Code = 1;
|
MESAPIInvoke.GetInterfaceInfo("OutStockMaterBind", request.TaskID, request.Devid, result.Code, result.Message);
|
WriteLog.Info("出库物料绑定MES调我们的接口").Write("结束,任务号:" + request.TaskID + "\t" + "物料类型:" + request.MaterialType + "\t" + "物料状态" + request.MaterialStatus + "\t" + "物料条码" + request.BarCode + "\t" + "缓存架编号:" + request.Devid + "\t" + "反馈结果:" + result.Code + "\t" + "反馈信息:" + result.Message + "\t" + DateTime.Now, "出库物料绑定");
|
return result;
|
}
|
if (!request.MaterialType.Contains("空托盘"))
|
{
|
var stock = groupRepository.FindFirst(f => f.BarCode == request.BarCode);
|
if (stock == null)
|
{
|
bill_group_stock bill_Group_Stock = new bill_group_stock()
|
{
|
BarCode = request.BarCode,
|
created_time = DateTime.Now,
|
location_id = loc.id,
|
MaterialStatus = request.MaterialStatus,
|
MaterialType = request.MaterialType,
|
Remark1 = agvtask.agv_remark,
|
stock_id = new Guid(),
|
updated_time = DateTime.Now,
|
updated_user = "admin",
|
created_user = "admin",
|
GY_Status = "",
|
FQ_Status = "",
|
QX_Status = "",
|
TB_Status = "",
|
first_tb = 1
|
};
|
groupRepository.Add(bill_Group_Stock, true);
|
}
|
else
|
{
|
stock.GY_Status = "";
|
stock.FQ_Status = "";
|
stock.QX_Status = "";
|
stock.TB_Status = "";
|
stock.MaterialStatus = request.MaterialStatus;
|
stock.MaterialType = request.MaterialType;
|
stock.location_id = loc.id;
|
groupRepository.Update(stock, true);
|
}
|
}
|
agvtask.agv_fromaddress = request.Devid;
|
agvtask.agv_taskstate = "Create";
|
agvtask.agv_materbarcode = request.BarCode;
|
agvtask.agv_materielid = request.MaterialType;
|
agvRepository.Update(agvtask, true);
|
result.Code = 0;
|
MESAPIInvoke.GetInterfaceInfo("OutStockMaterBind", request.TaskID, request.Devid, result.Code, result.Message);
|
WriteLog.Info("出库物料绑定MES调我们的接口").Write("结束4,任务号:" + request.TaskID + "\t" + "物料类型:" + request.MaterialType + "\t" + "物料状态" + request.MaterialStatus + "\t" + "物料条码" + request.BarCode + "\t" + "缓存架编号:" + request.Devid + "\t" + "反馈结果:" + result.Code + "\t" + "反馈信息:" + result.Message + "\t" + DateTime.Now, "出库物料绑定");
|
}
|
}
|
}
|
catch (Exception ex)
|
{
|
result.Code = 1;
|
result.Message = ex.Message;
|
MESAPIInvoke.GetInterfaceInfo("OutStockMaterBind", request.TaskID, request.Devid, result.Code, result.Message);
|
WriteLog.Info("出库物料绑定MES调我们的接口").Write("异常,任务号:" + request.TaskID + "\t" + "物料类型:" + request.MaterialType + "\t" + "物料状态" + request.MaterialStatus + "\t" + "物料条码" + request.BarCode + "\t" + "缓存架编号:" + request.Devid + "\t" + "反馈结果:" + result.Code + "\t" + "反馈信息:" + result.Message + "\t" + DateTime.Now, "出库物料绑定");
|
}
|
return result;
|
}
|
|
public static ResultMaterstateUp UpdateAGVTaskState(MEStockMaterBindRequest request)
|
{
|
ResultMaterstateUp responseContent = new ResultMaterstateUp();
|
try
|
{
|
VOLContext Context = new VOLContext();
|
UserContext userContext=new UserContext();
|
Idt_task_numberRepository tasknumberRep = new dt_task_numberRepository(Context);
|
dt_task_numberService tasknumber = new dt_task_numberService(tasknumberRep);
|
Ibase_ware_locationRepository locationRepository = new base_ware_locationRepository(Context);
|
Ibase_routing_tableRepository routingRepository = new base_routing_tableRepository(Context);
|
Ibill_pda_groupdiskRepository pdaRepository = new bill_pda_groupdiskRepository(Context);
|
Idt_agvtaskRepository agvtaskRepository = new dt_agvtaskRepository(Context);
|
Ibill_group_stockRepository group_StockRepository = new bill_group_stockRepository(Context);
|
Idt_agvtask_htyRepository agvtask_HtyRepository = new dt_agvtask_htyRepository(Context);
|
var agvTask = agvtaskRepository.FindFirst(v => v.agv_tasknum == request.TaskID);
|
WriteLog.Info("手动完成任务").Write("UpdateAGVTaskState,任务号:" + agvTask.agv_tasknum + DateTime.Now, "手动完成任务");
|
if (agvTask == null)
|
{
|
throw new Exception(string.Format("未查询到手动完成任务:" + request.TaskID));
|
responseContent.Code = 1;
|
return responseContent;
|
}
|
if (userContext.UserName=="ME1")
|
{
|
if (agvTask.agv_code=="负极1号AGV"|| agvTask.agv_code == "正极1号AGV")
|
{
|
|
}
|
else {
|
throw new Exception(string.Format($"账号【{userContext.UserName}】无权限完成【{agvTask.agv_code}】AGV任务" + request.TaskID)); }
|
}
|
else if (userContext.UserName == "ME3")
|
{
|
if (agvTask.agv_code == "负极2号AGV" || agvTask.agv_code == "正极2号AGV")
|
{
|
|
}
|
else
|
{
|
throw new Exception(string.Format($"账号【{userContext.UserName}】无权限完成【{agvTask.agv_code}】AGV任务" + request.TaskID));
|
}
|
}
|
else
|
{
|
throw new Exception(string.Format($"账号【{userContext.UserName}】无权限完成【{agvTask.agv_code}】AGV任务" + request.TaskID));
|
}
|
PLCClient plcClient = WCSService.Clients.Find(v => v.PLCName == agvTask.agv_code);
|
//起点货位改为空
|
var fromloc = locationRepository.FindFirst(f => f.upper_code == agvTask.agv_fromaddress || f.down_code == agvTask.agv_fromaddress);
|
if (fromloc != null)
|
{
|
fromloc.location_state = LocationStateEnum.LocationState_Empty.ToString();
|
locationRepository.Update(fromloc, true);
|
}
|
//如果是设备就不用更改,是缓存架货位状态为已存储,(库存表)location_id=(货位表)的货位
|
base_ware_location location = locationRepository.FindFirst(f => f.upper_code == agvTask.agv_toaddress || f.down_code == agvTask.agv_toaddress);
|
bill_group_stock stock = new bill_group_stock();
|
if (agvTask.agv_fromaddress.Contains("0201") && agvTask.agv_toaddress.Contains("ZZLJ"))
|
{
|
location.location_state = LocationStateEnum.LocationState_Stored.ToString();
|
locationRepository.Update(location, true);
|
}
|
else if (agvTask.agv_fromaddress.Contains("WLX") && agvTask.agv_toaddress.Contains("0101"))
|
{
|
location.location_state = LocationStateEnum.LocationState_Stored.ToString();
|
locationRepository.Update(location, true);
|
MESback WMSbackresult = MESAPIInvoke.InStockMaterBind(agvTask.agv_toaddress, "空托盘", agvTask.agv_tasknum, "OK", 3);
|
if (WMSbackresult.Code > 0)
|
{
|
responseContent.Code = 1;
|
responseContent.Message = WMSbackresult.Message;
|
WriteLog.Info("手动完成任务").Write("手动完成任务失败,任务号:" + agvTask.agv_tasknum + responseContent.Message + DateTime.Now, "手动完成任务");
|
return responseContent;
|
}
|
}
|
else if (agvTask.agv_toaddress.Contains("JR"))
|
{
|
if (agvTask.agv_taskstate == AGVTaskStateEnum.Complete.ToString())
|
{
|
var iswork = agvtaskRepository.FindFirst(f => f.agv_remark == "true" && f.agv_tasknum == agvTask.agv_tasknum);
|
if (iswork != null)
|
{
|
MESback WMSbackresult = new MESback();
|
WMSbackresult = MESAPIInvoke.OutStockMaterMove(agvTask.agv_fromaddress, agvTask.agv_materielid, 4, Convert.ToInt32(iswork.agv_qty), agvTask.agv_tasknum);
|
if (WMSbackresult.Code > 0) { new Exception(WMSbackresult.Message); }
|
}
|
}
|
|
}
|
else if (agvTask.agv_toaddress.Contains("HXWLX"))
|
{ //如果是进烘箱的任务,需要告诉WMS两个进烘箱物料的条码和位置,需要问胡工怎么给他值
|
if (agvTask.agv_fromaddress.Contains("KPHLX"))
|
{
|
var materials = WebApiHelper.ParseFromJson<List<BakingClass>>(agvTask.agv_materbarcode);
|
MESback WMSbackresult = MESAPIInvoke.BakingFeedingBinding(agvTask.agv_toaddress, materials);
|
if (WMSbackresult.Code > 0) { new Exception(WMSbackresult.Message); }
|
}
|
else
|
{
|
WebResponseContent content = new WebResponseContent();
|
content = group_StockRepository.DbContextBeginTransaction(() =>
|
{
|
var materbarcode = agvTask.agv_materbarcode.Split(";");
|
List<BakingClass> materials = new List<BakingClass>();
|
for (int i = 0; i < materbarcode.Count(); i++)
|
{
|
BakingClass bakingClass = new BakingClass();
|
stock = group_StockRepository.Find(f => f.BarCode == materbarcode[i]).OrderByDescending(f => f.created_time).FirstOrDefault();
|
bakingClass.BarCode = materbarcode[i];
|
bakingClass.MaterialType = stock.MaterialType;
|
materials.Add(bakingClass);
|
group_StockRepository.Delete(stock, true);
|
WriteLog.Info("烘烤").Write("materials" + materials[i].BarCode + "\t" + materials[i].MaterialType + "\t" + bakingClass.BarCode + "\t" + bakingClass.MaterialType + DateTime.Now, "烘烤物料条码");
|
}
|
MESback WMSbackresult = MESAPIInvoke.BakingFeedingBinding(agvTask.agv_toaddress, materials);
|
if (WMSbackresult.Code > 0) { return content = WebResponseContent.Instance.Error(WMSbackresult.Message); }
|
//如果终点地址是去烘烤箱的删除库存
|
location.location_state = LocationStateEnum.LocationState_Empty.ToString();
|
locationRepository.Update(location, true);
|
return WebResponseContent.Instance.OK();
|
});
|
if (content.Status == false)
|
{
|
responseContent.Code = 1;
|
responseContent.Message = "手动完成任务失败";
|
return responseContent;
|
}
|
}
|
}
|
else
|
{
|
stock = group_StockRepository.FindFirst(f => f.BarCode == agvTask.agv_materbarcode);
|
if (!agvTask.agv_toaddress.Contains("SB") && !agvTask.agv_fromaddress.Contains("WLX") && !agvTask.agv_toaddress.Contains("JJK") && !agvTask.agv_toaddress.Contains("WLX"))
|
{
|
if (stock == null)
|
{
|
bill_group_stock newstock = new bill_group_stock
|
{
|
BarCode = agvTask.agv_materbarcode,
|
MaterialType = agvTask.agv_materielid,
|
MaterialStatus = agvTask.agv_materbarcode.Split('*')[6],
|
first_tb = 0,
|
location_id = location.id,
|
TB_Status = "",
|
FQ_Status = "",
|
GY_Status = "",
|
QX_Status = "",
|
created_time = DateTime.Now,
|
created_user = "WCS",
|
updated_time = DateTime.Now,
|
updated_user = "WCS"
|
};
|
group_StockRepository.Add(newstock, true);
|
}
|
else
|
{
|
stock.location_id = location.id;
|
group_StockRepository.Update(stock, true);
|
}
|
|
location.location_state = LocationStateEnum.LocationState_Stored.ToString();
|
locationRepository.Update(location, true);
|
if (agvTask.agv_toaddress.Contains("HCJ") || agvTask.agv_toaddress.Contains("CBJ") || agvTask.agv_toaddress.Contains("ZZLJ"))
|
{
|
if (stock.MaterialStatus == "OK")
|
{
|
plcClient.WriteValue(ConveyorLineInfoDBName.MaterOK.ToString(), agvTask.agv_toaddress, 0);
|
}
|
else if (stock.MaterialStatus == "nou") { }
|
else
|
{
|
plcClient.WriteValue(ConveyorLineInfoDBName.MaterNG.ToString(), agvTask.agv_toaddress, 0);
|
}
|
|
}
|
//如果终点地址是库内,需要给WMS反馈入库物料绑定
|
if (agvTask.agv_toaddress.Contains("0101"))
|
{
|
MESback WMSbackresult = MESAPIInvoke.InStockMaterBind(agvTask.agv_toaddress, agvTask.agv_materielid, agvTask.agv_materbarcode, agvTask.agv_materbarcode.Split('*')[6], 3);
|
if (WMSbackresult.Code > 0) { new Exception(WMSbackresult.Message); }
|
}
|
}
|
else if (agvTask.agv_toaddress.Contains("SB"))
|
{
|
//如果终点地址是去设备
|
location.location_state = LocationStateEnum.LocationState_Empty.ToString();
|
locationRepository.Update(location, true);
|
group_StockRepository.Delete(stock, true);
|
}
|
else if (agvTask.agv_toaddress.Contains("WLX"))
|
{
|
if (agvTask.agv_code.Contains("正"))
|
{
|
//添加物料条码,三楼输送线出口取前两个条码
|
var barcode = tasknumberRep.FindFirst(v => v.taskno == 1);
|
barcode.numtype = barcode.numtype + agvTask.agv_materbarcode + ";";
|
tasknumberRep.Update(barcode, true);
|
}
|
else
|
{
|
//添加物料条码,三楼输送线出口取前两个条码
|
var barcode = tasknumberRep.FindFirst(v => v.taskno == 2);
|
barcode.numtype = barcode.numtype + agvTask.agv_materbarcode + ";";
|
tasknumberRep.Update(barcode, true);
|
}
|
}
|
else if (agvTask.agv_toaddress.Contains("JJK"))
|
{
|
if (stock.MaterialStatus == "OK")
|
{
|
plcClient.WriteValue(ConveyorLineInfoDBName.MaterOK.ToString(), agvTask.agv_toaddress, 0);
|
}
|
else
|
{
|
plcClient.WriteValue(ConveyorLineInfoDBName.MaterNG.ToString(), agvTask.agv_toaddress, 0);
|
}
|
if (agvTask.agv_toaddress.Contains("Z"))
|
{
|
MESback WMSbackresult = MESAPIInvoke.InStockMaterBind(agvTask.agv_toaddress, agvTask.agv_materielid, agvTask.agv_materbarcode, agvTask.agv_materbarcode.Split('*')[6], 1);
|
if (WMSbackresult.Code > 0) { new Exception(WMSbackresult.Message); }
|
}
|
else if (agvTask.agv_toaddress.Contains("F"))
|
{
|
MESback WMSbackresult = MESAPIInvoke.InStockMaterBind(agvTask.agv_toaddress, agvTask.agv_materielid, agvTask.agv_materbarcode, agvTask.agv_materbarcode.Split('*')[6], 2);
|
if (WMSbackresult.Code > 0) { new Exception(WMSbackresult.Message); }
|
}
|
|
}
|
}
|
agvtask_HtyRepository.AddTaskHistorys(agvTask, OperateType.ManualCompletion.ToString(),userContext.UserName);
|
agvtaskRepository.Delete(agvTask, true);
|
responseContent.Code = 0;
|
}
|
catch (Exception ex)
|
{
|
responseContent.Code = 1;
|
responseContent.Message = ex.Message;
|
}
|
return responseContent;
|
}
|
|
public static ResultMaterstateUp DeleteAGVTaskState(MEStockMaterBindRequest request)
|
{
|
ResultMaterstateUp result = new ResultMaterstateUp();
|
try
|
{
|
UserContext userContext = new UserContext();
|
VOLContext Context = new VOLContext();
|
WebResponseContent responseContent = new WebResponseContent();
|
Idt_task_numberRepository tasknumberRep = new dt_task_numberRepository(Context);
|
dt_task_numberService tasknumber = new dt_task_numberService(tasknumberRep);
|
Ibase_ware_locationRepository locationRepository = new base_ware_locationRepository(Context);
|
Ibase_routing_tableRepository routingRepository = new base_routing_tableRepository(Context);
|
Ibill_pda_groupdiskRepository pdaRepository = new bill_pda_groupdiskRepository(Context);
|
Idt_agvtaskRepository agvtaskRepository = new dt_agvtaskRepository(Context);
|
Ibill_group_stockRepository group_StockRepository = new bill_group_stockRepository(Context);
|
Idt_agvtask_htyRepository agvtask_HtyRepository = new dt_agvtask_htyRepository(Context);
|
var agvTask = agvtaskRepository.FindFirst(v => v.agv_tasknum == request.TaskID);
|
if (userContext.UserName == "ME1")
|
{
|
if (agvTask.agv_code == "负极1号AGV" || agvTask.agv_code == "正极1号AGV")
|
{
|
|
}
|
else
|
{
|
throw new Exception(string.Format($"账号【{userContext.UserName}】无权限删除【{agvTask.agv_code}】AGV任务" + request.TaskID));
|
}
|
}
|
else if (userContext.UserName == "ME3")
|
{
|
if (agvTask.agv_code == "负极2号AGV" || agvTask.agv_code == "正极2号AGV")
|
{
|
|
}
|
else
|
{
|
throw new Exception(string.Format($"账号【{userContext.UserName}】无权限删除【{agvTask.agv_code}】AGV任务" + request.TaskID));
|
}
|
}
|
else
|
{
|
throw new Exception(string.Format($"账号【{userContext.UserName}】无权限删除【{agvTask.agv_code}】AGV任务" + request.TaskID));
|
}
|
PLCClient plcClient = WCSService.Clients.Find(v => v.PLCName == agvTask.agv_code);
|
if (plcClient == null)
|
{
|
WriteLog.Info("DeleteAGVTaskState").Write("取消任务失败," + agvTask.agv_code + "plc未连接" + "\t" + DateTime.Now, "DeleteAGVTaskState");
|
result.Code = 1;
|
result.Message = "取消任务失败";
|
return result;
|
}
|
plcClient.WriteValue(TaskDBName.taskID.ToString(), agvTask.agv_tasknum);
|
Task.Delay(2000).Wait();
|
string taskId = plcClient.ReadValue(TaskDBName.taskID.ToString()).ToString();
|
if (taskId == agvTask.agv_tasknum)
|
{
|
plcClient.WriteValue(TaskDBName.taskInteractiveW.ToString(), 2);
|
for (int i = 0; i < 5; i++)
|
{
|
Task.Delay(2000).Wait();
|
var agvnumber = Convert.ToInt32(plcClient.ReadValue(TaskDBName.taskInteractiveW.ToString()));
|
if (agvnumber != 2)
|
{
|
plcClient.WriteValue(TaskDBName.taskInteractiveW.ToString(), 2);
|
}
|
else
|
{
|
break;
|
}
|
}
|
Task.Delay(2000).Wait();
|
int TaskInteractive = Convert.ToInt32(plcClient.ReadValue(TaskDBName.taskInteractiveR.ToString()));
|
if (TaskInteractive == 1)
|
{
|
plcClient.WriteValue(TaskDBName.taskInteractiveW.ToString(), 0);
|
for (int i = 0; i < 5; i++)
|
{
|
Task.Delay(2000).Wait();
|
var agvnumber = Convert.ToInt32(plcClient.ReadValue(TaskDBName.taskInteractiveW.ToString()));
|
if (agvnumber != 0)
|
{
|
plcClient.WriteValue(TaskDBName.taskInteractiveW.ToString(), 0);
|
}
|
else
|
{
|
break;
|
}
|
}
|
Task.Delay(2000).Wait();
|
int TaskInteractiver = Convert.ToInt32(plcClient.ReadValue(TaskDBName.taskInteractiveR.ToString()));
|
if (TaskInteractiver == 0)
|
{
|
responseContent = agvtaskRepository.DbContextBeginTransaction(() =>
|
{
|
agvtask_HtyRepository.AddTaskHistorys(agvTask, OperateType.CancelManually.ToString(), userContext.UserName);
|
|
WriteLog.Info("DeleteAGVTaskState").Write("DeleteAGVTaskState" + agvTask.agv_tasknum + DateTime.Now, "DeleteAGVTaskState");
|
var location = locationRepository.FindFirst(f => f.upper_code == agvTask.agv_fromaddress || f.down_code == agvTask.agv_fromaddress);
|
if (location != null)
|
{
|
location.location_state = LocationStateEnum.LocationState_Empty.ToString();
|
locationRepository.Update(location, true);
|
}
|
var stock = group_StockRepository.FindFirst(v => v.BarCode == agvTask.agv_materbarcode);
|
if (stock != null)
|
{
|
group_StockRepository.Delete(stock, true);
|
}
|
var toloc = locationRepository.FindFirst(f => f.upper_code == agvTask.agv_toaddress || f.down_code == agvTask.agv_toaddress);
|
if (toloc != null)
|
{
|
toloc.location_state = LocationStateEnum.LocationState_Empty.ToString();
|
locationRepository.Update(toloc, true);
|
}
|
agvtaskRepository.Delete(agvTask, true);
|
result.Code = 0;
|
return WebResponseContent.Instance.OK();
|
});
|
}
|
else
|
{
|
WriteLog.Info("DeleteAGVTaskState").Write("取消任务失败,AGV的taskInteractiveR的值不为0,是" + TaskInteractiver + "\t" + DateTime.Now, "DeleteAGVTaskState");
|
result.Code = 1;
|
result.Message = "取消任务失败";
|
return result;
|
}
|
}
|
else
|
{
|
WriteLog.Info("DeleteAGVTaskState").Write("取消任务失败,AGV的taskInteractiveR的值不为1,是" + TaskInteractive + "\t" + DateTime.Now, "DeleteAGVTaskState");
|
result.Code = 1;
|
result.Message = "取消任务失败";
|
return result;
|
}
|
}
|
else
|
{
|
WriteLog.Info("DeleteAGVTaskState").Write("取消任务失败,AGV的taskId的值与写入的taskId不一致,写入的taskId是" + agvTask.agv_tasknum + "\t" + DateTime.Now, "DeleteAGVTaskState");
|
result.Code = 1;
|
result.Message = "取消任务失败";
|
return result;
|
}
|
}
|
catch (Exception ex)
|
{
|
throw;
|
}
|
return result;
|
}
|
|
public static ResulAbnormalState GetAbnormalState(AbnormalId abnormalId)
|
{
|
ResulAbnormalState responseContent = new ResulAbnormalState();
|
try
|
{
|
VOLContext Context = new VOLContext();
|
Idt_task_numberRepository tasknumberRep = new dt_task_numberRepository(Context);
|
dt_task_numberService tasknumber = new dt_task_numberService(tasknumberRep);
|
Ibase_ware_locationRepository locationRepository = new base_ware_locationRepository(Context);
|
Ibase_routing_tableRepository routingRepository = new base_routing_tableRepository(Context);
|
Ibill_pda_groupdiskRepository pdaRepository = new bill_pda_groupdiskRepository(Context);
|
Idt_agvtaskRepository agvtaskRepository = new dt_agvtaskRepository(Context);
|
Ibill_group_stockRepository group_StockRepository = new bill_group_stockRepository(Context);
|
Idt_agvtask_htyRepository agvtask_HtyRepository = new dt_agvtask_htyRepository(Context);
|
var agvTask = new dt_agvtask();
|
if (abnormalId.taskId.Contains("GH-"))
|
{
|
string taskId = abnormalId.taskId.Remove(0, 3);
|
agvTask = agvtaskRepository.FindFirst(v => v.agv_tasknum == taskId);
|
}
|
else
|
{
|
agvTask = agvtaskRepository.FindFirst(v => v.agv_tasknum == abnormalId.taskId);
|
}
|
dt_agvtask newagvtask = new dt_agvtask
|
{
|
agv_materbarcode = agvTask.agv_materbarcode,
|
agv_barcode = agvTask.agv_barcode,
|
agv_code = agvTask.agv_code,
|
agv_createtime = DateTime.Now,
|
agv_realesstime = DateTime.Now,
|
agv_fromaddress = agvTask.agv_fromaddress,
|
agv_grade = 1,
|
agv_materielid = agvTask.agv_materielid,
|
agv_qty = 1,
|
agv_tasknum = "KH-" + tasknumber.GetTaskNumber(tasknumberRep),
|
agv_taskstate = "WaitStockOut",
|
agv_tasktype = "TaskType_Outbound",
|
agv_toaddress = agvTask.agv_toaddress,
|
agv_userid = "WCS",
|
agv_remark = agvTask.agv_remark
|
};
|
if (newagvtask.agv_materielid == "空托盘")
|
{
|
newagvtask.agv_worktype = 2;
|
}
|
else
|
{
|
newagvtask.agv_worktype = 1;
|
}
|
//调用WMS呼叫物料出库
|
if (newagvtask.agv_code == "正极1号AGV")
|
{
|
//调用WMS呼叫物料出库
|
List<string> StockList = new List<string> { "ZXD0201", "ZXC0201", "ZXB0201", "ZXA0201" };
|
MESback WMSbackresult = MESAPIInvoke.OutNeedStosk(newagvtask.agv_tasknum, StockList, 3, newagvtask.agv_materielid, "", newagvtask.agv_remark);
|
if (WMSbackresult == null || WMSbackresult.Code > 0)
|
{
|
var agvtaskold = agvtaskRepository.FindFirst(v => v.agv_fromaddress == "错误展示");
|
agvtaskold.ErrMsg = WMSbackresult.Message.ToString();
|
agvtaskold.agv_createtime = DateTime.Now;
|
agvtaskRepository.Update(agvtaskold, true);
|
throw new Exception($"失败,任务号:{newagvtask.agv_tasknum}");
|
}
|
}
|
else if (newagvtask.agv_code == "负极1号AGV")
|
{
|
//调用WMS呼叫物料出库
|
List<string> StockList = new List<string> { "FXD0201", "FXC0201", "FXB0201", "FXA0201" };
|
MESback WMSbackresult = MESAPIInvoke.OutNeedStosk(newagvtask.agv_tasknum, StockList, 3, newagvtask.agv_materielid, "", newagvtask.agv_remark);
|
if (WMSbackresult == null || WMSbackresult.Code > 0)
|
{
|
var agvtaskold = agvtaskRepository.FindFirst(v => v.agv_fromaddress == "错误展示");
|
agvtaskold.ErrMsg = WMSbackresult.Message.ToString();
|
agvtaskold.agv_createtime = DateTime.Now;
|
agvtaskRepository.Update(agvtaskold, true);
|
throw new Exception($"失败,任务号:{newagvtask.agv_tasknum}");
|
}
|
}
|
else if (newagvtask.agv_toaddress.Contains("JR") && newagvtask.agv_code == "负极2号AGV")
|
{
|
List<string> StockList = new List<string> { "FJXL-FBT001", "FJXL-FBT002" };
|
MESback WMSbackresult = MESAPIInvoke.OutNeedStosk(newagvtask.agv_tasknum, StockList, 4, newagvtask.agv_materielid, "", newagvtask.agv_toaddress);
|
if (WMSbackresult == null || WMSbackresult.Code > 0)
|
{
|
var agvtaskold = agvtaskRepository.FindFirst(v => v.agv_fromaddress == "错误展示");
|
agvtaskold.ErrMsg = WMSbackresult.Message.ToString();
|
agvtaskold.agv_createtime = DateTime.Now;
|
agvtaskRepository.Update(agvtaskold, true);
|
throw new Exception($"失败,任务号:{newagvtask.agv_tasknum}");
|
}
|
}
|
else if (newagvtask.agv_toaddress.Contains("JR") && newagvtask.agv_code == "正极2号AGV")
|
{
|
List<string> StockList = new List<string> { "ZJXL-FBT001", "ZJXL-FBT002" };
|
MESback WMSbackresult = MESAPIInvoke.OutNeedStosk(newagvtask.agv_tasknum, StockList, 4, newagvtask.agv_materielid, "", newagvtask.agv_toaddress);
|
if (WMSbackresult == null || WMSbackresult.Code > 0)
|
{
|
var agvtaskold = agvtaskRepository.FindFirst(v => v.agv_fromaddress == "错误展示");
|
agvtaskold.ErrMsg = WMSbackresult.Message.ToString();
|
agvtaskold.agv_createtime = DateTime.Now;
|
agvtaskRepository.Update(agvtaskold, true);
|
throw new Exception($"失败,任务号:{newagvtask.agv_tasknum}");
|
}
|
}
|
|
agvtaskRepository.Add(newagvtask, true);
|
WriteLog.Info("GetAbnormalState").Write("GetAbnormalState" + newagvtask.agv_tasknum + DateTime.Now, "GetAbnormalState");
|
agvtask_HtyRepository.AddTaskHistory(agvTask, OperateType.Abnormal.ToString());
|
agvtaskRepository.Delete(agvTask, true);
|
responseContent.Code = 0;
|
MESAPIInvoke.GetInterfaceInfo("GetAbnormalState", abnormalId.taskId, "", responseContent.Code, responseContent.Message);
|
}
|
catch (Exception ex)
|
{
|
responseContent.Code = 1;
|
responseContent.Message = ex.Message;
|
MESAPIInvoke.GetInterfaceInfo("GetAbnormalState", abnormalId.taskId, "", responseContent.Code, responseContent.Message);
|
}
|
return responseContent;
|
}
|
|
public static List<LocationInfo> Getlocationwork(LocationworkRequest request)
|
{
|
VOLContext Context = new VOLContext();
|
ResultMaterstateUp result = new ResultMaterstateUp();
|
Ibase_ware_locationRepository locRepository = new base_ware_locationRepository(Context);
|
List<LocationInfo> locationInfo = new List<LocationInfo>();
|
try
|
{
|
var client = WCSService.Clients;
|
PLCClient zagvplc = client.Find(v => v.PLCName == "正极1号AGV");
|
PLCClient fagvplc = client.Find(v => v.PLCName == "负极1号AGV");
|
if (string.IsNullOrEmpty(request.PLCDescroption))
|
{
|
var cbjlocation = locRepository.Find(f => f.down_code.Contains("CBJ") || f.upper_code.Contains("ZZLJ") || f.upper_code.Contains("JJK")).Select(s => s.down_code).ToList();
|
var location = locRepository.Find(w => !w.upper_code.Contains("CBJ") && w.upper_code.Contains("HCJ")).Select(s => s.upper_code).ToList();
|
string isZWork = "";
|
foreach (var item in cbjlocation)
|
{
|
if (item.Contains("ZJSL") || item.Contains("ZJXL"))
|
{
|
LocationInfo locInfo = new LocationInfo();
|
isZWork = zagvplc.ReadValue(ConveyorLineInfoDBName.R_Location_iswork.ToString(), item).ToString();
|
locInfo.Devid = item;
|
locInfo.name = zagvplc.PLCName;
|
if (isZWork == "1")
|
{
|
isZWork = "空";
|
}
|
else if (isZWork == "2")
|
{
|
isZWork = "有货";
|
}
|
locInfo.iswork = isZWork;
|
locationInfo.Add(locInfo);
|
}
|
else
|
{
|
LocationInfo locInfo = new LocationInfo();
|
isZWork = fagvplc.ReadValue(ConveyorLineInfoDBName.R_Location_iswork.ToString(), item).ToString();
|
locInfo.Devid = item;
|
locInfo.name = fagvplc.PLCName;
|
if (isZWork == "1")
|
{
|
isZWork = "空";
|
}
|
else if (isZWork == "2")
|
{
|
isZWork = "有货";
|
}
|
locInfo.iswork = isZWork;
|
locationInfo.Add(locInfo);
|
}
|
}
|
foreach (var item in location)
|
{
|
if (item.Contains("ZJSL") || item.Contains("ZJXL"))
|
{
|
LocationInfo locInfo = new LocationInfo();
|
isZWork = zagvplc.ReadValue(ConveyorLineInfoDBName.R_Location_iswork.ToString(), item).ToString();
|
locInfo.Devid = item;
|
locInfo.name = zagvplc.PLCName;
|
if (isZWork == "1")
|
{
|
isZWork = "空";
|
}
|
else if (isZWork == "2")
|
{
|
isZWork = "有货";
|
}
|
locInfo.iswork = isZWork;
|
locationInfo.Add(locInfo);
|
}
|
else
|
{
|
LocationInfo locInfo = new LocationInfo();
|
isZWork = fagvplc.ReadValue(ConveyorLineInfoDBName.R_Location_iswork.ToString(), item).ToString();
|
locInfo.Devid = item;
|
locInfo.name = fagvplc.PLCName;
|
if (isZWork == "1")
|
{
|
isZWork = "空";
|
}
|
else if (isZWork == "2")
|
{
|
isZWork = "有货";
|
}
|
locInfo.iswork = isZWork;
|
locationInfo.Add(locInfo);
|
}
|
}
|
}
|
else
|
{
|
var location = locRepository.Find(f => f.upper_code.Contains(request.PLCDescroption) || f.down_code.Contains(request.PLCDescroption));
|
string isZWork = "";
|
string Devid = "";
|
foreach (var item in location)
|
{
|
if (item.upper_code.Contains("ZJSL") || item.down_code.Contains("ZJXL"))
|
{
|
if (item.down_code.Contains("CBJ") || item.upper_code.Contains("ZZLJ") || item.upper_code.Contains("JJK"))
|
{
|
isZWork = zagvplc.ReadValue(ConveyorLineInfoDBName.R_Location_iswork.ToString(), item.down_code).ToString();
|
Devid = item.down_code;
|
}
|
else
|
{
|
isZWork = zagvplc.ReadValue(ConveyorLineInfoDBName.R_Location_iswork.ToString(), item.upper_code).ToString();
|
Devid = item.upper_code;
|
}
|
LocationInfo locInfo = new LocationInfo();
|
locInfo.Devid = Devid;
|
locInfo.name = zagvplc.PLCName;
|
if (isZWork == "1")
|
{
|
isZWork = "空";
|
}
|
else if (isZWork == "2")
|
{
|
isZWork = "有货";
|
}
|
locInfo.iswork = isZWork;
|
locationInfo.Add(locInfo);
|
}
|
else
|
{
|
if (item.down_code.Contains("CBJ") || item.upper_code.Contains("ZZLJ") || item.upper_code.Contains("JJK"))
|
{
|
isZWork = fagvplc.ReadValue(ConveyorLineInfoDBName.R_Location_iswork.ToString(), item.down_code).ToString();
|
Devid = item.down_code;
|
}
|
else
|
{
|
isZWork = fagvplc.ReadValue(ConveyorLineInfoDBName.R_Location_iswork.ToString(), item.upper_code).ToString();
|
Devid = item.upper_code;
|
}
|
LocationInfo locInfo = new LocationInfo();
|
locInfo.Devid = Devid;
|
locInfo.name = fagvplc.PLCName;
|
if (isZWork == "1")
|
{
|
isZWork = "空";
|
}
|
else if (isZWork == "2")
|
{
|
isZWork = "有货";
|
}
|
locInfo.iswork = isZWork;
|
locationInfo.Add(locInfo);
|
}
|
}
|
}
|
}
|
catch (Exception ex)
|
{
|
|
}
|
return locationInfo;
|
}
|
|
public static ResultMaterstateUp DeleteTask(MESDeleteRequest request)
|
{
|
VOLContext Context = new VOLContext();
|
ResultMaterstateUp result = new ResultMaterstateUp();
|
Ibase_ware_locationRepository locRepository = new base_ware_locationRepository(Context);
|
Idt_agvtaskRepository agvRepository = new dt_agvtaskRepository(Context);
|
Idt_agvtask_htyRepository agvtask_HtyRepository = new dt_agvtask_htyRepository(Context);
|
try
|
{
|
WriteLog.Info("删除任务MES调我们的接口").Write(request.taskid + "\t" + DateTime.Now, "DeleteTask");
|
if (request.taskid.Contains("GH-")) { request.taskid = request.taskid.Remove(0, 3); }
|
var agvtask = agvRepository.FindFirst(v => v.agv_tasknum == request.taskid);
|
if (agvtask == null)
|
{
|
result.Code = 0;
|
result.Message = "没有当前任务号";
|
MESAPIInvoke.GetInterfaceInfo("DeleteTask", request.taskid, "", result.Code, result.Message);
|
return result;
|
}
|
else
|
{
|
var fromlocation = locRepository.FindFirst(f => f.down_code == agvtask.agv_fromaddress || f.upper_code == agvtask.agv_fromaddress);
|
fromlocation.location_state = LocationStateEnum.LocationState_Empty.ToString();
|
locRepository.Update(fromlocation, true);
|
var tolocation = locRepository.FindFirst(f => f.down_code == agvtask.agv_toaddress || f.upper_code == agvtask.agv_toaddress);
|
tolocation.location_state = LocationStateEnum.LocationState_Empty.ToString();
|
locRepository.Update(tolocation, true);
|
agvtask_HtyRepository.AddTaskHistory(agvtask, OperateType.Delete.ToString());
|
agvRepository.Delete(agvtask, true);
|
result.Code = 0;
|
MESAPIInvoke.GetInterfaceInfo("DeleteTask", request.taskid, "", result.Code, result.Message);
|
WriteLog.Info("出库物料绑定MES调我们的接口").Write("结束," + request.taskid + "\t" + DateTime.Now, "DeleteTask");
|
}
|
}
|
catch (Exception ex)
|
{
|
result.Code = 1;
|
result.Message = ex.Message;
|
MESAPIInvoke.GetInterfaceInfo("DeleteTask", request.taskid, "", result.Code, result.Message);
|
WriteLog.Info("删除任务MES调我们的接口").Write("异常," + request.taskid + "\t" + ex.Message + "\t" + DateTime.Now, "DeleteTask");
|
}
|
return result;
|
}
|
public static ResultMaterstateUp DeleteZHXBarCode()
|
{
|
ResultMaterstateUp result = new ResultMaterstateUp();
|
try
|
{
|
VOLContext Context = new VOLContext();
|
WebResponseContent responseContent = new WebResponseContent();
|
Idt_task_numberRepository tasknumberRep = new dt_task_numberRepository(Context);
|
Ibill_group_stockRepository group_StockRepository = new bill_group_stockRepository(Context);
|
responseContent = tasknumberRep.DbContextBeginTransaction(() =>
|
{
|
var barcodelist = tasknumberRep.FindFirst(v => v.taskno == 1);
|
WriteLog.Info("没有删除之前的正极烘箱条码").Write(barcodelist + "\t" + DateTime.Now, "没有删除之前的正极烘箱条码");
|
string[] BarCodelist = barcodelist.numtype.Split(";");
|
string newBarcode = "";
|
if (BarCodelist.Length <= 2)
|
{
|
barcodelist.numtype = "";
|
tasknumberRep.Update(barcodelist, true);
|
for (int i = 1; i <= BarCodelist.Length; i++)
|
{
|
var stock = group_StockRepository.FindFirst(v => v.BarCode == BarCodelist[i - 1]);
|
if (stock != null)
|
{
|
group_StockRepository.Delete(stock, true);
|
}
|
}
|
}
|
else
|
{
|
for (int i = 2; i < BarCodelist.Length; i++)
|
{
|
if (!string.IsNullOrEmpty(BarCodelist[i]))
|
{
|
newBarcode = newBarcode + BarCodelist[i] + ";";
|
}
|
}
|
barcodelist.numtype = newBarcode;
|
tasknumberRep.Update(barcodelist, true);
|
var stock1 = group_StockRepository.FindFirst(v => v.BarCode == BarCodelist[0]);
|
if (stock1 != null)
|
{
|
group_StockRepository.Delete(stock1, true);
|
}
|
var stock2 = group_StockRepository.FindFirst(v => v.BarCode == BarCodelist[1]);
|
if (stock2 != null)
|
{
|
group_StockRepository.Delete(stock2, true);
|
}
|
|
}
|
result.Code = 0;
|
return WebResponseContent.Instance.OK();
|
});
|
}
|
catch (Exception ex)
|
{
|
throw;
|
}
|
return result;
|
}
|
public static ResultMaterstateUp DeleteFHXBarCode()
|
{
|
ResultMaterstateUp result = new ResultMaterstateUp();
|
try
|
{
|
VOLContext Context = new VOLContext();
|
WebResponseContent responseContent = new WebResponseContent();
|
Idt_task_numberRepository tasknumberRep = new dt_task_numberRepository(Context);
|
Ibill_group_stockRepository group_StockRepository = new bill_group_stockRepository(Context);
|
responseContent = tasknumberRep.DbContextBeginTransaction(() =>
|
{
|
var barcodelist = tasknumberRep.FindFirst(v => v.taskno == 2);
|
WriteLog.Info("没有删除之前的负极烘箱条码").Write(barcodelist + "\t" + DateTime.Now, "没有删除之前的负极烘箱条码");
|
string[] BarCodelist = barcodelist.numtype.Split(";");
|
string newBarcode = "";
|
if (BarCodelist.Length <= 2)
|
{
|
barcodelist.numtype = "";
|
tasknumberRep.Update(barcodelist, true);
|
for (int i = 1; i <= BarCodelist.Length; i++)
|
{
|
var stock = group_StockRepository.FindFirst(v => v.BarCode == BarCodelist[i - 1]);
|
if (stock != null)
|
{
|
group_StockRepository.Delete(stock, true);
|
}
|
}
|
}
|
else
|
{
|
for (int i = 2; i < BarCodelist.Length; i++)
|
{
|
if (!string.IsNullOrEmpty(BarCodelist[i]))
|
{
|
newBarcode = newBarcode + BarCodelist[i] + ";";
|
}
|
}
|
barcodelist.numtype = newBarcode;
|
tasknumberRep.Update(barcodelist, true);
|
var stock1 = group_StockRepository.FindFirst(v => v.BarCode == BarCodelist[0]);
|
if (stock1 != null)
|
{
|
group_StockRepository.Delete(stock1, true);
|
}
|
var stock2 = group_StockRepository.FindFirst(v => v.BarCode == BarCodelist[1]);
|
if (stock2 != null)
|
{
|
group_StockRepository.Delete(stock2, true);
|
}
|
}
|
result.Code = 0;
|
return WebResponseContent.Instance.OK();
|
});
|
}
|
catch (Exception ex)
|
{
|
throw;
|
}
|
return result;
|
}
|
|
public static WebResponseContent AddHKOneTask(string HKNo)
|
{
|
VOLContext Context = new VOLContext();
|
Idt_agvtaskRepository agvRepository = new dt_agvtaskRepository(Context);
|
Ibase_routing_tableRepository routingRepository = new base_routing_tableRepository(Context);
|
Idt_task_numberRepository tasknumberRep = new dt_task_numberRepository(Context);
|
dt_task_numberService tasknumber = new dt_task_numberService(tasknumberRep);
|
WebResponseContent responseContent = new WebResponseContent();
|
try
|
{
|
PLCClient plc = WCSService.Clients.Find(v => v.PLCName == HKNo);
|
if (plc == null)
|
throw new Exception(string.Format("{0}PLC为连接", HKNo));
|
|
var task = new List<dt_agvtask>();
|
if (plc.PLCDescroption.Contains("ZJSL"))
|
{
|
task = agvRepository.Find(f => f.agv_toaddress.Contains("ZJSL-GMHX")).ToList();
|
}
|
else
|
{
|
task = agvRepository.Find(f => f.agv_toaddress.Contains("FJSL-GMHX")).ToList();
|
}
|
if (task.Count >= 1)
|
throw new Exception("当前存在任务");
|
//获取隔膜烘箱上料请求
|
string isWork = plc.ReadValue(ConveyorLineInfoDBName.R_HKSB_UPrequest.ToString(), plc.PLCDescroption).ToString();
|
PLCClient hcxplc = WCSService.Clients.Find(v => v.PLCName == "正极提升机");
|
string isZGMWork = hcxplc.ReadValue(ConveyorLineInfoDBName.R_ZGMWork.ToString(), hcxplc.PLCDescroption).ToString();
|
string isFGMWork = hcxplc.ReadValue(ConveyorLineInfoDBName.R_FGMWork.ToString(), hcxplc.PLCDescroption).ToString();
|
string isZState = hcxplc.ReadValue(ConveyorLineInfoDBName.R_ZGMState.ToString(), hcxplc.PLCDescroption).ToString();
|
string isFState = hcxplc.ReadValue(ConveyorLineInfoDBName.R_FGMState.ToString(), hcxplc.PLCDescroption).ToString();
|
|
|
var route = routingRepository.Find(f => f.route_end == plc.PLCDescroption);
|
foreach (var r in route)
|
{
|
if (bool.Parse(isZGMWork) && int.Parse(isZState) == 2)
|
{
|
dt_agvtask agvtask = new dt_agvtask
|
{
|
agv_materbarcode = "A" + DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss") + "," + "B" + DateTime.Now.ToString("yyyy-MM-dd-HH-MM-SS"),
|
agv_barcode = "",
|
agv_code = "负极2号AGV",
|
agv_createtime = DateTime.Now,
|
agv_realesstime = DateTime.Now,
|
agv_fromaddress = r.route_began,
|
agv_grade = 1,
|
agv_materielid = "隔膜物料",
|
agv_qty = 1,
|
agv_tasknum = "KH-" + tasknumber.GetTaskNumber(tasknumberRep),
|
agv_taskstate = "Create",
|
agv_tasktype = "TaskType_Outbound",
|
agv_toaddress = plc.PLCDescroption,
|
agv_userid = "WCS",
|
agv_worktype = 1
|
};
|
agvRepository.Add(agvtask, true);
|
WriteLog.Info("AddHKOneTask").Write("AddHKOneTask" + "手动添加任务成功" + agvtask.agv_tasknum + DateTime.Now, "AddHKOneTask");
|
}
|
else if (bool.Parse(isFGMWork) && int.Parse(isFState) == 2)
|
{
|
dt_agvtask agvtask = new dt_agvtask
|
{
|
agv_materbarcode = "A" + DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss") + ";" + "B" + DateTime.Now.ToString("yyyy-MM-dd-HH-MM-SS"),
|
agv_barcode = "",
|
agv_code = "负极2号AGV",
|
agv_createtime = DateTime.Now,
|
agv_realesstime = DateTime.Now,
|
agv_fromaddress = r.route_began,
|
agv_grade = 1,
|
agv_materielid = "隔膜物料",
|
agv_qty = 1,
|
agv_tasknum = "KH-" + tasknumber.GetTaskNumber(tasknumberRep),
|
agv_taskstate = "Create",
|
agv_tasktype = "TaskType_Outbound",
|
agv_toaddress = plc.PLCDescroption,
|
agv_userid = "WCS",
|
agv_worktype = 1
|
};
|
agvRepository.Add(agvtask, true);
|
WriteLog.Info("AddHKOneTask").Write("AddHKOneTask" + "手动添加任务成功"+agvtask.agv_tasknum + DateTime.Now, "AddHKOneTask");
|
}
|
}
|
|
responseContent.Status = true;
|
}
|
catch (Exception ex)
|
{
|
responseContent.Message = ex.Message.ToString();
|
responseContent.Status = false;
|
}
|
return responseContent;
|
}
|
|
public static WebResponseContent AddHKTowTask(string HKNo)
|
{
|
|
VOLContext Context = new VOLContext();
|
Idt_agvtaskRepository agvRepository = new dt_agvtaskRepository(Context);
|
Ibase_routing_tableRepository routingRepository = new base_routing_tableRepository(Context);
|
Idt_task_numberRepository tasknumberRep = new dt_task_numberRepository(Context);
|
dt_task_numberService tasknumber = new dt_task_numberService(tasknumberRep);
|
Ibill_group_stockRepository groupRepository = new bill_group_stockRepository(Context);
|
WebResponseContent responseContent = new WebResponseContent();
|
try
|
{
|
|
PLCClient plc = WCSService.Clients.Find(v => v.PLCName == HKNo);
|
if (plc == null)
|
throw new Exception(string.Format("{0}PLC为连接", HKNo));
|
var hxtask = agvRepository.FindFirst(f => f.agv_fromaddress.Contains("KPHLX") && f.agv_toaddress == plc.PLCDescroption);
|
if (hxtask != null)
|
{
|
throw new Exception("当前存在回流任务");
|
}
|
var task = new List<dt_agvtask>();
|
if (plc.PLCDescroption.Contains("ZJSL"))
|
{
|
task = agvRepository.Find(f => f.agv_remark.Contains("ZJSL") && f.agv_taskstate == "WaitStockOut").ToList();
|
}
|
else
|
{
|
task = agvRepository.Find(f => f.agv_remark.Contains("FJSL") && f.agv_taskstate == "WaitStockOut").ToList();
|
}
|
if (task.Count >= 1)
|
throw new Exception("当前存在任务");
|
var stock = groupRepository.Find(v => v.Remark1 == plc.PLCDescroption).ToList();
|
if (stock.Count >= 1)
|
throw new Exception("当前存在库存任务");
|
WebResponseContent content = new WebResponseContent();
|
string[] tasknum = tasknumber.GetTaskNumber(tasknumberRep, 2).Split(";");
|
responseContent = agvRepository.DbContextBeginTransaction(() =>
|
{
|
for (int i = 0; i < 4; i++)
|
{
|
dt_agvtask agvtask = new dt_agvtask
|
{
|
agv_materbarcode = "daiding",
|
agv_barcode = "",
|
// agv_code = "正极1号AGV",
|
agv_createtime = DateTime.Now,
|
agv_realesstime = DateTime.Now,
|
agv_fromaddress = "nou",
|
agv_grade = 1,
|
agv_materielid = "",
|
agv_qty = 1,
|
agv_tasknum = "KH-" + tasknum[i],
|
agv_taskstate = "WaitStockOut",
|
agv_tasktype = "TaskType_Outbound",
|
agv_toaddress = "nou",
|
agv_userid = "WCS",
|
agv_worktype = 1,
|
agv_remark = plc.PLCDescroption
|
};
|
if (plc.PLCDescroption.Contains("ZJSL"))
|
{
|
agvtask.agv_code = "正极1号AGV";
|
//调用WMS呼叫物料出库
|
List<string> StockList = new List<string> { "ZXD0201", "ZXC0201", "ZXB0201", "ZXA0201" };
|
MESback WMSbackresult = MESAPIInvoke.OutNeedStosk(agvtask.agv_tasknum, StockList, 3, "", "", plc.PLCDescroption);
|
WriteLog.Info($"{HKNo}手动上料").Write($"正极1号AGV,MES返回数据:{JsonConvert.SerializeObject(WMSbackresult)},时间:" + DateTime.Now + "", $"{HKNo}手动上料");
|
if (WMSbackresult == null) { throw new Exception($"失败,任务号:{agvtask.agv_tasknum}"); }
|
agvRepository.Add(agvtask, true);
|
WriteLog.Info("Z_HKSB_UpTask").Write("Z_HKSB_UpTask" + agvtask.agv_tasknum + DateTime.Now, "Z_HKSB_UpTask");
|
}
|
else
|
{
|
agvtask.agv_code = "负极1号AGV";
|
//调用WMS呼叫物料出库
|
List<string> StockList = new List<string> { "FXD0201", "FXC0201", "FXB0201", "FXA0201" };
|
MESback WMSbackresult = MESAPIInvoke.OutNeedStosk(agvtask.agv_tasknum, StockList, 3, "", "", plc.PLCDescroption);
|
WriteLog.Info($"{HKNo}手动上料").Write($"负极1号AGV,MES返回数据:{JsonConvert.SerializeObject(WMSbackresult)},时间:" + DateTime.Now + "", $"{HKNo}手动上料");
|
if (WMSbackresult == null) { throw new Exception($"失败,任务号:{agvtask.agv_tasknum}"); }
|
agvRepository.Add(agvtask, true);
|
WriteLog.Info("Z_HKSB_UpTask").Write("Z_HKSB_UpTask" + agvtask.agv_tasknum + DateTime.Now, "Z_HKSB_UpTask");
|
}
|
}
|
plc.WriteValue(ConveyorLineInfoDBName.R_HKSB_IsWorkBatchNo.ToString(), plc.PLCDescroption, false).ToString();
|
return WebResponseContent.Instance.OK();
|
});
|
|
responseContent.Status = true;
|
}
|
catch (Exception ex)
|
{
|
responseContent.Message = ex.Message.ToString();
|
responseContent.Status = false;
|
}
|
return responseContent;
|
}
|
|
}
|
}
|