From 9c6f213884183f6f3a49f224fc9723e84e53f226 Mon Sep 17 00:00:00 2001
From: dengjunjie <dengjunjie@hnkhzn.com>
Date: 星期一, 25 三月 2024 14:07:34 +0800
Subject: [PATCH] 数据库更新
---
代码管理/PCS/WCS_Server/WIDESEA_WCS/Jobs/equipment/PipelineJob.cs | 403 +++++++++++++++++++++++++++++++++++++++++++++++++-------
1 files changed, 348 insertions(+), 55 deletions(-)
diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WCS/Jobs/equipment/PipelineJob.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WCS/Jobs/equipment/PipelineJob.cs"
index 4d94346..b452b93 100644
--- "a/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WCS/Jobs/equipment/PipelineJob.cs"
+++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WCS/Jobs/equipment/PipelineJob.cs"
@@ -1,17 +1,27 @@
-锘縰sing Quartz;
+锘縰sing HslCommunication;
+using Microsoft.AspNetCore.Mvc;
+using Newtonsoft.Json;
+using Quartz;
using System;
using System.Collections.Generic;
using System.Linq;
+using System.Reflection;
using System.Text;
using System.Threading.Tasks;
+using System.Xml.Linq;
using WIDESEA_Comm;
+using WIDESEA_Comm.LogInfo;
+using WIDESEA_Comm.TaskNo;
using WIDESEA_Core.BaseProvider;
using WIDESEA_Core.EFDbContext;
-using WIDESEA_Core.FreeDB;
+using WIDESEA_Core.Extensions;
+using WIDESEA_Entity.DomainModels;
using WIDESEA_WCS.IRepositories;
using WIDESEA_WCS.Jobs;
using WIDESEA_WCS.Repositories;
using WIDESEA_WCS.WCSClient;
+using WIDESEA_WMS.IRepositories;
+using WIDESEA_WMS.Repositories;
using static System.Collections.Specialized.BitVector32;
namespace WIDESEA_WCS
@@ -26,20 +36,6 @@
{
try
{
- var client = context.JobDetail.JobDataMap.Get("JobParams") as PLCClient;
- if (client == null)
- {
- return Task.CompletedTask;
- }
-
- //鑷姩閲嶈繛
- if (!client.IsConnected)
- {
- client.Connect();
- return Task.CompletedTask;
- }
-
- //DoAction(client);
ExecuteJob(context, DoAction);
}
catch { }
@@ -55,7 +51,10 @@
client.Connect();
return;
}
+ client.WriteByOrder("W_Palpitate", client.ReadByOrder<bool>("R_Palpitate", "蹇冭烦"));
Loadinglevel(client);
+ AutoEmptyTray(client);
+ StationState(client);
}
/// <summary>
/// 涓婃枡鍖�
@@ -63,57 +62,351 @@
/// <param name="client"></param>
private void Loadinglevel(PLCClient client, string number = "涓婃枡鍖�")
{
- VOLContext Context = new VOLContext();
- Idt_plcinfoheadRepository repository = new dt_plcinfoheadRepository(Context);
- Idt_plcinfodetailRepository plcRepository = new dt_plcinfodetailRepository(Context);
- Idt_geometry_dataRepository dataRepository = new dt_geometry_dataRepository(Context);
- Idt_stationinfoRepository stationinfoRepository = new dt_stationinfoRepository(Context);
- var plc = repository.FindFirst(x => x.plcinfo_name == client.PLCName);
- var Gantry_client = PLCClient.Clients.FirstOrDefault(t => t.PLCName == "妗佹灦");
- if (!Gantry_client.IsConnected) return;
- var Gantryplc = repository.FindFirst(x => x.plcinfo_name == Gantry_client.PLCName);
- List<string> names = new List<string>() { "S01001001", "S01001002" };
- foreach (string name in names)
+ try
{
- var station = stationinfoRepository.FindFirst(x => x.stationCode == name && x.enable && x.location_state == LocationStateEnum.Stroge.ToString());
- if (station == null)
+ VOLContext Context = new VOLContext();
+ Idt_plcinfoheadRepository repository = new dt_plcinfoheadRepository(Context);
+ Idt_plcinfodetailRepository plcRepository = new dt_plcinfodetailRepository(Context);
+ Idt_geometry_dataRepository dataRepository = new dt_geometry_dataRepository(Context);
+ Idt_stationinfoRepository stationinfoRepository = new dt_stationinfoRepository(Context);
+ var plc = repository.FindFirst(x => x.plcinfo_name == client.PLCName);
+ var Gantry_client = PLCClient.Clients.FirstOrDefault(t => t.PLCName == "妗佹灦");
+ if (Gantry_client == null) throw new Exception("妗佹灦璋冨害鏈嶅姟鏈紑鍚紒");
+ if (!Gantry_client.IsConnected) throw new Exception("涓庢鏋惰繛鎺ヨ秴鏃讹紒");
+ var Gantryplc = repository.FindFirst(x => x.plcinfo_name == Gantry_client.PLCName);
+
+
+ ///鏌ユ壘涓婃枡鍖虹殑璐т綅
+ var Stations = stationinfoRepository.Find(x => x.area == area_code(number));
+ //缂撳瓨鏋舵湭鍚敤绂佹妗佹灦杩涘叆
+ foreach (var station in Stations)
{
- Gantry_client.WriteByOrder("W_RequestUnload", false, number);//淇″彿涓篺alse妗佹灦鍋滄杩涘叆
- continue;
+ if (!station.enable || station.location_state != LocationStateEnum.Stroge.ToString())
+ Gantry_client.WriteByOrder("W_RequestUnload", false, number);//淇″彿涓篺alse妗佹灦鍋滄杩涘叆
}
- var details = plcRepository.Find(x => x.plcdetail_iotype == plc.plcinfo_iotyep && x.plcdetail_number == name).ToList();
- var PalletSignal = (Int16)DBExtension.Read(details.Where(x => x.plcdetail_name == "R_PalletSignal").First(), client);//璇诲彇鎵樼洏淇″彿:1:鏈�,2鏃�
- var MaterialSignal = (Int16)DBExtension.Read(details.Where(x => x.plcdetail_name == "R_MaterialSignal").First(), client);//璇诲彇璐х墿淇″彿:1:鏈�,2鏃�
- if (PalletSignal == 1 && MaterialSignal == 1)
+
+ var Station = Stations?.Where(x => x.enable && x.location_state == LocationStateEnum.Stroge.ToString() && x.quantity > 0).OrderBy(x => x.quantity).FirstOrDefault();
+ if (Station != null)
{
- Gantry_client.WriteByOrder("W_AreaNr", (Int16)1, number);//鍖哄煙璐т綅鍙�
- Gantry_client.WriteByOrder("W_IndexNr", (Int16)1, number);//鎵樼洏涓婄殑绗嚑涓溅杞�
- Gantry_client.WriteByOrder("W_Storage_Type", (Int16)1, number); //鎵樼洏绫诲瀷1-妯斁;2-绔栨斁
- Gantry_client.WriteByOrder("W_Wheel_Type", (Int16)1, number);//杞﹁疆绫诲瀷
- Gantry_client.WriteByOrder("W_Wheel_id", "", number);//杞﹁疆SN鍙�
- Gantry_client.WriteByOrder("W_RequestUnload", true, number);
+ var SNS = Station.bindSN.Split(",");
+ List<string> list = new List<string>();
+ foreach (var SN in SNS)
+ {
+ if (!string.IsNullOrEmpty(SN))
+ list.Add(SN);
+ }
+ //缂撳瓨鏋朵笂杞﹁疆鏁伴噺涓嶴N鍙锋暟閲忎笉涓�鑷�
+ if (list.Count != Station.quantity)
+ {
+ Station.location_state = LocationStateEnum.Abnormal.ToString();
+ Station.remark = "杞﹁疆鏁伴噺涓嶴N鍙锋暟閲忎笉涓�鑷�";
+ stationinfoRepository.Update(Station, true);
+ Gantry_client.WriteByOrder("W_RequestUnload", false, number);//淇″彿涓篺alse妗佹灦鍋滄杩涘叆
+ #region 鏃ュ織璁板綍
+ WriteDBLog.Error("涓婃枡鍖�", $"鍐欏叆妗佹灦淇℃伅锛歕nW_RequestUnload锛歠alse\n\n{Station.stationCode}杞﹁疆鏁伴噺涓嶴N鍙锋暟閲忎笉涓�鑷�", "PCS");
+ #endregion
+ return;
+ //throw new Exception("涓婃枡浣嶈溅杞暟閲忎笌SN鍙锋暟閲忎笉涓�鑷达紝涓婃枡浣嶇紪鍙凤細" + Station.stationCode);
+ }
+ var details = plcRepository.Find(x => x.plcdetail_iotype == plc.plcinfo_iotyep && x.plcdetail_number == Station.stationCode).ToList();
+ var PalletSignal = (Int16)DBExtension.Read(details.Where(x => x.plcdetail_name == "R_PalletSignal").First(), client);//璇诲彇鎵樼洏淇″彿:1:鏈�,2鏃�
+ var MaterialSignal = (Int16)DBExtension.Read(details.Where(x => x.plcdetail_name == "R_MaterialSignal").First(), client);//璇诲彇璐х墿淇″彿:1:鏈�,2鏃�
+ if (PalletSignal == 1 && MaterialSignal == 1)
+ {
+ var area = Convert.ToInt16(Station.stationCode.Substring(Station.stationCode.Length - 1, 1));
+ Gantry_client.WriteByOrder("W_AreaNr", (Int16)area, number);//鍖哄煙璐т綅鍙�
+ Gantry_client.WriteByOrder("W_IndexNr", (Int16)SNS.Length, number);//鎵樼洏涓婄殑绗嚑涓溅杞�
+ Gantry_client.WriteByOrder("W_Storage_Type", (Int16)1, number); //鎵樼洏绫诲瀷1-妯斁;2-绔栨斁
+ Gantry_client.WriteByOrder("W_Wheel_Type", (Int16)Convert.ToInt16(QueryMateriel(Station.stationType) == null ? QueryMateriel1(Station.stationType).TypeId : QueryMateriel(Station.stationType).TypeId), number);//杞﹁疆绫诲瀷
+ Gantry_client.WriteByOrder("W_Wheel_id", SNS[SNS.Length - 1], number);//杞﹁疆SN鍙�
+ Gantry_client.WriteByOrder("W_RequestUnload", true, number);
+ #region 鏃ュ織璁板綍
+ WriteDBLog.Success("涓婃枡鍖虹敵璇�", $"璇诲彇鎵樼洏鍏夌數淇″彿锛歿PalletSignal}\n璇诲彇绗竴涓溅杞厜鐢典俊鍙凤細{MaterialSignal}\n\n" +
+ $"鍐欏叆妗佹灦淇℃伅锛歕n鍖哄煙璐т綅鍙凤細{area}\n鎵樼洏涓婄殑绗嚑涓溅杞細{SNS.Length}\n鎵樼洏绫诲瀷锛歿1}\n杞﹁疆绫诲瀷锛歿(QueryMateriel(Station.stationType).TypeId == null ? QueryMateriel1(Station.stationType).TypeId : QueryMateriel(Station.stationType).TypeId)}" +
+ $"\n杞﹁疆SN鍙凤細{SNS[SNS.Length - 1]}\nW_RequestUnload锛歵rue", "PCS");
+ #endregion
+ }
+ else
+ {
+ Gantry_client.WriteByOrder("W_RequestUnload", false, number);
+ }
+
+ var Gantrydetails = plcRepository.Find(x => x.plcdetail_iotype == Gantryplc.plcinfo_iotyep && x.plcdetail_number == number).ToList();
+ var Gantry_Out_of_Area = (bool)DBExtension.Read(Gantrydetails.Where(x => x.plcdetail_name == "R_Gantry_Out_of_Area").First(), Gantry_client);//妗佹灦鏄惁鍦ㄥ尯鍩熷唴
+
+ var QueryDate = (bool)DBExtension.Read(Gantrydetails.Where(x => x.plcdetail_name == "R_QueryDate").First(), Gantry_client);//淇℃伅鏌ヨ
+ if (QueryDate)
+ {
+ var Date_Vaild = (bool)DBExtension.Read(Gantrydetails.Where(x => x.plcdetail_name == "R_Date_Vaild").First(), Gantry_client);//淇℃伅纭
+ if (!Date_Vaild)//淇℃伅鏈夎锛岃褰曟棩蹇�
+ {
+ Station.location_state = LocationStateEnum.Abnormal.ToString();
+ Station.remark = $"鏈煡璇㈠埌SN鍙凤細{SNS[SNS.Length - 1]}鐨勮鍗�";
+ stationinfoRepository.Update(Station, true);
+ Gantry_client.WriteByOrder("W_RequestUnload", false, number);//淇″彿涓篺alse妗佹灦鍋滄杩涘叆
+ //throw new Exception($"鏈煡璇㈠埌SN鍙凤細{SNS[SNS.Length - 1]}鐨勮鍗曪紝涓婃枡浣嶇紪鍙凤細{Station.stationCode}");
+ WriteDBLog.Error("涓婃枡鍖轰俊鎭煡璇�", $"鍐欏叆妗佹灦淇℃伅锛歕nW_RequestUnload锛歠alse\n\n{Station.stationCode}鏈煡璇㈠埌SN鍙凤細{SNS[SNS.Length - 1]}鐨勮鍗�", "PCS");
+ return;
+ }
+ }
+ var finished = (bool)DBExtension.Read(Gantrydetails.Where(x => x.plcdetail_name == "R_Unlod_finished").First(), Gantry_client);//澶瑰彇瀹屾垚
+ var updatefinished = (bool)DBExtension.Read(Gantrydetails.Where(x => x.plcdetail_name == "W_Storage_update").First(), Gantry_client);//璐т綅鐘舵�佹洿鏂�
+ if (!finished && updatefinished)
+ Gantry_client.WriteByOrder("W_Storage_update", false, number);//璐т綅鐘舵�佹洿鏂�
+ if (finished && !updatefinished)
+ {
+ Gantry_client.WriteByOrder("W_RequestUnload", false, number);//淇″彿涓篺alse妗佹灦鍋滄杩涘叆
+ Updatemes(SNS[SNS.Length - 1]);
+ Station.quantity = Station.quantity - 1;
+ Station.bindSN = OperStr(SNS);
+ if (Station.quantity <= 0)
+ {
+ Station.stationType = string.Empty;
+ //Station.location_state = LocationStateEnum.Empty.ToString();
+ Station.Number = string.Empty;
+ Station.heatNumber = string.Empty;
+ Station.tray_status = "EmptyTray";
+ }
+ var count = stationinfoRepository.Update(Station, true);
+ if (count < 1)
+ {
+ WriteDBLog.Error("鍙栨枡瀹屾垚", $"涓婃枡浣嶄俊鎭洿鏂板け璐ワ紒涓婃枡浣嶇紪鍙凤細{Station.stationCode}", "PCS");
+ //throw new Exception($"涓婃枡浣嶄俊鎭洿鏂板け璐ワ紒涓婃枡浣嶇紪鍙凤細{Station.stationCode}");
+ return;
+ }
+ Gantry_client.WriteByOrder("W_Storage_update", true, number);//璐т綅鐘舵�佹洿鏂�
+ #region 鏃ュ織璁板綍
+ WriteDBLog.Success("鍙栨枡瀹屾垚", $"鍐欏叆妗佹灦淇℃伅锛歕n璐т綅鐘舵�佹洿鏂帮細{true}\nW_RequestUnload锛歿false}", "PCS");
+ #endregion
+ //finished = (bool)DBExtension.Read(Gantrydetails.Where(x => x.plcdetail_name == "R_Unlod_finished").First(), Gantry_client);
+ //while (finished)
+ //{
+ // finished = (bool)DBExtension.Read(Gantrydetails.Where(x => x.plcdetail_name == "R_Unlod_finished").First(), Gantry_client);
+ // Gantry_client.WriteByOrder("W_Storage_update", false, number);//璐т綅鐘舵�佹洿鏂�
+ //}
+ }
+ //else if (!finished && updatefinished)
+ // Gantry_client.WriteByOrder("W_Storage_update", false, number);//璐т綅鐘舵�佹洿鏂�
+
}
else
+ Gantry_client.WriteByOrder("W_RequestUnload", false, number);//淇″彿涓篺alse妗佹灦鍋滄杩涘叆
+ }
+ catch (Exception ex)
+ {
+ WriteDBLog.Error("涓婃枡鍖�", $"閿欒淇℃伅锛歿ex.Message}", "PCS");
+ //WritePCSLog.LogAdd(requestin.AreaNr.ToString(), respone.success == 1 ? "鎴愬姛 " : "澶辫触", "WMS", "AGV", json, JsonConvert.SerializeObject(respone), remark, "妫�娴嬬嚎涓婃枡鍖�", ex.Message);
+ }
+ }
+ /// <summary>
+ /// 鑷姩鍙栫┖鎵�
+ /// </summary>
+ /// <param name="client"></param>
+ private void AutoEmptyTray(PLCClient client)
+ {
+ try
+ {
+ VOLContext Context = new VOLContext();
+ Idt_plcinfoheadRepository repository = new dt_plcinfoheadRepository(Context);
+ Idt_plcinfodetailRepository plcRepository = new dt_plcinfodetailRepository(Context);
+ Idt_agvtaskRepository agvtaskService = new dt_agvtaskRepository(Context);
+ Idt_stationinfoRepository stationinfoRepository = new dt_stationinfoRepository(Context);
+ var plc = repository.FindFirst(x => x.plcinfo_name == client.PLCName);
+ List<string> stationCodes = new List<string>() { "S01001001", "S01001002", "W01001001", "W01001002", "W01001003" };
+ foreach (var stationCode in stationCodes)
{
- Gantry_client.WriteByOrder("W_RequestUnload", false, number);
- }
- var Gantrydetails = plcRepository.Find(x => x.plcdetail_iotype == Gantryplc.plcinfo_iotyep && x.plcdetail_number == number).ToList();
- var Gantry_Out_of_Area = (bool)DBExtension.Read(Gantrydetails.Where(x => x.plcdetail_name == "R_Gantry_Out_of_Area").First(), Gantry_client);//妗佹灦鏄惁鍦ㄥ尯鍩熷唴
-
- var QueryDate = (bool)DBExtension.Read(Gantrydetails.Where(x => x.plcdetail_name == "R_QueryDate").First(), Gantry_client);//淇℃伅鏌ヨ
- if (QueryDate)
- {
- var Date_Vaild = (bool)DBExtension.Read(Gantrydetails.Where(x => x.plcdetail_name == "R_Date_Vaild").First(), Gantry_client);//淇℃伅纭
- if (!Date_Vaild)//淇℃伅鏈夎锛岃褰曟棩蹇�
+ if (agvtaskService.Find(x => x.agv_fromaddress == stationCode || x.agv_toaddress == stationCode).Any())
+ continue;
+ var details = plcRepository.Find(x => x.plcdetail_iotype == plc.plcinfo_iotyep && x.plcdetail_number == stationCode).ToList();
+ var PalletSignal = (Int16)DBExtension.Read(details.Where(x => x.plcdetail_name == "R_PalletSignal").First(), client);//璇诲彇鎵樼洏淇″彿:1:鏈�,2鏃�
+ var MaterialSignal = (Int16)DBExtension.Read(details.Where(x => x.plcdetail_name == "R_MaterialSignal").First(), client);//璇诲彇璐х墿淇″彿:1:鏈�,2鏃�
+ var station = stationinfoRepository.Find(x => x.stationCode == stationCode).FirstOrDefault();
+ if (PalletSignal == 1 && MaterialSignal == 2 && (station.stationCode.Contains("S0100100") ? station.tray_status == "EmptyTray" : true))
{
+ var area = station.tray_type == "SmallTray" ? "11" : "10";
+ var task = agvtaskService.Find(x => (x.agv_toaddress.Contains("W") || x.agv_toaddress.Contains("X")) && x.agv_taskstate == "Queue" /*&& x.agv_tasktype == "TaskType_EmptyPallet" */ && x.agv_Traytype == station.tray_type).OrderBy(x => x.agv_createtime).FirstOrDefault();
+ if (task != null)
+ {
+ task.agv_fromaddress = station.stationCode;
+ task.StarQuantity = 0;
+ task.agv_taskstate = "Create";
+ agvtaskService.Update(task, true);
+ station.location_state = LocationStateEnum.Busy.ToString();
+ stationinfoRepository.Update(station, true);
+ continue;
+ }
+ var EmptyStation = stationinfoRepository.Find(x => x.area == area && x.quantity < 5 && x.stationCode.Contains("A") && x.location_state != LocationStateEnum.Busy.ToString() && x.enable)
+ .OrderByDescending(x => x.line).OrderBy(x => x.column).FirstOrDefault();
+ if (EmptyStation == null)
+ {
+ EmptyStation = stationinfoRepository.Find(x => x.area == area && x.quantity < 5 && x.stationCode.Contains(area == "10" ? "D" : "C") && x.location_state == LocationStateEnum.Busy.ToString() && x.enable).OrderByDescending(x => x.column).FirstOrDefault();//鏈�鍚庝竴涓揣浣嶆湁浠诲姟鍒欎笉鑳界敓鎴愬叆搴撲换鍔�
+ if (EmptyStation != null) continue;
+ EmptyStation = stationinfoRepository.Find(x => x.area == area && x.quantity < 5 && x.stationCode.Contains(area == "10" ? "D" : "C") && x.location_state == LocationStateEnum.Stroge.ToString() && x.enable).OrderByDescending(x => x.column).FirstOrDefault();//鎵炬渶澶栭潰娌″爢婊�5涓殑璐т綅
+ if (EmptyStation == null)
+ EmptyStation = stationinfoRepository.Find(x => x.area == area && x.quantity < 5 && x.stationCode.Contains(area == "10" ? "D" : "C") && x.location_state == LocationStateEnum.Empty.ToString() && x.enable).OrderBy(x => x.column).FirstOrDefault();
+ }
+
+ if (EmptyStation != null)
+ {
+ #region 鍚屼竴涓┖鎵樹綅鍙兘鍚屾椂鐢熸垚涓�涓┖鎵樹换鍔�
+ if (agvtaskService.Find(x => x.agv_fromaddress == EmptyStation.stationCode || x.agv_toaddress == EmptyStation.stationCode).Any())
+ return;
+ #endregion
+ dt_agvtask agvtask = new dt_agvtask()
+ {
+ agv_fromaddress = station.stationCode,
+ agv_id = Guid.NewGuid(),
+ agv_tasknum = IdenxManager.GetTaskNo("KH-", "WMS"),
+ agv_grade = 1,
+ agv_createtime = DateTime.Now,
+ agv_taskstate = "Create",
+ //agv_materielid = station.stationType,
+ agv_qty = 1,
+ StarQuantity = 0,
+ EndQuantity = EmptyStation.quantity,
+ agv_tasktype = "TaskType_EmptyPallet",
+ agv_toaddress = EmptyStation.stationCode,
+ agv_userid = "绯荤粺",
+ agv_TrayStatus = "EmptyTray",//station.tray_status,
+ agv_Traytype = station.tray_type,
+ };
+ agvtaskService.Add(agvtask, true);
+ station.location_state = LocationStateEnum.Busy.ToString();
+ stationinfoRepository.Update(station, true);
+ EmptyStation.location_state = LocationStateEnum.Busy.ToString();
+ stationinfoRepository.Update(EmptyStation, true);
+ WriteDBLog.Success("鍒涘缓鑷姩鍙栫┖鎵樹换鍔�", $"浠诲姟缂栧彿锛歿agvtask.agv_tasknum}", "PCS");
+ return;
+ }
}
}
- var finished = (bool)DBExtension.Read(Gantrydetails.Where(x => x.plcdetail_name == "R_Unlod_finished").First(), Gantry_client);//澶瑰彇瀹屾垚
- if (finished)
- {
+ }
+ catch (Exception ex)
+ {
+ WriteDBLog.Error("鍒涘缓鑷姩鍙栫┖鎵樹换鍔�", $"閿欒淇℃伅锛歿ex.Message}", "PCS");
+ }
+ }
- Gantry_client.WriteByOrder("W_Storage_update", true, number);//璐т綅鐘舵�佹洿鏂�
+ /// <summary>
+ /// 妫�娴嬪厜鐢电姸鎬佷笌绯荤粺璐т綅鐘舵�佹槸鍚︿竴鑷�
+ /// </summary>
+ /// <param name="client"></param>
+ private void StationState(PLCClient client)
+ {
+ try
+ {
+ List<string> names = new List<string>() { "1鍗曞厓涓嬫枡鍖�", "2鍗曞厓涓嬫枡鍖�", "3鍗曞厓涓嬫枡鍖�", "涓婃枡鍖�" };
+ foreach (var name in names)
+ {
+ VOLContext Context = new VOLContext();
+ Idt_stationinfoRepository stationinfoRepository = new dt_stationinfoRepository(Context);
+ var Stations = stationinfoRepository.Find(x => x.area == area_code(name) && x.enable && !x.location_state.Contains("Busy") && x.location_state != LocationStateEnum.Abnormal.ToString());
+ foreach (var Station in Stations)
+ {
+ var PalletSignal = client.ReadByOrder<Int16>("R_PalletSignal", Station.stationCode);//璇诲彇鎵樼洏淇″彿:1:鏈�,2鏃�
+ var MaterialSignal = client.ReadByOrder<Int16>("R_MaterialSignal", Station.stationCode);//璇诲彇璐х墿淇″彿:1:鏈�,2鏃�
+ if (Station.quantity > 0 && (PalletSignal != 1 || MaterialSignal != 1))//绯荤粺璐т綅鏈夎溅杞紝鍏夌數妫�娴嬫棤杞﹁疆
+ {
+ Station.location_state = LocationStateEnum.Abnormal.ToString();
+ Station.remark = "杞﹁疆鏁伴噺澶т簬0锛屽厜鐢垫娴嬫棤鎵樼洏鎴栨棤杞﹁疆";
+ stationinfoRepository.Update(Station, true);
+ client.WriteByOrder("W_AlarmSignal", (Int16)2, name);//鎶ヨ
+ continue;
+ }
+ if (Station.location_state == LocationStateEnum.Stroge.ToString() && PalletSignal != 1)
+ {
+ Station.location_state = LocationStateEnum.Abnormal.ToString();
+ Station.remark = "璐т綅鏈夎揣锛屽厜鐢垫娴嬫棤鎵樼洏";
+ stationinfoRepository.Update(Station, true);
+ client.WriteByOrder("W_AlarmSignal", (Int16)2, name);//鎶ヨ
+ continue;
+ }
+ if (Station.location_state == LocationStateEnum.Empty.ToString() && (PalletSignal == 1 || MaterialSignal == 1))//绯荤粺璐т綅涓虹┖锛屽厜鐢垫娴嬫湁鏂�
+ {
+ Station.location_state = LocationStateEnum.Abnormal.ToString();
+ Station.remark = "璐т綅鏃犺揣锛屽厜鐢垫娴嬫湁鏂�";
+ stationinfoRepository.Update(Station, true);
+ client.WriteByOrder("W_AlarmSignal", (Int16)2, name);//鎶ヨ
+ continue;
+ }
+ //if (Station.quantity < 1 && MaterialSignal == 1)//绯荤粺璐т綅鏃犺溅杞紝鍏夌數妫�娴嬫湁杞﹁疆
+ //{
+ // Station.location_state = LocationStateEnum.Abnormal.ToString();
+ // Station.remark = "璐т綅鏃犺溅杞紝鍏夌數妫�娴嬫湁杞﹁疆";
+ // stationinfoRepository.Update(Station, true);
+ // client.WriteByOrder("W_AlarmSignal", (Int16)2, name);//鎶ヨ
+ // continue;
+ //}
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+
+ //throw;
+ }
+ }
+ public static string area_code(string area_name)
+ {
+ VOLContext Context = new VOLContext();
+ Idt_areainfoRepository areainfoRepository = new dt_areainfoRepository(Context);
+ var areainfo = areainfoRepository.Find(x => x.area_name == area_name).FirstOrDefault();
+ return areainfo.area_code.ToString();
+ }
+
+ private string OperStr(string[] strArrty)
+ {
+ string[] newstr = strArrty.RemoveLast(1);
+ string Newsn = string.Join(",", newstr);
+
+ return Newsn;
+ }
+ public static dt_geometry_data QueryMateriel(string type)
+ {
+ VOLContext Context = new VOLContext();
+ Idt_geometry_dataRepository dataRepository = new dt_geometry_dataRepository(Context);
+ var materielinfo = dataRepository.Find(x => x.Description == type).OrderBy(x => x.TypeId).FirstOrDefault();
+ return materielinfo;
+ }
+ public static dt_geometry_data_detectionline QueryMateriel1(string type)
+ {
+ VOLContext Context = new VOLContext();
+ Idt_geometry_data_detectionlineRepository detectionlineRepository = new dt_geometry_data_detectionlineRepository(Context);
+ var materielinfo1 = detectionlineRepository.Find(x => x.Description == type).OrderBy(x => x.TypeId).FirstOrDefault();
+ return materielinfo1;
+ }
+ public static string QueryMateriel(int typeId)
+ {
+ VOLContext Context = new VOLContext();
+ Idt_geometry_dataRepository dataRepository = new dt_geometry_dataRepository(Context);
+ var materielinfo = dataRepository.FindFirst(x => x.TypeId == typeId);
+ return materielinfo.Description;
+ }
+ /// <summary>
+ /// 鏇存敼宸ュ崟鐘舵��
+ /// </summary>
+ /// <param name="SN"></param>
+ public static void Updatemes(string SN)
+ {
+ VOLContext Context = new VOLContext();
+ Idt_mes_detailRepository mes_DetailRepository = new dt_mes_detailRepository(Context);
+ Idt_mes_headRepository mes_HeadRepository = new dt_mes_headRepository(Context);
+ //var mes_Detail = freeDB.Select<dt_mes_detail>().Where(x => x.SN == SN).First();
+ var mes_Detail = mes_DetailRepository.Find(x => x.SN == SN).FirstOrDefault();
+ if (mes_Detail != null)
+ {
+ mes_Detail.Status = "涓婄嚎";
+ mes_Detail.FinishTime = DateTime.Now;
+ //freeDB.DataBase.Update<dt_mes_detail>().SetSource(mes_Detail).UpdateColumns(x => new { x.Status, x.FinishTime }).ExecuteAffrows();
+ mes_DetailRepository.Update(mes_Detail, true);
+ //var mes_Head = freeDB.Select<dt_mes_head>().Where(x => x.jobID == mes_Detail.jobID).First();
+ var mes_Head = mes_HeadRepository.Find(x => x.jobID == mes_Detail.jobID).FirstOrDefault();
+ if (mes_Head != null)
+ {
+ mes_Head.finishNum = mes_Head.finishNum + 1;
+ //freeDB.DataBase.Update<dt_mes_head>().SetSource(mes_Head).UpdateColumns(x => new { x.finishNum }).ExecuteAffrows();
+ mes_HeadRepository.Update(mes_Head, true);
}
}
}
--
Gitblit v1.9.3