using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using System.Threading;
|
using WIDESEA_Common;
|
using WIDESEA_Common.Tools;
|
using WIDESEA_Core.EFDbContext;
|
using WIDESEA_Core.Utilities;
|
using WIDESEA_Entity.DomainModels;
|
using WIDESEA_Services;
|
using WIDESEA_Services.IRepositories;
|
using WIDESEA_Services.Repositories;
|
using WIDESEA_Services.Services;
|
using WIDESEA_WCS.WCSClient;
|
|
namespace WIDESEA_WCS.Jobs
|
{
|
public partial class EquipmentExecutor : SchedulerExecuteBase
|
{
|
private static int _readZQXDownSignalso = 0;
|
/// <summary>
|
/// 清洗设备下料逻辑
|
/// </summary>
|
/// <returns></returns>
|
public static void Z_QXSB_DownTask()
|
{
|
if (Interlocked.Exchange(ref _readZQXDownSignalso, 1) == 0)
|
{
|
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 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);
|
Ibill_group_stockRepository groupRepository = new bill_group_stockRepository(Context);
|
List<string> QXSB = new List<string> { "正极清洗机" };
|
PLCClient zagvplc = WCSService.Clients.Find(v => v.PLCName == "正极1号AGV");
|
foreach (var item in QXSB)
|
{
|
PLCClient plc = WCSService.Clients.Find(v => v.PLCName == item);
|
var task = agvRepository.FindFirst(f => f.agv_fromaddress == plc.PLCDownLoc);
|
if (task == null)
|
{
|
//获取下料请求
|
string isWork = plc.ReadValue(ConveyorLineInfoDBName.R_QXSB_DOWNrequest.ToString(), plc.PLCDescroption).ToString();
|
//获取工单号
|
string batchNo = plc.ReadValue(ConveyorLineInfoDBName.R_QXSB_DOWNbatchNo.ToString(), plc.PLCDescroption).ToString();
|
GetEquipmentInfo(plc.PLCDownLoc, isWork, batchNo, "", "");
|
if (bool.Parse(isWork))
|
{
|
//调用MES接口获取下料信息
|
MESback material = MESAPIInvoke.EquipUnloading(plc.PLCDownLoc, batchNo);
|
if (material.Code == 0)
|
{
|
//查找下料库存
|
var stock = groupRepository.FindFirst(v => v.MaterialType == material.MaterialType);
|
if (stock == null)
|
{
|
WriteLog.Info("Z_QXSB_DownTask").Write(item + "下料异常,查询到" + material.BarCode + "库存信息", "Z_QXSB_DownTask");
|
continue;
|
}
|
//查询路由信息
|
var routes = routingRepository.Find(v => v.route_began == plc.PLCDownLoc).ToList();
|
|
foreach (var route in routes)
|
{
|
string ismaterial = zagvplc.ReadValue(ConveyorLineInfoDBName.R_Location_iswork.ToString(), route.route_end).ToString();
|
GetEquipmentInfo(plc.PLCDownLoc, isWork, batchNo, "", ismaterial);
|
if (ismaterial == "2")
|
continue;
|
var location = locRepository.FindFirst(v => v.upper_code == route.route_end);
|
if (location.location_state != LocationStateEnum.LocationState_Empty.ToString())
|
continue;
|
//条件全部通过,生成AGV任务
|
dt_agvtask agvtask = new dt_agvtask
|
{
|
agv_materbarcode = "daiding",//下料任务预先没有条码,PDA在缓存架绑定时接收新的条码
|
agv_barcode = "",
|
agv_code = "正极1号AGV",
|
agv_createtime = DateTime.Now,
|
agv_fromaddress = route.route_began,
|
agv_grade = 1,
|
agv_materielid = material.MaterialType,
|
agv_qty = 1,
|
agv_tasknum = "KH-" + tasknumber.GetTaskNumber(tasknumberRep),
|
agv_taskstate = "Create",
|
agv_tasktype = "TaskType_Outbound",
|
agv_toaddress = route.route_end,
|
agv_userid = "WCS",
|
agv_worktype = 1
|
};
|
location.location_state = LocationStateEnum.LocationState_Lock.ToString();
|
locRepository.Update(location, true);
|
agvRepository.Add(agvtask, true);
|
WriteLog.Info("Z_QXSB_DownTask").Write("Z_QXSB_DownTask" + agvtask.agv_tasknum + DateTime.Now, "Z_QXSB_DownTask");
|
break;
|
}
|
|
}
|
else
|
{
|
WriteLog.Info("Z_QXSB_DownTask").Write("调用MES接口EquipUnloading失败" + material.Message, "Z_QXSB_DownTask");
|
}
|
}
|
}
|
}
|
}
|
catch (Exception)
|
{
|
|
}
|
finally
|
{
|
Interlocked.Exchange(ref _readZQXDownSignalso, 0);
|
}
|
}
|
|
}
|
}
|
}
|