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 _readZFINOUTSignalso = 0;
|
public static object requestJJK = new object();
|
/// <summary>
|
/// 正极和负极大及卷库出入库逻辑
|
/// </summary>
|
/// <returns></returns>
|
public static void ZF_InOut_Djjk()
|
{
|
|
if (Interlocked.Exchange(ref _readZFINOUTSignalso, 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> HCJnos = new List<string> {"ZJSL-FQHCJ001","ZJSL-TBHCJ007","ZJSL-TBHCJ008","ZJSL-TBHCJ009","ZJSL-TBHCJ010","ZJSL-TBHCJ011","ZJSL-TBHCJ012",
|
"ZJSL-TBHCJ001","ZJSL-TBHCJ002","ZJSL-TBHCJ003","ZJSL-TBHCJ004","ZJSL-TBHCJ005","ZJSL-TBHCJ006",
|
"ZJSL-QXHCJ001","ZJSL-QXHCJ002", "ZJSL-GYHCJ001", "ZJSL-GYHCJ002", "ZJSL-GYHCJ003","ZJSL-FQHCJ002"};
|
PLCClient plc = null;
|
string toadd = "";
|
var task = agvRepository.FindFirst(f=>(f.agv_toaddress.Contains("JJK")&&f.agv_fromaddress.Contains("ZJ"))||(f.agv_fromaddress=="nou"&&f.agv_toaddress.Contains("HCJ")&& f.agv_toaddress.Contains("ZJ")));
|
if (task!=null)
|
{
|
WriteLog.Info("ZF_InOut_Djjk").Write("正极大极卷库有正在执行的任务" + DateTime.Now, "ZF_InOut_Djjk");
|
return;
|
}
|
foreach (var hcj in HCJnos)
|
{
|
toadd = "ZJXL-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 == "ZJSL-JJK001" && f.down_code == "ZJXL-JJK001");
|
if (stock == null)
|
continue;
|
//判断当前状态是否有更新
|
if (hcj.Contains("QX") && hcj.Contains("ZJ"))
|
{
|
if (string.IsNullOrEmpty(stock.TB_Status))
|
{
|
continue;
|
}
|
}
|
else if (hcj.Contains("TB") && hcj.Contains("ZJ"))
|
{
|
if (string.IsNullOrEmpty(stock.TB_Status))
|
{
|
continue;
|
}
|
}
|
else if (hcj.Contains("FQ") && hcj.Contains("ZJ"))
|
{
|
if (string.IsNullOrEmpty(stock.GY_Status))
|
{
|
continue;
|
}
|
}
|
else if (hcj.Contains("GY") && hcj.Contains("ZJ"))
|
{
|
if (string.IsNullOrEmpty(stock.QX_Status))
|
{
|
continue;
|
}
|
}
|
lock (requestJJK)
|
{
|
if (loc.location_state == LocationStateEnum.LocationState_Empty.ToString() && location.location_state == LocationStateEnum.LocationState_Stored.ToString() && stock.BarCode != null && stock.MaterialStatus != null)
|
{
|
responseContent = locRepository.DbContextBeginTransaction(() =>
|
{
|
MESback WMSbackresult = MESAPIInvoke.PreTask(1);
|
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("ZF_InOut_Djjk").Write("ZF_InOut_Djjk" + agvtask.agv_tasknum + stock.BarCode + DateTime.Now, "ZF_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("ZF_InOut_Djjk").Write("ZF_InOut_Djjk" + ex.Message + DateTime.Now, "ZF_InOut_Djjk");
|
}
|
finally
|
{
|
Interlocked.Exchange(ref _readZFINOUTSignalso, 0);
|
}
|
}
|
}
|
}
|
}
|