using HslCommunication;
using System;
using System.Threading;
using System.Threading.Tasks;
using WIDESEA_Common;
using WIDESEA_Common.LoctionEnum;
using WIDESEA_Common.Tools;
using WIDESEA_Core.EFDbContext;
using WIDESEA_Core.Utilities;
using WIDESEA_Entity.DomainModels;
using WIDESEA_Services.IRepositories;
using WIDESEA_Services.Repositories;
using WIDESEA_Services.Services;
using WIDESEA_WCS.WCSClient;
namespace WIDESEA_WCS
{
public partial class StackerExecutor
{
public static object requestFJTSJ = new object();//requestZJJK
private static int _readTSJDOWNSignalsoFTSJ = 0;//_readZTBUPSignalso
///
/// 负极辊分下料工作逻辑
///
///
public static void F_TSJ_DownTask()
{
if (Interlocked.Exchange(ref _readTSJDOWNSignalsoFTSJ, 1) == 0)
{
Task.Run(() =>
{
try
{
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 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);
Idt_agvtask_htyRepository agvhtyRepository = new dt_agvtask_htyRepository(Context);
Ibill_group_stockRepository groupRepository = new bill_group_stockRepository(Context);
if (WCSService.Clients == null)
{
return;
}
PLCClient plc = WCSService.Clients.Find(v => v.PLCName == "负极箔材提升机");
if (plc == null)
{
return;
}
//当前设备有没有下料请求
//bool TSJ_CL = Convert.ToBoolean(plc.ReadValue("R_Feedingrequest".ToString(), plc.PLCDescroption));
OperateResult TSJ_CL = plc.SiemensPLCClient.SiemensS7NetClient.ReadBool("DB51.93");
if (TSJ_CL.Content)
{
//查看当前辊分机设备是否有AGV任务
var SBtask = agvRepository.FindFirst(f => f.agv_fromaddress == plc.PLCDescroption);
//有结束本次循环
if (SBtask != null) { return; }
base_ware_location ware_Locations = locRepository.FindFirst(d => d.upper_code == "FJ-BCHCJ37" && d.location_state == LoctionStateEnum.LocationState_Empty.ToString() && d.tpgd == 0 && d.status == 1 && d.task == 2);
if (ware_Locations != null)
{
//生成提升机机下料任务
dt_agvtask agvtask = new dt_agvtask
{
agv_id = Guid.NewGuid(),
agv_tasknum = "KH-" + IdenxManager.GetTaskNo(),
agv_fromaddress = plc.PLCDescroption,
agv_toaddress = ware_Locations.upper_code,
agv_code = "负极AGV调度",
agv_remark = "负极提升机下料",
agv_taskstate = AGVTaskStateEnum.Create.ToString(),
agv_tasktype = AGVTaskTypeEnum.TaskType_Outbound.ToString(),
agv_worktype = 1,//工作类型
agv_materielid = "",
agv_qty = 1,
agv_createtime = DateTime.Now,
agv_grade = 0,//任务优先级
agv_userid = "WCS",
agv_barcode = "",
};
ware_Locations.task = 1;
ware_Locations.update_time = DateTime.Now;
int a = locRepository.Update(ware_Locations, d => new { d.task, d.update_time }, true);
if (a == 1)
{
agvRepository.Add(agvtask, true);
//WriteDBLog.Info($"负极提升机下料任务生成").Write($"生成任务:{agvtask.agv_tasknum},终点货位【{ware_Locations.upper_code}】状态:托盘光电检测:{ware_Locations.tpgd},状态:{ware_Locations.location_state},更新时间:{ware_Locations.wireless_time}", $"负极提升机下料任务生成");
//WriteDBLog.Info($"负极提升机下料任务生成").Write($"----------------任务生成成功 {DateTime.Now} -------------- {Environment.NewLine}", $"负极提升机下料任务生成");
}
//WriteLog.GetLog("设备呼叫").Write($"设备 {plc.PLCDescroption} 呼叫成功,任务{agvtask.agv_tasknum}生成", "设备呼叫");
}
}
}
catch (Exception ex)
{
WriteLog.GetLog().Write($"负极提升机下料:{DateTime.Now} --------------{ex}", $"负极提升机下料调度");
}
finally
{
Interlocked.Exchange(ref _readTSJDOWNSignalsoFTSJ, 0);
}
});
}
}
}
}