using System; using System.Collections.Generic; 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 _readZTSJSignalso = 0; /// /// 正极提升机口有下料请求 /// /// public static void Z_TSJ_DownTask() { if (Interlocked.Exchange(ref _readZTSJSignalso, 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); PLCClient plc = WCSService.Clients.Find(v => v.PLCName == "正极提升机"); if (plc == null) return; //获取三楼正极上料请求 DB1002.693.0 string isZWork = plc.ReadValue(ConveyorLineInfoDBName.R_ZTSJ_Downrequest.ToString(), plc.PLCDescroption).ToString(); //获取三楼负极上料请求 string isFWork = plc.ReadValue(ConveyorLineInfoDBName.R_FTSJ_Downrequest.ToString(), plc.PLCDescroption).ToString(); WriteLog.Info("提升机请求").Write("Z_TSJ_DownTask,正极:" + isZWork+"负极:" + isFWork + DateTime.Now, "提升机请求"); if (bool.Parse(isZWork)) { string newBarcode = ""; string fromAdd = "ZJXL-WLX002"; //查询是否有任务存在 var task = agvRepository.FindFirst(v => v.agv_fromaddress == fromAdd); if (task != null) return; //读取物料条码 //BarCode = plc.ReadValue(ConveyorLineInfoDBName.R_ZTSJ_Barcode.ToString(), plc.PLCDescroption).ToString(); //当AGV完成时,并且任务是去三楼的,则将任务条码保存在数据库中,三楼下料时,每次取前两个条码,并删除前两个条码 var barcodelist = tasknumberRep.FindFirst(v => v.taskno == 1); string[] BarCodelist = barcodelist.numtype.Split(";"); if (BarCodelist.Length <= 2 && (string.IsNullOrEmpty(BarCodelist[1]) || string.IsNullOrEmpty(BarCodelist[0]))) { if (string.IsNullOrEmpty(BarCodelist[0]) ) { barcodelist.numtype = barcodelist.numtype.Substring(1, barcodelist.numtype.Length-1); tasknumberRep.Update(barcodelist, true); } return; } var hxtask = agvRepository.FindFirst(f => f.agv_materbarcode.Contains(BarCodelist[0])); if (hxtask != null) { var agvtaskold= agvRepository.FindFirst(v => v.agv_fromaddress == "错误展示"); agvtaskold.agv_realesstime = DateTime.Now; agvtaskold.ErrMsg = "提升机有下料请求,但当前条码已经存在任务"; agvRepository.Update(agvtaskold,true); throw new Exception(string.Format("正极提升机有下料请求,但当前条码已经存在任务{0}", BarCodelist[0])); } //查找库存 var stock = groupRepository.FindFirst(v => v.BarCode == BarCodelist[0]); if (stock == null) { var agvtaskold = agvRepository.FindFirst(v => v.agv_fromaddress == "错误展示"); agvtaskold.ErrMsg = "正极提升机有下料请求,但请求条码未查询到库存信息"; agvtaskold.agv_realesstime = DateTime.Now; agvRepository.Update(agvtaskold, true); WriteLog.Info("Z_TSJ_DownTask").Write("提升机有下料请求,但请求条码未查询到库存信息,条码是" + BarCodelist[0] + DateTime.Now, "Z_TSJ_DownTask"); return; } string BarCode = BarCodelist[0] + ";" + BarCodelist[1]; WriteLog.Info("正极提升机下料时的两个烘箱条码").Write(BarCode +"\t"+ DateTime.Now, "正极提升机下料时的两个烘箱条码"); for (int i = 2; i < BarCodelist.Length; i++) { if (!string.IsNullOrEmpty(BarCodelist[i])) { newBarcode = newBarcode + BarCodelist[i] + ";"; } } barcodelist.numtype = newBarcode; tasknumberRep.Update(barcodelist, true); dt_agvtask agvtask = new dt_agvtask { agv_materbarcode = BarCode, agv_barcode = "", agv_code = "负极2号AGV", agv_createtime = DateTime.Now, agv_fromaddress = fromAdd, agv_grade = 1, agv_materielid = stock.BarCode, agv_qty = 1, agv_tasknum = "KH-" + tasknumber.GetTaskNumber(tasknumberRep), agv_taskstate = "Create", agv_tasktype = "TaskType_Outbound", agv_toaddress = stock.Remark1, agv_userid = "WCS", agv_worktype = 1 }; agvRepository.Add(agvtask, true); WriteLog.Info("Z_TSJ_DownTask").Write("Z_TSJ_DownTask" + agvtask.agv_tasknum + DateTime.Now, "Z_TSJ_DownTask"); } if (bool.Parse(isFWork)) { string newBarcode = ""; string fromAdd = "FJXL-WLX002"; //查询是否有任务存在 var task = agvRepository.FindFirst(v => v.agv_fromaddress == fromAdd); if (task != null) return; //BarCode = plc.ReadValue(ConveyorLineInfoDBName.R_FTSJ_Barcode.ToString(), plc.PLCDescroption).ToString(); //当AGV完成时,并且任务是去三楼的,则将任务条码保存在数据库中,三楼下料时,每次取前两个条码,并删除前两个条码 var barcodelist = tasknumberRep.FindFirst(v => v.taskno == 2); string[] BarCodelist = barcodelist.numtype.Split(";"); if (BarCodelist.Length <= 2 && (string.IsNullOrEmpty(BarCodelist[1])|| string.IsNullOrEmpty(BarCodelist[0]))) { if (string.IsNullOrEmpty(BarCodelist[0])) { barcodelist.numtype = barcodelist.numtype.Substring(1, barcodelist.numtype.Length - 1); tasknumberRep.Update(barcodelist, true); } return; } var hxtask = agvRepository.FindFirst(f => f.agv_materbarcode.Contains(BarCodelist[0])); if (hxtask != null) { var agvtaskold = agvRepository.FindFirst(v => v.agv_fromaddress == "错误展示"); agvtaskold.ErrMsg = "负极提升机有下料请求,但当前条码已经存在任务"; agvtaskold.agv_realesstime = DateTime.Now; agvRepository.Update(agvtaskold, true); throw new Exception(string.Format("提升机有下料请求,但当前条码已经存在任务{0}", BarCodelist[0])); } //查找库存 var stock = groupRepository.FindFirst(v => v.BarCode == BarCodelist[0]); if (stock == null) { var agvtaskold = agvRepository.FindFirst(v => v.agv_fromaddress == "错误展示"); agvtaskold.ErrMsg = "负极提升机有下料请求,但请求条码未查询到库存信息"; agvtaskold.agv_realesstime = DateTime.Now; agvRepository.Update(agvtaskold, true); WriteLog.Info("Z_TSJ_DownTask").Write("提升机有下料请求,但请求条码未查询到库存信息,条码是" + BarCodelist[0] + DateTime.Now, "Z_TSJ_DownTask"); return; } string BarCode = BarCodelist[0] + ";" + BarCodelist[1]; WriteLog.Info("负极提升机下料时的两个烘箱条码").Write(BarCode + "\t" + DateTime.Now, "负极提升机下料时的两个烘箱条码"); for (int i = 2; i < BarCodelist.Length; i++) { if (!string.IsNullOrEmpty(BarCodelist[i])) { newBarcode = newBarcode + BarCodelist[i] + ";"; } } barcodelist.numtype = newBarcode; tasknumberRep.Update(barcodelist, true); dt_agvtask agvtask = new dt_agvtask { agv_materbarcode = BarCode, agv_barcode = "", agv_code = "负极2号AGV", agv_createtime = DateTime.Now, agv_fromaddress = fromAdd, agv_grade = 1, agv_materielid = stock.BarCode, agv_qty = 1, agv_tasknum = "KH-" + tasknumber.GetTaskNumber(tasknumberRep), agv_taskstate = "Create", agv_tasktype = "TaskType_Outbound", agv_toaddress = stock.Remark1, agv_userid = "WCS", agv_worktype = 1 }; agvRepository.Add(agvtask, true); WriteLog.Info("Z_TSJ_DownTask").Write("Z_TSJ_DownTask" + agvtask.agv_tasknum + stock.BarCode + DateTime.Now, "Z_TSJ_DownTask"); } } catch (Exception ex) { WriteLog.Info("Z_TSJ_DownTask").Write("Z_TSJ_DownTask" + ex.Message + DateTime.Now, "Z_TSJ_DownTask"); } finally { Interlocked.Exchange(ref _readZTSJSignalso, 0); } } } } }