From 6be6a1e453861fa0beb818236fdd8183024074c4 Mon Sep 17 00:00:00 2001
From: wxw <Administrator@DESKTOP-5BIMHQ3>
Date: 星期二, 04 十一月 2025 08:21:40 +0800
Subject: [PATCH] 增加和MES对接接口
---
Wms/WMS.BLL/BllTransServer/RcsServer.cs | 218 ++++++++++++++++++++++++++++++++++++-----------------
1 files changed, 147 insertions(+), 71 deletions(-)
diff --git a/Wms/WMS.BLL/BllTransServer/RcsServer.cs b/Wms/WMS.BLL/BllTransServer/RcsServer.cs
index bb768fa..a00753c 100644
--- a/Wms/WMS.BLL/BllTransServer/RcsServer.cs
+++ b/Wms/WMS.BLL/BllTransServer/RcsServer.cs
@@ -27,7 +27,8 @@
{
public class RcsServer:IRcsServer
{
- private readonly object RcsLock = new object();
+ private static readonly object GetPalleLock = new object();
+ private static readonly object ApplyLocatLock = new object();
private static readonly SqlSugarScope Db = DataContext.Db;
/// <summary>
@@ -37,9 +38,9 @@
/// <param name="url"></param>
/// <param name="taskNo"></param>
/// <exception cref="Exception"></exception>
- public void GetPalletNo(Pallnetmsg model, string url, out string taskNo)
+ public void GetPalletNo(Pallnetmsg model, string url,string urlMes, out string taskNo)
{
- lock (RcsLock)
+ lock (GetPalleLock)
{
try
{
@@ -59,7 +60,6 @@
//鍙《璁惧鎵�鍦ㄥ偍浣嶄俊鎭紙鐩爣鍌ㄤ綅锛�
var endLoction = new SysStorageLocat();
- var urlMes = "";//鍥炰紶MES鐨勬帴鍙e湴鍧�
var noticeNo = "0";//鍑哄叆搴撳崟鎹槑缁咺D
//鎵�鏈夊緟鍒嗛厤鐨勬《
@@ -251,36 +251,28 @@
foreach (var item in palletList)
{
#region 鍘绘帀MES
- //string jsonReq = JsonConvert.SerializeObject(item.PalletNo);
- //var response = HttpHelper.DoPost(urlMes, jsonReq, "鍥炰紶MES鑴忔《缂栧彿", "RCS").ToString();
- //var obj = JsonConvert.DeserializeObject<ReMes>(response);//瑙f瀽杩斿洖鏁版嵁
- //if (obj.Success == "0")
- //{
- // if (obj.Result != "1")//涓嶅彲娓呮礂锛屽皢鑴忔《鍐荤粨
- // {
- // item.Status = "5";//寮傚父鍐荤粨
- // //淇敼璇ユ《搴撳瓨鐘舵��
- // Db.Updateable(item).ExecuteCommand();
+ var reObj = new
+ {
+ devive = item.PackagNo
+ };
+ string jsonReq = JsonConvert.SerializeObject(reObj);
+ var response = HttpHelper.DoPost(urlMes, jsonReq, "鍥炰紶MES鑴忔《缂栧彿鍒ゆ柇鏄惁鍙竻娲�", "MES").ToString();
+ var obj = JsonConvert.DeserializeObject<ReMes>(response);//瑙f瀽杩斿洖鏁版嵁
+ if (obj.state == "200")
+ {
+ if (obj.data != "1")//涓嶅彲娓呮礂锛屽皢鑴忔《鍐荤粨
+ {
+ item.Status = "5";//寮傚父鍐荤粨
+ //淇敼璇ユ《搴撳瓨鐘舵��
+ Db.Updateable(item).ExecuteCommand();
- // continue;
- // }
- // //涓嬪彂灏忚溅浠诲姟
- // var task2 = new TaskDetial
- // {
- // Startport = item.LocatNo,
- // Endport = model.Location,
- // Pallno = item.PalletNo,
- // Type = model.Type,
- // Crtype = "1",
- // Noticedetailno = int.Parse(noticeno),
- // };
- // CreateLotTask(task2);
- // return;
- //}
- //else
- //{
- // throw new Exception("鍥炰紶MES鍑�妗剁紪鍙峰け璐ワ紒");
- //}
+ continue;
+ }
+ }
+ else
+ {
+ throw new Exception("鍙剰妗跺洖浼燤ES鍒ゆ柇澶辫触锛�");
+ }
#endregion
item.Status = "2";//鍒嗛厤鐘舵�� 0:寰呭垎閰嶏紝1锛氶儴鍒嗗垎閰� 锛� 2:宸插垎閰�
@@ -448,7 +440,7 @@
/// <exception cref="Exception"></exception>
public void ApplyLocatNo(Pallnetmsg model, string url, out string taskNo)
{
- lock (RcsLock)
+ lock (ApplyLocatLock)
{
try
{
@@ -520,6 +512,11 @@
{
throw new Exception($"鏈煡璇㈠埌璇ヨ澶囨墍鍦ㄥ偍浣嶄俊鎭紝Location:{model.Location}");
}
+ //鍒ゆ柇鏄惁鏈夋壒娆″彿
+ if (string.IsNullOrWhiteSpace(model.LotNo))
+ {
+ throw new Exception("鎵规鍙蜂负绌猴紒");
+ }
//鏌ユ壘妗跺簱瀛樹俊鎭�
palletInfo = Db.Queryable<DataStockDetail>().Where(w => w.IsDel == "0" && w.WareHouseNo == deviceLocatInfo.WareHouseNo && w.AreaNo == deviceLocatInfo.AreaNo && w.LocatNo == deviceLocatInfo.LocatNo).OrderBy(o => o.UpdateTime).First();
if (palletInfo == null)
@@ -527,7 +524,7 @@
throw new Exception($"鏈煡璇㈠埌璇ヨ澶囦笂妗剁殑搴撳瓨淇℃伅");
}
palletInfo.LotNo = model.LotNo;//鎵规鍙�
- //鏇存柊妗跺簱瀛樹俊鎭�
+ //鏇存柊妗跺簱瀛樹俊鎭�
Db.Updateable(palletInfo).ExecuteCommand();
//鏌ユ壘璇ユ《鏈夋病鏈夋鍦ㄦ墽琛岀殑浠诲姟
@@ -536,12 +533,7 @@
{
throw new Exception($"璇ユ《鏈夋鍦ㄦ墽琛岀殑浠诲姟锛孭alletNo:{palletInfo.PalletNo}");
}
-
- //鍒ゆ柇鏄惁鏈夋壒娆″彿
- if (string.IsNullOrWhiteSpace(model.LotNo))
- {
- throw new Exception("鎵规鍙蜂负绌猴紒");
- }
+
//鏌ユ壘鍒拌杞﹂棿棰勬贩鍖�
loction = GetLocatModel(houseNo, "1");
if (loction == null)
@@ -782,7 +774,7 @@
Db.BeginTran();
//鏌ユ壘鏄惁鏈夌┖浣欒剰妗朵綅
- var endLocat = Db.Queryable<SysStorageLocat>().First(w => w.WareHouseNo == detail.WareHouseNo && w.AreaNo.Contains("04") && w.Status == "0" && w.Flag=="0");
+ var endLocat = Db.Queryable<SysStorageLocat>().First(w => w.WareHouseNo == detail.WareHouseNo && w.AreaNo.Contains("04") && w.Status == "0" && w.Flag == "0");
if (endLocat == null)
{
detail.Status = "5";//寮傚父閿佸畾
@@ -830,22 +822,97 @@
{
try
{
+ //妗朵俊鎭�
var detail = Db.Queryable<DataStockDetail>().First(w => w.PalletNo == pallnetmsg.PalletNo && w.PalletStatus == "3");
if (detail == null)
{
throw new Exception($"搴撳瓨涓笉瀛樺湪妗跺彿涓猴細{pallnetmsg.PalletNo}鐨勫簱瀛�!");
}
- //涓嬪彂灏忚溅浠诲姟
+ //璁惧淇℃伅
+ var deviceInfo = Db.Queryable<SysStorageArea>().First(w => w.IsDel == "0" && w.DeviceCode.Contains(pallnetmsg.Location));
+ if (deviceInfo == null)
+ {
+ throw new Exception($"涓嶅瓨鍦ㄨ澶囧彿涓猴細{pallnetmsg.Location}鐨勮澶�!");
+ }
+ //鐩爣鍌ㄤ綅淇℃伅
+ var endLoction = Db.Queryable<SysStorageLocat>().First(w => w.IsDel == "0" && w.WareHouseNo == deviceInfo.WareHouseNo && w.AreaNo == deviceInfo.AreaNo && w.Column == 1);// Column=1 娓呮礂鍌ㄤ綅锛孋olumn=2 娓呮礂瀹屾枡鍌ㄤ綅
+ if (endLoction == null)
+ {
+ throw new Exception("鍙《璁惧鐩爣鍌ㄤ綅淇℃伅涓嶅瓨鍦�");
+ }
+
+ detail.Status = "2";//鍒嗛厤鐘舵�� 0:寰呭垎閰嶏紝1锛氶儴鍒嗗垎閰� 锛� 2:宸插垎閰�
+ //鏇存柊妗跺簱瀛樻槑缁�
+ Db.Updateable(detail).ExecuteCommand();
+
+ //璧峰鍌ㄤ綅鍦板潃淇℃伅
+ var startLoction = Db.Queryable<SysStorageLocat>().First(w => w.IsDel == "0" && w.LocatNo == detail.LocatNo);
+ if (startLoction == null)
+ {
+ throw new Exception($"妗跺彿锛歿detail.PalletNo}鍌ㄤ綅淇℃伅{detail.LocatNo}涓嶅瓨鍦�");
+ }
+
+ var taskNo = new Common().GetMaxNo("TN");//浠诲姟鍙�
+ var logTaskEntry = new LogTask
+ {
+ TaskNo = taskNo,
+ Sender = "WMS",
+ Receiver = "RCS",
+ //IsSuccess = 1, //鏄惁涓嬪彂鎴愬姛 0澶辫触 1鎴愬姛
+ SendDate = DateTime.Now, //鍙戦�佹椂闂�
+ //BackDate = DateTime.Now, //杩斿洖鏃堕棿
+ StartLocat = startLoction.LocatNo,//璧峰浣嶇疆
+ EndLocat = endLoction.LocatNo,//鐩爣浣嶇疆
+ PalletNo = detail.PalletNo,//鎵樼洏鐮�
+ IsSend = 1,//鏄惁鍙啀娆′笅鍙�
+ IsCancel = 1,//鏄惁鍙彇娑�
+ IsFinish = 1,//鏄惁鍙畬鎴�
+ Type = "1",//浠诲姟绫诲瀷 0 鍏ュ簱浠诲姟 1 鍑哄簱浠诲姟 2 绉诲簱浠诲姟
+ OrderType = "3",//鍗曟嵁绫诲瀷 0 鍏ュ簱 1 鍑哄簱 3 绉诲簱
+ Status = "0",//浠诲姟鐘舵��0锛氱瓑寰呮墽琛�1姝e湪鎵ц2鎵ц瀹屾垚
+ NoticeDetailNo = 0,
+ Msg = $"MES涓嬪彂娓呮礂鎸囧畾鑴忔《锛屾《鍙�:{pallnetmsg.PalletNo},璁惧鍙凤細{pallnetmsg.Location}", //鍏抽敭淇℃伅
+ LotNo = ""//鎵规鍙�
+ };
+ //缁勭粐涓嬪彂灏忚溅浠诲姟淇℃伅
var task = new TaskDetial
{
- Startport = detail.LocatNo,
- Endport = pallnetmsg.Location,
- Pallno = detail.PalletNo,
- Crtype = "1",
+ Taskno = taskNo,//浠诲姟鍙�
+ Startport = startLoction.LocatNo,//璧峰浣嶇疆
+ Endport = endLoction.LocatNo,//鐩爣浣嶇疆
+ Pallno = detail.PalletNo,//妗跺彿
+ Crtype = "1",//鍙《
+ WareHouseNo = detail.WareHouseNo//杞﹂棿缂栫爜
};
- string taskNo = "";
- string agvMsg = string.Empty;
- CreateTaskForAgv(task, url, out agvMsg);
+ //缁欎笅杞︿笅鍙戜换鍔�
+ logTaskEntry.SendDate = DateTime.Now;//鍙戦�佹椂闂�
+ string agvMsg=string.Empty;
+ var agvResult = CreateTaskForAgv(task, url, out agvMsg);
+ if (agvResult)//鎴愬姛
+ {
+ //璇锋眰鎴愬姛淇敼浠诲姟琛ㄧ浉搴斿瓧娈电姸鎬�
+ logTaskEntry.IsSuccess = 1;
+ logTaskEntry.IsSend = 0;
+ //logTaskEntry.IsCancel = 0;
+ logTaskEntry.BackDate = DateTime.Now;
+ logTaskEntry.Status = "1";//姝e湪鎵ц
+ Db.Insertable(logTaskEntry).ExecuteCommand();
+
+ startLoction.Status = "3";//鍑哄簱涓�
+ Db.Updateable(startLoction).ExecuteCommand();
+
+ endLoction.Status = "2";//鍏ュ簱涓�
+ Db.Updateable(endLoction).ExecuteCommand();
+ }
+ else//澶辫触
+ {
+ logTaskEntry.IsSuccess = 0;
+ logTaskEntry.Information = agvMsg;
+ Db.Insertable(logTaskEntry).ExecuteCommand();
+
+ }
+ //鎻愪氦浜嬪姟
+ Db.CommitTran();
}
catch (Exception ex)
{
@@ -1293,33 +1360,42 @@
agvTask.taskTyp = "Z5";
}
- // 姝e紡杩愯绋嬪簭鏀惧紑
- var jsonData = JsonConvert.SerializeObject(agvTask);
- string response = HttpHelper.DoPost(url, jsonData, "涓嬪彂缁橝GV杞繍鍛戒护", "AGV");
- //瑙f瀽杩斿洖鏁版嵁
- var agvModel = JsonConvert.DeserializeObject<OutCommanAgvDto>(response);
- if (agvModel.Code == "0")
+
+ if (string.IsNullOrEmpty(url))//娴嬭瘯绯荤粺
{
- result = true;//缁欎笅杞︿笅鍙戜换鍔℃垚鍔�
-
+ result = true;
agvMsg = "";
}
- else
+ else//姝e紡绯荤粺
{
- string logMsg = "";
- if (taskDetial.Crtype == "1")//鍙《锛堟《鍑哄簱锛�
+ var jsonData = JsonConvert.SerializeObject(agvTask);
+ string response = HttpHelper.DoPost(url, jsonData, "涓嬪彂缁橝GV杞繍鍛戒护", "AGV");
+ //瑙f瀽杩斿洖鏁版嵁
+ var agvModel = JsonConvert.DeserializeObject<OutCommanAgvDto>(response);
+ if (agvModel.Code == "0")
{
- logMsg = "鐢宠鍙《";
- }
- else if (taskDetial.Crtype == "0")//鐢宠鍌ㄤ綅锛堟《鍏ュ簱锛�
- {
- logMsg = "鐢宠鍌ㄤ綅";
- }
- var logStr = $@".\log\AGV\AGV{logMsg}" + DateTime.Now.ToString("yyyyMMdd") + ".txt";
- LogFile.SaveLogToFile($"AGV{logMsg}寮傚父锛�( {agvModel.Message} ),", logStr);
+ result = true;//缁欎笅杞︿笅鍙戜换鍔℃垚鍔�
- agvMsg = agvModel.Message;
+ agvMsg = "";
+ }
+ else
+ {
+ string logMsg = "";
+ if (taskDetial.Crtype == "1")//鍙《锛堟《鍑哄簱锛�
+ {
+ logMsg = "鐢宠鍙《";
+ }
+ else if (taskDetial.Crtype == "0")//鐢宠鍌ㄤ綅锛堟《鍏ュ簱锛�
+ {
+ logMsg = "鐢宠鍌ㄤ綅";
+ }
+ var logStr = $@".\log\AGV\AGV{logMsg}" + DateTime.Now.ToString("yyyyMMdd") + ".txt";
+ LogFile.SaveLogToFile($"AGV{logMsg}寮傚父锛�( {agvModel.Message} ),", logStr);
+
+ agvMsg = agvModel.Message;
+ }
}
+
return result;
#endregion
}
@@ -1345,7 +1421,7 @@
var taskIng= Db.Queryable<LogTask>().First(w => w.IsDel == "0" && (w.Status == "0" || w.Status == "1") && w.PalletNo == palletNo);
if (taskIng != null)
{
- throw new Exception("鍒嗛厤鐨勬《鏈夋鍦ㄦ墽琛岀殑浠诲姟锛岃绋嶅悗鍐嶈瘯");
+ throw new Exception($"鍒嗛厤鐨勬《{palletNo}鏈夋鍦ㄦ墽琛岀殑浠诲姟锛岃绋嶅悗鍐嶈瘯");
}
//鍒嗛厤妗剁殑鍌ㄤ綅淇℃伅
var locatInfo = Db.Queryable<SysStorageLocat>().First(w => w.IsDel == "0" && w.LocatNo == palletInfo.LocatNo);
--
Gitblit v1.8.0