using Microsoft.CodeAnalysis;
|
using Microsoft.EntityFrameworkCore;
|
using Newtonsoft.Json;
|
using Newtonsoft.Json.Linq;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using WIDESEA_Common;
|
using WIDESEA_Common.LoctionEnum;
|
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_WCS.JobsPart.Public;
|
|
namespace WIDESEA_WCS
|
{
|
public class WIFIService
|
{
|
private static int wifibutton = 0;
|
public static WebResponseContent Rolloffcall(object num)
|
{
|
|
WebResponseContent content = new WebResponseContent();
|
try
|
{
|
if (num == null)
|
{
|
return content.Error("呼叫失败,请求值为空");
|
}
|
string loctionid = JsonConvert.SerializeObject(num);
|
var jObject = JObject.Parse(loctionid);
|
string locNum = jObject["NUM"].ToString();
|
//string locNum = num.ToString();
|
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);
|
base_ware_location ware_Locatio = ibase_Ware_Location.FindFirst(d => d.upper_code == locNum && d.task == 2);
|
if (ware_Locatio == null)
|
{
|
return content.Error("辊分货架按钮请求失败");
|
}
|
|
if (locNum.Contains("GFHCJ"))
|
{
|
|
if (ware_Locatio.logic_col==1)
|
{
|
|
ware_Locatio.update_time = DateTime.Now;
|
ware_Locatio.logic_col = 0;//设置未良品物料
|
|
int gf = ibase_Ware_Location.Update(ware_Locatio, d => new { d.logic_col, d.update_time }, true);
|
if (gf != 1)
|
{
|
return content.Error("辊分货架按钮请求失败");
|
}
|
else
|
{
|
content.OK("呼叫成功", 2);
|
}
|
}
|
else if(ware_Locatio.logic_col == 0)
|
{
|
base_ware_location location_GF = ibase_Ware_Location.FindFirst(t => t.upper_code == locNum && t.location_state == LocationStateEnum.LocationState_Stored.ToString() && t.tpgd == 1 && t.status == 1 && (t.gd1 == 1 || t.gd2 == 1 || t.gd3 == 1 || t.gd4 == 1) && t.task == 2);
|
if (location_GF == null)
|
{
|
return content.Error("辊分货架按钮请求失败");
|
}
|
if (location_GF.geartype == "暂无")
|
{
|
return content.Error("辊分货架按钮请求失败");
|
}
|
|
location_GF.update_time = DateTime.Now;
|
location_GF.logic_col = 1;//设置良品物料
|
|
int gf = ibase_Ware_Location.Update(location_GF, d => new { d.logic_col, d.update_time }, true);
|
if (gf != 1)
|
{
|
return content.Error("辊分货架按钮请求失败");
|
}
|
else
|
{
|
content.OK("呼叫成功", 1);
|
}
|
}
|
else
|
{
|
|
return content.Error($"质检状态异常,无法切换");
|
}
|
|
}
|
else if (locNum.Contains("JKHCJ") || locNum.Contains("BCHCJ") || locNum.Contains("TBHCJ"))
|
{
|
|
string logname = "";
|
if (locNum.Contains("JKHCJ"))
|
{
|
logname = "极库按钮请求记录";
|
}
|
else if (locNum.Contains("BCHCJ"))
|
{
|
logname = "箔材按钮请求记录";
|
}
|
else if (locNum.Contains("TBHCJ"))
|
{
|
logname = "涂布按钮请求记录";
|
}
|
WriteLog.GetLog().Write($"---------------接口调用开始,时间:{DateTime.Now}------------", $"{logname}");
|
base_ware_location ware_Location = ibase_Ware_Location.FindFirst(d => d.upper_code == locNum && d.location_state == LoctionStateEnum.LocationState_Stored.ToString() && d.tpgd == 1 && d.task == 2 && d.status == 1);
|
if (ware_Location == null)
|
{
|
return content.Error($"质检状态异常,无法切换");
|
}
|
if ((ware_Location.upper_code.Contains("BCHCJ37") && ware_Location.logic_row == "TSJXL-BCK") || (ware_Location.upper_code.Contains("BCHCJ35") && ware_Location.logic_row == "TBXL-BCK"))
|
{
|
return content.Error($"质检状态异常,无法切换");
|
}
|
if (ware_Location.logic_col == 1)
|
{
|
|
ware_Location.logic_col = 0;
|
ware_Location.update_time = DateTime.Now;
|
var entry = ibase_Ware_Location.DbContext.ChangeTracker.Entries<base_ware_location>().FirstOrDefault();
|
if (entry != null)
|
{
|
entry.State = EntityState.Detached;
|
}
|
int x = ibase_Ware_Location.Update(ware_Location, d => new
|
{
|
d.logic_col,
|
d.update_time
|
}, true);
|
if (x!=1)
|
{
|
return content.Error("货架按钮请求失败");
|
}
|
else
|
{
|
return content.OK("呼叫成功", 2);
|
}
|
|
}
|
else if (ware_Location.logic_col == 0)
|
{
|
|
ware_Location.logic_col = 1;
|
ware_Location.update_time = DateTime.Now;
|
var entry = ibase_Ware_Location.DbContext.ChangeTracker.Entries<base_ware_location>().FirstOrDefault();
|
if (entry != null)
|
{
|
entry.State = EntityState.Detached;
|
}
|
int aw = ibase_Ware_Location.Update(ware_Location, d => new
|
{
|
d.logic_col,
|
d.update_time
|
}, true);
|
if (aw!=1)
|
{
|
return content.Error("货架按钮请求失败");
|
}
|
else
|
{
|
return content.OK("呼叫成功", 1);
|
} }
|
else
|
{
|
return content.Error($"质检状态异常,无法切换");
|
}
|
}
|
else if (locNum.Contains("QJHCJ"))
|
{
|
base_ware_location location_QJ = ibase_Ware_Location.FindFirst(t => t.upper_code == locNum && t.location_state == LocationStateEnum.LocationState_Empty.ToString() && t.tpgd == 0 && t.gd1 == 0 && t.gd2 == 0 && t.gd3 == 0 && t.gd4 == 0 && t.status == 1 && t.task == 2);
|
if (location_QJ == null)
|
{
|
return content.Error("切卷叫料失败");
|
}
|
if (location_QJ.geartype == "暂无")
|
{
|
return content.Error("切卷叫料失败");
|
}
|
List<base_routing_table> routing_table = routingRepository.Find(v => v.route_end == location_QJ.upper_code).ToList();
|
List<base_ware_location> jkloction = new List<base_ware_location>();
|
if (routing_table.Count > 0)//无料才能生成任务&& location_QJ.tpgd==0
|
{
|
foreach (var item in routing_table)
|
{
|
base_ware_location ware_Location = ibase_Ware_Location.FindFirst(d => d.upper_code == item.route_began && d.location_state == LoctionStateEnum.LocationState_Stored.ToString() && d.logic_col == 1 && d.tpgd == 1 && d.status == 1 && d.task == 2 && d.geartype == location_QJ.geartype);
|
if (ware_Location != null)
|
{
|
jkloction.Add(ware_Location);
|
}
|
}
|
if (jkloction.Count > 0)
|
{
|
#region 记录上料请求信号
|
WriteLog.GetLog().Write($"{locNum}上料请求---{DateTime.Now}", $"切卷上料请求");
|
#endregion
|
//再次判断是否有任务存在
|
dt_agvtask agvtaskOld = agvRepository.FindFirst(x=>x.agv_toaddress== location_QJ.upper_code);
|
if (agvtaskOld!=null && location_QJ.task==2)
|
{
|
location_QJ.logic_col = 1;//设置良品物料
|
location_QJ.task = 1;//设置任务生成1
|
var ent = ibase_Ware_Location.DbContext.ChangeTracker.Entries<base_ware_location>().FirstOrDefault();
|
if (ent != null)
|
{
|
ent.State = EntityState.Detached;
|
}
|
ibase_Ware_Location.Update(location_QJ, true);
|
return content.Error("改缓存架任务已存在");
|
}
|
base_ware_location lotion = jkloction.OrderBy(d => d.update_time).FirstOrDefault();
|
dt_agvtask agvtask = new dt_agvtask()
|
{
|
agv_id = Guid.NewGuid(),
|
agv_tasknum = "KH-" + IdenxManager.GetTaskNo(),
|
agv_fromaddress = lotion.upper_code,
|
agv_toaddress = location_QJ.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 = ""
|
};
|
location_QJ.logic_col = 1;//设置良品物料
|
location_QJ.task = 1;//设置任务生成1
|
var entry = ibase_Ware_Location.DbContext.ChangeTracker.Entries<base_ware_location>().FirstOrDefault();
|
if (entry != null)
|
{
|
entry.State = EntityState.Detached;
|
}
|
int dw= ibase_Ware_Location.Update(location_QJ, d => new { d.logic_col, d.task }, true);
|
if (dw!=1)
|
{
|
return content.Error("辊分货架按钮请求失败");
|
}
|
|
|
lotion.logic_col = 1;//设置良品物料
|
lotion.task = 1;//设置任务生成1
|
var entrys = ibase_Ware_Location.DbContext.ChangeTracker.Entries<base_ware_location>().FirstOrDefault();
|
if (entrys != null)
|
{
|
entrys.State = EntityState.Detached;
|
}
|
int be= ibase_Ware_Location.Update(lotion, d => new { d.logic_col, d.task }, true);
|
if (be != 1)
|
{
|
return content.Error("辊分货架按钮请求失败");
|
}
|
|
if (be==1&& dw==1)
|
{
|
agvRepository.Add(agvtask, true);//任务生成
|
//WriteDBLog.Info($"切卷按钮任务生成").Write($"生成任务:{agvtask.agv_tasknum}", $"切卷按钮任务生成");
|
//WriteDBLog.Info($"切卷按钮任务生成").Write($"起点货位【{lotion.upper_code}】状态:托盘光电检测:{lotion.tpgd},状态:{lotion.location_state},更新时间:{lotion.wireless_time}", $"切卷按钮任务生成");
|
//WriteDBLog.Info($"切卷按钮任务生成").Write($"终点货位【{location_QJ.upper_code}】状态:托盘光电检测:{location_QJ.tpgd},-1光电:{location_QJ.gd2},-2光电:{location_QJ.gd1},-3光电:{location_QJ.gd4},-4光电:{location_QJ.gd3},状态:{location_QJ.location_state},更新时间:{location_QJ.wireless_time}", $"切卷按钮任务生成");
|
//WriteDBLog.Info($"切卷按钮任务生成").Write($"----------------任务生成成功 {DateTime.Now} -------------- {Environment.NewLine}", $"切卷按钮任务生成");
|
return content.OK("呼叫成功,任务已记录", 1);
|
}
|
}
|
else
|
{
|
//WriteLog.GetLog($"切卷按钮请求记录").Write($"切卷呼叫货位:{locNum},时间:{DateTime.Now},内容:未找到满足送往切卷的料", "切卷按钮请求记录");
|
//WriteLog.GetLog($"切卷按钮请求记录").Write($"---------------结束记录,时间:{DateTime.Now}------------{Environment.NewLine}", "切卷按钮请求记录");
|
return content.Error("未找到满足送往切卷的极库料");
|
}
|
}
|
else
|
{
|
return content.Error("切卷叫料失败");
|
}
|
}
|
return content;
|
|
|
}
|
catch (Exception ex)
|
{
|
|
return content.Error(ex.Message);
|
}
|
|
|
}
|
|
public class GFparameter
|
{
|
public string loctioncode { get; set; }
|
public bool fig { get; set; }
|
}
|
}
|
}
|