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 _readFINOUTSignalso = 0;
|
public static object requestFJJK = new object();
|
/// <summary>
|
/// 正极和负极大及卷库出入库逻辑
|
/// </summary>
|
/// <returns></returns>
|
public static void F_InOut_Djjk()
|
{
|
|
if (Interlocked.Exchange(ref _readFINOUTSignalso, 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> HCJnos = new List<string> { "FJSL-FQHCJ001",
|
"FJSL-TBHCJ007","FJSL-TBHCJ008","FJSL-TBHCJ009","FJSL-TBHCJ010","FJSL-TBHCJ011","FJSL-TBHCJ012",
|
"FJSL-TBHCJ001","FJSL-TBHCJ002","FJSL-TBHCJ003","FJSL-TBHCJ004","FJSL-TBHCJ005","FJSL-TBHCJ006",
|
"FJSL-FQHCJ002","FJSL-GYHCJ001","FJSL-GYHCJ002","FJSL-GYHCJ003","FJSL-QXHCJ001","FJSL-QXHCJ002"};
|
PLCClient plc = null;
|
string toadd = "";
|
var task = agvRepository.FindFirst(f => (f.agv_toaddress.Contains("JJK") && f.agv_fromaddress.Contains("FJ")) || (f.agv_fromaddress == "nou" && f.agv_toaddress.Contains("HCJ") && f.agv_toaddress.Contains("FJ")));
|
if (task != null)
|
{
|
WriteLog.Info("F_InOut_Djjk").Write("负极大极卷库有正在执行的任务" + DateTime.Now, "F_InOut_Djjk");
|
return;
|
}
|
foreach (var hcj in HCJnos)
|
{
|
toadd = "FJXL-JJK001";
|
plc = WCSService.Clients.Find(v => v.PLCName == "负极1号AGV");
|
if (plc == null)
|
continue;
|
var iswork = plc.ReadValue(ConveyorLineInfoDBName.R_Location_iswork.ToString(), toadd).ToString();
|
if (iswork == "2")
|
continue;
|
//读取有货无货信号
|
var isemptyorwork = plc.ReadValue(ConveyorLineInfoDBName.R_Location_iswork.ToString(), hcj).ToString();
|
GetEquipmentInfo(toadd, hcj+"的货位状态是"+ isemptyorwork, "", "", iswork);
|
if (isemptyorwork == "1")
|
continue;
|
var location = locRepository.FindFirst(v => v.upper_code == hcj);
|
var stock = groupRepository.Find(v => v.location_id == location.id).OrderByDescending(v => v.created_time).FirstOrDefault();
|
var loc = locRepository.FindFirst(f => f.upper_code == "FJSL-JJK001" && f.down_code == "FJXL-JJK001");
|
if (stock == null)
|
continue;
|
//判断当前状态是否有更新
|
if (hcj.Contains("TB") && hcj.Contains("FJ"))
|
{
|
if (string.IsNullOrEmpty(stock.TB_Status))
|
{
|
continue;
|
}
|
}
|
else if (hcj.Contains("FQ") && hcj.Contains("FJ"))
|
{
|
if (string.IsNullOrEmpty(stock.QX_Status))
|
{
|
continue;
|
}
|
}
|
else if (hcj.Contains("QX") && hcj.Contains("FJ"))
|
{
|
if (string.IsNullOrEmpty(stock.GY_Status))
|
{
|
continue;
|
}
|
}
|
else if (hcj.Contains("GY") && hcj.Contains("FJ"))
|
{
|
if (string.IsNullOrEmpty(stock.TB_Status))
|
{
|
continue;
|
}
|
}
|
lock (requestFJJK)
|
{
|
if (loc.location_state == LocationStateEnum.LocationState_Empty.ToString() && location.location_state == LocationStateEnum.LocationState_Stored.ToString() && stock.BarCode != null && stock.MaterialStatus != null)
|
{
|
WebResponseContent responseContent = new WebResponseContent();
|
responseContent = locRepository.DbContextBeginTransaction(() =>
|
{
|
MESback WMSbackresult = MESAPIInvoke.PreTask(2);
|
if (WMSbackresult == null)
|
{
|
return WebResponseContent.Instance.Error("负极大极卷库不通过入库申请");
|
}
|
dt_agvtask agvtask = new dt_agvtask
|
{
|
agv_materbarcode = stock.BarCode,
|
agv_barcode = "",
|
agv_code = plc.PLCName,
|
agv_createtime = DateTime.Now,
|
agv_fromaddress = hcj,
|
agv_grade = 1,
|
agv_materielid = stock.MaterialType,
|
agv_qty = 1,
|
agv_tasknum = "KH-" + tasknumber.GetTaskNumber(tasknumberRep),
|
agv_taskstate = "Create",
|
agv_tasktype = "TaskType_Outbound",
|
agv_toaddress = toadd,
|
agv_userid = "WCS",
|
agv_worktype = 1
|
};
|
agvRepository.Add(agvtask, true);
|
WriteLog.Info("F_InOut_Djjk").Write("F_InOut_Djjk" + agvtask.agv_tasknum + stock.BarCode + DateTime.Now, "F_InOut_Djjk");
|
location.location_state = LocationStateEnum.LocationState_Lock.ToString();
|
loc.location_state = LocationStateEnum.LocationState_Lock.ToString();
|
locRepository.Update(loc, true);
|
locRepository.Update(location, true);
|
return WebResponseContent.Instance.OK();
|
});
|
}
|
}
|
}
|
}
|
catch (Exception ex)
|
{
|
WriteLog.Info("F_InOut_Djjk").Write("F_InOut_Djjk" + ex.Message + DateTime.Now, "F_InOut_Djjk");
|
}
|
finally
|
{
|
Interlocked.Exchange(ref _readFINOUTSignalso, 0);
|
}
|
}
|
}
|
}
|
}
|