using HslCommunication;
|
using Newtonsoft.Json;
|
using System;
|
using System.Collections.Generic;
|
using System.Diagnostics;
|
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 _readZHKUPSignalso = 0;
|
public static void Z_HKSB_UpTask()
|
{
|
if (Interlocked.Exchange(ref _readZHKUPSignalso, 1) == 0)
|
{
|
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);
|
Ibill_group_stockRepository groupRepository = new bill_group_stockRepository(Context);
|
List<string> HKSBs = new List<string> { "正极3号烘烤机", "正极4号烘烤机", "正极5号烘烤机", "正极6号烘烤机",
|
"正极7号烘烤机", "正极8号烘烤机", "正极9号烘烤机", "正极10号烘烤机",
|
"负极3号烘烤机", "负极4号烘烤机","负极5号烘烤机", "负极6号烘烤机", "负极7号烘烤机", "负极8号烘烤机",
|
"负极9号烘烤机", "负极10号烘烤机" };
|
//List<string> HKSBs = new List<string> { "正极9号烘烤机", "正极10号烘烤机" };
|
foreach (var hksb in HKSBs)
|
{
|
WriteLog.Info($"{hksb}上料").Write($"{hksb}开始,时间:" + DateTime.Now + " ----------", $"{hksb}上料");
|
PLCClient plc = WCSService.Clients.Find(v => v.PLCName == hksb);
|
if (plc == null)
|
continue;
|
var hxtask = agvRepository.FindFirst(f => f.agv_fromaddress.Contains("KPHLX") && f.agv_toaddress == plc.PLCDescroption);
|
if (hxtask != null) { GetEquipmentInfo(plc.PLCDescroption, "", "当前有烘箱回流任务", "", ""); continue; }
|
//启用工单
|
string IsBatchNo = plc.ReadValue(ConveyorLineInfoDBName.R_HKSB_IsWorkBatchNo.ToString(), plc.PLCDescroption).ToString();
|
if (IsBatchNo == "False") { GetEquipmentInfo(plc.PLCDescroption, "", "烘箱启用工单为"+IsBatchNo, "", ""); continue; }
|
WriteLog.Info($"{hksb}上料").Write($"IsBatchNo:{IsBatchNo},时间:" + DateTime.Now + " ----------", $"{hksb}上料");
|
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)
|
continue;
|
var stock = groupRepository.Find(v => v.Remark1 == plc.PLCDescroption).ToList();
|
if (stock.Count >= 1)
|
continue;
|
//获取上料请求
|
string isWork = plc.ReadValue(ConveyorLineInfoDBName.R_HKSB_UPrequest.ToString(), plc.PLCDescroption).ToString();
|
WriteLog.Info($"{hksb}上料").Write($"isWork:{isWork},时间:" + DateTime.Now + " ----------", $"{hksb}上料");
|
GetEquipmentInfo(plc.PLCDescroption, isWork, "", "", "");
|
if (isWork != "5")
|
continue;
|
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($"{hksb}上料").Write($"正极1号AGV,MES返回数据:{JsonConvert.SerializeObject(WMSbackresult)},时间:" + DateTime.Now + "", $"{hksb}上料");
|
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($"{hksb}上料").Write($"负极1号AGV,MES返回数据:{JsonConvert.SerializeObject(WMSbackresult)},时间:" + DateTime.Now + "", $"{hksb}上料");
|
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();
|
});
|
WriteLog.Info($"{hksb}上料").Write($"{hksb}结束,时间:" + DateTime.Now + $" ----------{Environment.NewLine}", $"{hksb}上料");
|
break;
|
}
|
}
|
catch (Exception ex)
|
{
|
WriteLog.Info("Z_HKSB_UpTask").Write("Z_HKSB_UpTask" + ex.Message + DateTime.Now, "Z_HKSB_UpTask");
|
}
|
finally
|
{
|
Interlocked.Exchange(ref _readZHKUPSignalso, 0);
|
}
|
}
|
}
|
}
|
}
|