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.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 _readZLJSignalso = 0;
|
public static object requestFX = new object();
|
public static object requestZX = new object();
|
/// <summary>
|
/// 中转料架逻辑流程
|
/// </summary>
|
/// <returns></returns>
|
public static void Z_ZZLJ_Task()
|
{
|
if (Interlocked.Exchange(ref _readZLJSignalso, 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);
|
Idt_agvtask_htyRepository agvtask_HtyRepository = new dt_agvtask_htyRepository(Context);
|
List<string> ZZLJS = new List<string> { "ZJXL-ZZLJ001", "ZJXL-ZZLJ002", "ZJXL-ZZLJ003", "ZJXL-ZZLJ004", "FJXL-ZZLJ001",
|
"FJXL-ZZLJ002", "FJXL-ZZLJ003", "FJXL-ZZLJ004" };
|
foreach (var ZZLJ in ZZLJS)
|
{
|
var location = locRepository.FindFirst(v => v.down_code == ZZLJ);
|
var stocks = groupRepository.Find(v => v.location_id == location.id);
|
var stock = new bill_group_stock();
|
if (stocks.Count() > 0)
|
{
|
stock = stocks.OrderByDescending(o => o.created_time).First();
|
}
|
else
|
{
|
continue;
|
}
|
//判断分切的状态
|
if (stock != null && (stock.FQ_Status == "OK" || stock.FQ_Status == "NG"))
|
{
|
string address = "";
|
bool choose = false;
|
var KClocation = new base_ware_location();
|
string toaddressnum = "";
|
if (location.location_state == LocationStateEnum.LocationState_Stored.ToString())
|
{
|
if (ZZLJ.Contains("ZJXL"))
|
{
|
lock (requestZX)
|
{
|
var tasks = agvRepository.Find(f => f.agv_toaddress.Contains("ZX"));
|
if (tasks.Count() == 0)
|
{
|
var taskthy = agvtask_HtyRepository.Find(f => f.agv_toaddress.Contains("ZX") && (f.agv_taskstate == "Finished" || f.agv_taskstate == "ManualCompletion")).OrderByDescending(o => o.agv_createtime).First();
|
toaddressnum = taskthy.agv_toaddress.Substring(2, 1);
|
}
|
else
|
{
|
var task = tasks.OrderByDescending(o => o.agv_createtime).First();
|
toaddressnum = task.agv_toaddress.Substring(2, 1);
|
}
|
List<string> nums = new List<string>() { "ZXD0101", "ZXB0101", "ZXC0101", "ZXA0101" };
|
int count = 0;
|
for (int i=0;i<nums.Count();i++)
|
{
|
var loc = locRepository.FindFirst(f=>f.upper_code==nums[i]);
|
if (loc.location_state==LocationStateEnum.LocationState_Empty.ToString())
|
{
|
count = 1;
|
}
|
}
|
if (count==0) { continue; }
|
for (int i = 1; i < 5; i++)
|
{
|
if (choose)
|
{
|
KClocation = locRepository.FindFirst(v => v.upper_code == nums[i - 1]);
|
if (KClocation.location_state == LocationStateEnum.LocationState_Empty.ToString())
|
{
|
address = KClocation.upper_code;
|
choose = false;
|
break;
|
}
|
else
|
{
|
if (nums[i - 1].Contains("A")) { i = 0; }
|
continue;
|
}
|
}
|
else if (nums[i - 1].Contains(toaddressnum))
|
{
|
choose = true;
|
if (toaddressnum == "A") { i = 0; }
|
continue;
|
}
|
else
|
{
|
continue;
|
}
|
}
|
}
|
}
|
else if (ZZLJ.Contains("FJXL"))
|
{
|
lock (requestFX)
|
{
|
var tasks = agvRepository.Find(f => f.agv_toaddress.Contains("FX"));
|
if (tasks.Count() == 0)
|
{
|
var taskthy = agvtask_HtyRepository.Find(f => f.agv_toaddress.Contains("FX") && (f.agv_taskstate == "Finished" || f.agv_taskstate == "ManualCompletion")).OrderByDescending(o => o.agv_createtime).First();
|
toaddressnum = taskthy.agv_toaddress.Substring(2, 1);
|
}
|
else
|
{
|
var task = tasks.OrderByDescending(o => o.agv_createtime).First();
|
toaddressnum = task.agv_toaddress.Substring(2, 1);
|
}
|
List<string> nums = new List<string>() { "FXD0101", "FXB0101", "FXC0101", "FXA0101" };
|
int count = 0;
|
for (int i = 0; i < nums.Count(); i++)
|
{
|
var loc = locRepository.FindFirst(f => f.upper_code == nums[i]);
|
if (loc.location_state == LocationStateEnum.LocationState_Empty.ToString())
|
{
|
count = 1;
|
}
|
}
|
if (count == 0) { continue; }
|
for (int i = 1; i < 5; i++)
|
{
|
if (choose)
|
{
|
KClocation = locRepository.FindFirst(v => v.upper_code == nums[i - 1]);
|
if (KClocation.location_state == LocationStateEnum.LocationState_Empty.ToString())
|
{
|
address = KClocation.upper_code;
|
choose = false;
|
break;
|
}
|
else
|
{
|
if (nums[i - 1].Contains("A")) { i = 0; }
|
continue;
|
}
|
}
|
else if (nums[i - 1].Contains(toaddressnum))
|
{
|
choose = true;
|
if (toaddressnum == "A") { i = 0; }
|
continue;
|
}
|
else
|
{
|
continue;
|
}
|
}
|
}
|
}
|
if (!string.IsNullOrEmpty(address))
|
{
|
responseContent = locRepository.DbContextBeginTransaction(() =>
|
{
|
//条件全部通过,生成AGV任务
|
dt_agvtask agvtask = new dt_agvtask
|
{
|
agv_materbarcode = stock.BarCode,
|
agv_barcode = "",
|
agv_createtime = DateTime.Now,
|
agv_fromaddress = ZZLJ,
|
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 = address,
|
agv_userid = "WCS",
|
agv_worktype = 1
|
};
|
if (ZZLJ.Contains("ZJXL"))
|
{
|
agvtask.agv_code = "正极1号AGV";
|
}
|
else
|
{
|
agvtask.agv_code = "负极1号AGV";
|
}
|
stock.FQ_Status = stock.FQ_Status + "doing";
|
groupRepository.Update(stock, true);
|
agvRepository.Add(agvtask, true);
|
WriteLog.Info("Z_ZZLJ_Task").Write("Z_ZZLJ_Task" + agvtask.agv_tasknum + stock.BarCode + DateTime.Now, "Z_ZZLJ_Task");
|
location.location_state = LocationStateEnum.LocationState_Lock.ToString();
|
locRepository.Update(location, true);
|
KClocation.location_state = LocationStateEnum.LocationState_Lock.ToString();
|
locRepository.Update(KClocation, true);
|
return WebResponseContent.Instance.OK();
|
});
|
break;
|
}
|
}
|
|
}
|
}
|
}
|
catch (Exception ex)
|
{
|
WriteLog.Info("Z_ZZLJ_Task").Write("Z_ZZLJ_Task" + ex.Message + DateTime.Now, "Z_ZZLJ_Task");
|
throw new Exception(ex.Message);
|
}
|
finally
|
{
|
Interlocked.Exchange(ref _readZLJSignalso, 0);
|
}
|
}
|
}
|
}
|
}
|