using Microsoft.EntityFrameworkCore;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
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.Extensions;
using WIDESEA_Core.Utilities;
using WIDESEA_Entity.DomainModels;
using WIDESEA_Services.IRepositories;
using WIDESEA_Services.Repositories;
using WIDESEA_WCS.JobsPart.Public;
using WIDESEA_WCS.WCSClient;
using static FreeSql.Internal.GlobalFilter;
namespace WIDESEA_WCS.SchedulerExecute.AGV
{
public partial class AGVSchedulerExecute
{
///
/// 辊分下料缓存架良品料自动搬运极库
///
public static async void AgvAndEquiWorkZJ()
{
WebResponseContent content = new WebResponseContent();
VOLContext Context = new VOLContext();
Idt_agvtaskRepository agvRepository = new dt_agvtaskRepository(Context);
Ibase_routing_tableRepository routingRepository = new base_routing_tableRepository(Context);
Ibase_ware_locationRepository ibase_Ware_Location = new base_ware_locationRepository(Context);
List ware_Locatiolist = ibase_Ware_Location.Find(d => d.upper_code.Contains("GFHCJ") && d.logic_col == 1 && d.task == 2 && d.status == 1 && d.geartype != "暂无").ToList();
//if (ware_Locatio == null)
//{
// return ;
//}
foreach (var listloction in ware_Locatiolist)
{
List gfloction = new List();
List routing_table = routingRepository.Find(v => v.route_began == listloction.upper_code).ToList();
if (routing_table.Count > 0)
{
foreach (var item in routing_table)
{
base_ware_location ware_Location = ibase_Ware_Location.FindFirst(d => d.upper_code == item.route_end && d.location_state == LoctionStateEnum.LocationState_Empty.ToString() && d.logic_col == 0 && d.tpgd == 0 && d.status == 1 && d.task == 2 && d.geartype == "暂无");
if (ware_Location != null)
{
gfloction.Add(ware_Location);
}
}
if (gfloction.Count > 0)
{
base_ware_location ware_Locatio = ibase_Ware_Location.FindFirst(d => d.upper_code == listloction.upper_code);
if (ware_Locatio == null) { continue; }
base_ware_location lotion = gfloction.OrderBy(d => d.order_num).FirstOrDefault();
dt_agvtask agvtask = new dt_agvtask
{
agv_id = Guid.NewGuid(),
agv_tasknum = "KH-" + IdenxManager.GetTaskNo(),
agv_fromaddress = ware_Locatio.upper_code,
agv_toaddress = lotion.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 = ""
};
listloction.update_time = DateTime.Now;
ware_Locatio.logic_col = 1;//设置良品物料
ware_Locatio.task = 1;//设置任务生成1
ware_Locatio.light_color = "无";
var entrys = ibase_Ware_Location.DbContext.ChangeTracker.Entries().FirstOrDefault();
if (entrys != null)
{
entrys.State = EntityState.Detached;
}
int begin = ibase_Ware_Location.Update(ware_Locatio, d => new { d.logic_col, d.task, d.update_time, d.light_color }, true);
lotion.update_time = DateTime.Now;
lotion.logic_col = 1;
lotion.task = 1;
lotion.geartype = ware_Locatio.geartype;
var entry = ibase_Ware_Location.DbContext.ChangeTracker.Entries().FirstOrDefault();
if (entry != null)
{
entry.State = EntityState.Detached;
}
int end = ibase_Ware_Location.Update(lotion, d => new { d.logic_col, d.task, d.update_time, d.geartype }, true);
if (begin == 1 && end == 1)
{
agvRepository.Add(agvtask, true);//任务生成
return;
}
}
}
}
}
}
}