|
@@ -1,5 +1,7 @@
|
|
|
using centralController.model;
|
|
|
+using db;
|
|
|
using nettyCommunication;
|
|
|
+using parkMonitor.LOG;
|
|
|
using PLCS7;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
@@ -81,28 +83,19 @@ namespace centralController.WebServer
|
|
|
List<string> vehicleInsertList = new List<string>();
|
|
|
vehicleUpdateList.Add(vehicleUpdateSql);
|
|
|
vehicleInsertList.Add(vehicleInsertSql);
|
|
|
+ DBOperation dbHandle = null;
|
|
|
if (localDB)
|
|
|
- {
|
|
|
- if (!Monitor.Monitor.localDBOper.Insert(vehicleInsertList))
|
|
|
- {
|
|
|
- if (!Monitor.Monitor.localDBOper.UpdateTransaction(vehicleUpdateList))
|
|
|
- return false;
|
|
|
- else
|
|
|
- return true;
|
|
|
- }
|
|
|
- else return true;
|
|
|
- }
|
|
|
+ dbHandle = Monitor.Monitor.localDBOper;
|
|
|
else
|
|
|
+ dbHandle = Monitor.Monitor.remoteDBOper;
|
|
|
+ if (!dbHandle.UpdateTransaction(vehicleUpdateList))
|
|
|
{
|
|
|
- if (!Monitor.Monitor.remoteDBOper.Insert(vehicleInsertList))
|
|
|
- {
|
|
|
- if (!Monitor.Monitor.remoteDBOper.UpdateTransaction(vehicleUpdateList))
|
|
|
- return false;
|
|
|
- else
|
|
|
- return true;
|
|
|
- }
|
|
|
- else return true;
|
|
|
+ if (!dbHandle.Insert(vehicleInsertList, out int id))
|
|
|
+ return false;
|
|
|
+ else
|
|
|
+ return true;
|
|
|
}
|
|
|
+ else return true;
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 插入预约记录
|
|
@@ -114,7 +107,7 @@ namespace centralController.WebServer
|
|
|
/// <param name="orderTime"></param>
|
|
|
/// <param name="orderLength"></param>
|
|
|
/// <returns></returns>
|
|
|
- private bool InsertOrderRecord(bool localDB, string userID, bool parking, string license, string orderTime, int orderLength)
|
|
|
+ private bool InsertOrderRecord(bool localDB, string userID, bool parking, string license, string orderTime, int orderLength, out int id)
|
|
|
{
|
|
|
bool result = false;
|
|
|
string orderRecordInsertSql;
|
|
@@ -131,13 +124,13 @@ namespace centralController.WebServer
|
|
|
List<string> orderList = new List<string>();
|
|
|
orderList.Add(orderRecordInsertSql);
|
|
|
if (localDB)
|
|
|
- result = Monitor.Monitor.localDBOper.Insert(orderList);
|
|
|
+ result = Monitor.Monitor.localDBOper.Insert(orderList, out id);
|
|
|
else
|
|
|
- result = Monitor.Monitor.remoteDBOper.Insert(orderList);
|
|
|
+ result = Monitor.Monitor.remoteDBOper.Insert(orderList, out id);
|
|
|
return result;
|
|
|
}
|
|
|
/// <summary>
|
|
|
- /// 找到当前预约记录ID
|
|
|
+ /// 找到当前预约记录ID,暂未使用
|
|
|
/// </summary>
|
|
|
/// <param name="localDB"></param>
|
|
|
/// <param name="license"></param>
|
|
@@ -146,14 +139,18 @@ namespace centralController.WebServer
|
|
|
private int FindCurrentOrderRecordID(bool localDB, string license, int latestIndex = 1)
|
|
|
{
|
|
|
int currentID = 0;
|
|
|
- List<object[]> orderRecords = Monitor.Monitor.GetOrderRecords(localDB, license, DateTime.Now.ToString("yyyy-MM-dd"), DateTime.Now.AddDays(1).ToString("yyyy-MM-dd"));
|
|
|
- if (orderRecords.Count != 0)
|
|
|
+ int count = 10;
|
|
|
+ while (count-- > 0 && currentID == 0)
|
|
|
{
|
|
|
- try
|
|
|
+ List<object[]> orderRecords = Monitor.Monitor.GetOrderRecords(localDB, license, DateTime.Now.ToString("yyyy-MM-dd"), DateTime.Now.AddDays(1).ToString("yyyy-MM-dd"));
|
|
|
+ if (orderRecords.Count != 0)
|
|
|
{
|
|
|
- currentID = (int)(UInt32)orderRecords[latestIndex - 1][0];
|
|
|
+ try
|
|
|
+ {
|
|
|
+ currentID = (int)(UInt32)orderRecords[latestIndex - 1][0];
|
|
|
+ }
|
|
|
+ catch { }
|
|
|
}
|
|
|
- catch { }
|
|
|
}
|
|
|
return currentID;
|
|
|
}
|
|
@@ -171,9 +168,9 @@ namespace centralController.WebServer
|
|
|
{
|
|
|
UpdateVehicleState(localDB, parking ? 4 : 5, 0, license);
|
|
|
//预约记录插入db
|
|
|
- InsertOrderRecord(localDB, userID, parking, license, orderTime, orderLength);
|
|
|
- //查询预约记录id号
|
|
|
- int currentID = FindCurrentOrderRecordID(localDB, license);
|
|
|
+ InsertOrderRecord(localDB, userID, parking, license, orderTime, orderLength, out int currentID);
|
|
|
+ ////查询预约记录id号
|
|
|
+ //int currentID = FindCurrentOrderRecordID(localDB, license);
|
|
|
if (currentID == 0) { /*反馈web,预约失败*/ return false; }
|
|
|
//更新车辆状态
|
|
|
UpdateVehicleState(localDB, parking ? 4 : 5, currentID, license);
|
|
@@ -190,15 +187,16 @@ namespace centralController.WebServer
|
|
|
lock (waitToReserveLock)
|
|
|
{
|
|
|
//可预约车位总数
|
|
|
- allBookableSpace = Monitor.Monitor.ins.GetFreeSpaceCount(3);
|
|
|
+ allBookableSpace = Monitor.Monitor.ins.GetFreeSpaceCount(4);
|
|
|
count = 0;
|
|
|
DateTime start, end;
|
|
|
try
|
|
|
{
|
|
|
start = DateTime.Parse(msg.bookTime);
|
|
|
end = start.AddHours(msg.bookLength);
|
|
|
+ //Console.WriteLine("--------"+msg.bookTime+","+msg.bookLength);
|
|
|
}
|
|
|
- catch { return false; }
|
|
|
+ catch { Console.WriteLine("时间解析异常1"); return false; }
|
|
|
|
|
|
Queue<MessageUTF8>.Enumerator enumer = waitToReserveQueue.GetEnumerator();
|
|
|
while (enumer.MoveNext())
|
|
@@ -207,13 +205,31 @@ namespace centralController.WebServer
|
|
|
try
|
|
|
{
|
|
|
tempStart = DateTime.Parse(enumer.Current.bookTime);
|
|
|
- tempEnd = start.AddHours(enumer.Current.bookLength);
|
|
|
+ tempEnd = tempStart.AddHours(enumer.Current.bookLength);
|
|
|
+ //Console.WriteLine("#########" + enumer.Current.bookTime + "," + enumer.Current.bookLength);
|
|
|
}
|
|
|
- catch { return false; }
|
|
|
+ catch { Console.WriteLine("时间解析异常2"); return false; }
|
|
|
+ //Console.WriteLine("**********" + start.ToString() + "," + end.ToString() + "," + tempStart.ToString() + "," + tempEnd.ToString());
|
|
|
+ //Console.WriteLine("**********" + ((tempStart - end).TotalMinutes > 0)+","+ ((start - tempEnd).TotalMinutes > 0));
|
|
|
+ if (!((tempStart - end).TotalMinutes > 0 || (start - tempEnd).TotalMinutes > 0)) { count += 1; }
|
|
|
+ }
|
|
|
+ Queue<MessageUTF8>.Enumerator enumer2 = reservedQueue.GetEnumerator();
|
|
|
+ while (enumer2.MoveNext())
|
|
|
+ {
|
|
|
+ DateTime tempStart, tempEnd;
|
|
|
+ try
|
|
|
+ {
|
|
|
+ tempStart = DateTime.Parse(enumer2.Current.bookTime);
|
|
|
+ tempEnd = tempStart.AddHours(enumer2.Current.bookLength);
|
|
|
+ //Console.WriteLine("#########" + enumer.Current.bookTime + "," + enumer.Current.bookLength);
|
|
|
+ }
|
|
|
+ catch { Console.WriteLine("时间解析异常2"); return false; }
|
|
|
+ //Console.WriteLine("**********" + start.ToString() + "," + end.ToString() + "," + tempStart.ToString() + "," + tempEnd.ToString());
|
|
|
+ //Console.WriteLine("**********" + ((tempStart - end).TotalMinutes > 0)+","+ ((start - tempEnd).TotalMinutes > 0));
|
|
|
if (!((tempStart - end).TotalMinutes > 0 || (start - tempEnd).TotalMinutes > 0)) { count += 1; }
|
|
|
}
|
|
|
}
|
|
|
- Console.WriteLine(msg.context+":"+allBookableSpace+","+count);
|
|
|
+ Console.WriteLine("----------" + msg.context + ":" + allBookableSpace + "," + count);
|
|
|
if (allBookableSpace > count)
|
|
|
return true;
|
|
|
else
|
|
@@ -245,14 +261,17 @@ namespace centralController.WebServer
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
+ bool DBOperResult = true;
|
|
|
lock (waitToReserveLock)
|
|
|
{
|
|
|
waitToReserveQueue.Enqueue(msg);
|
|
|
}
|
|
|
//预约记录与车辆状态写入数据库
|
|
|
- ReserveDBOperation(true, msg.sender, true, msg.context, msg.bookTime, msg.bookLength);
|
|
|
- ReserveDBOperation(false, msg.sender, true, msg.context, msg.bookTime, msg.bookLength);
|
|
|
+ DBOperResult = DBOperResult && ReserveDBOperation(true, msg.sender, true, msg.context, msg.bookTime, msg.bookLength);
|
|
|
+ DBOperResult = DBOperResult && ReserveDBOperation(false, msg.sender, true, msg.context, msg.bookTime, msg.bookLength);
|
|
|
//回复成功给web
|
|
|
+ if (!DBOperResult)
|
|
|
+ Log.WriteLog(LogType.process, LogFile.WARNING, "预约数据库操作未获得记录ID");
|
|
|
returnMsg.cmd = "OK";
|
|
|
returnMsg.garageID = Monitor.Monitor.garageID;
|
|
|
returnMsg.context = msg.context;
|
|
@@ -261,6 +280,12 @@ namespace centralController.WebServer
|
|
|
}
|
|
|
}
|
|
|
break;
|
|
|
+
|
|
|
+ case "CANCELRESERVE":
|
|
|
+ //IEqualityComparer<MessageUTF8> comparer ;
|
|
|
+ //if(waitToReserveQueue.Contains(msg, )
|
|
|
+
|
|
|
+ break;
|
|
|
//预约取
|
|
|
case "PREFETCH":
|
|
|
break;
|
|
@@ -313,34 +338,35 @@ namespace centralController.WebServer
|
|
|
int countdown = 5;
|
|
|
while (countdown-- > 0)
|
|
|
{
|
|
|
- if (Monitor.Monitor.mainBlockInfo.bookParkCmd != 0)
|
|
|
- Thread.Sleep(300);
|
|
|
- else
|
|
|
+ if (Monitor.Monitor.mainBlockInfo.bookParkCmd != 0 && countdown>1)
|
|
|
{
|
|
|
- MainBlockStru mb = new MainBlockStru
|
|
|
+ Thread.Sleep(300);
|
|
|
+ if (countdown == 2)
|
|
|
{
|
|
|
- centralHearbeat = -1,
|
|
|
- bookParkCmd = parking ? (short)state : (short)-1,
|
|
|
- bookFetchCmd = !parking ? (short)state : (short)-1,
|
|
|
- licenseReceived = -1
|
|
|
- };
|
|
|
- Monitor.Monitor.PLC.WriteToPLC(mb, PLCDataType.central);
|
|
|
- Monitor.Monitor.SetNotification(mb.bookParkCmd + "," + mb.bookFetchCmd + "预约停车指令写入PLC", parkMonitor.model.TextColor.Log);
|
|
|
- break;
|
|
|
+ Monitor.Monitor.SetNotification("未能获取预约指令位0状态,尝试手动清除", parkMonitor.model.TextColor.Warning);
|
|
|
+ MainBlockStru mbs = new MainBlockStru
|
|
|
+ {
|
|
|
+ centralHearbeat = -1,
|
|
|
+ bookParkCmd = parking ? (short)0 : (short)-1,
|
|
|
+ bookFetchCmd = !parking ? (short)0 : (short)-1,
|
|
|
+ licenseReceived = -1
|
|
|
+ };
|
|
|
+ Monitor.Monitor.PLC.WriteToPLC(mbs, PLCDataType.central);
|
|
|
+ Thread.Sleep(500);
|
|
|
+ }
|
|
|
+ continue;
|
|
|
}
|
|
|
- if (countdown == 2)
|
|
|
+ MainBlockStru mb = new MainBlockStru
|
|
|
{
|
|
|
- Monitor.Monitor.SetNotification("未能获取预约指令位0状态,尝试手动清除", parkMonitor.model.TextColor.Warning);
|
|
|
- MainBlockStru mb = new MainBlockStru
|
|
|
- {
|
|
|
- centralHearbeat = -1,
|
|
|
- bookParkCmd = parking ? (short)0 : (short)-1,
|
|
|
- bookFetchCmd = !parking ? (short)0 : (short)-1,
|
|
|
- licenseReceived = -1
|
|
|
- };
|
|
|
- Monitor.Monitor.PLC.WriteToPLC(mb, PLCDataType.central);
|
|
|
- Thread.Sleep(500);
|
|
|
- }
|
|
|
+ centralHearbeat = -1,
|
|
|
+ bookParkCmd = parking ? (short)state : (short)-1,
|
|
|
+ bookFetchCmd = !parking ? (short)state : (short)-1,
|
|
|
+ licenseReceived = -1
|
|
|
+ };
|
|
|
+ Monitor.Monitor.PLC.WriteToPLC(mb, PLCDataType.central);
|
|
|
+ Monitor.Monitor.SetNotification(mb.bookParkCmd + "," + mb.bookFetchCmd + "; 预约停车指令写入PLC", parkMonitor.model.TextColor.Log);
|
|
|
+ Log.WriteLog(LogType.process, LogFile.INFO, mb.bookParkCmd + "," + mb.bookFetchCmd + "预约停车指令写入PLC");
|
|
|
+ break;
|
|
|
}
|
|
|
}
|
|
|
/// <summary>
|
|
@@ -364,7 +390,6 @@ namespace centralController.WebServer
|
|
|
Console.WriteLine("当前时间差:" + ts.TotalMinutes + ",指令类型:" + msg.cmd);
|
|
|
if (ts.TotalMinutes >= 0)
|
|
|
{
|
|
|
- Console.WriteLine();
|
|
|
//如果是预约停车,通知PLC减少一个可预约车位数
|
|
|
if (msg.cmd == "RESERVE")
|
|
|
{
|
|
@@ -395,6 +420,7 @@ namespace centralController.WebServer
|
|
|
if (ts.TotalMinutes > msg.bookLength * 60)
|
|
|
{
|
|
|
Monitor.Monitor.SetNotification(msg.context + " 预约已超时", parkMonitor.model.TextColor.Warning);
|
|
|
+ Log.WriteLog(LogType.process, LogFile.INFO, msg.context + " 预约已超时");
|
|
|
//通知PLC将可预约车位数恢复一个
|
|
|
SendBookCmd(true, 2);
|
|
|
//恢复车辆状态
|
|
@@ -461,13 +487,9 @@ namespace centralController.WebServer
|
|
|
{
|
|
|
byte[] bytes = new byte[256];
|
|
|
MessageUTF8 msg = ((MessageUTF8)comm.ReceiveMessage(out bytes));
|
|
|
- string str = "";
|
|
|
- //for (int i = 0; i < bytes.Length &&bytes[i]!=0x00; i++)
|
|
|
- //{
|
|
|
- // str += bytes[i] + " ";
|
|
|
- //}
|
|
|
- str = Encoding.Default.GetString(bytes);
|
|
|
- Console.WriteLine(str);
|
|
|
+ //string str = "";
|
|
|
+ //str = Encoding.Default.GetString(bytes);
|
|
|
+ //Console.WriteLine(str);
|
|
|
if (msg != null)
|
|
|
{
|
|
|
MsgHandling(msg);
|
|
@@ -544,8 +566,8 @@ namespace centralController.WebServer
|
|
|
int count = 12;
|
|
|
while (!isClosing)
|
|
|
{
|
|
|
- if (receiveMsg != null)
|
|
|
- Console.WriteLine(Connections.isAlive() + ", " + receiveMsg.ThreadState.ToString());
|
|
|
+ //if (receiveMsg != null)
|
|
|
+ // Console.WriteLine(Connections.isAlive() + ", " + receiveMsg.ThreadState.ToString());
|
|
|
if (Connections.isAlive())
|
|
|
{
|
|
|
if (!connected)
|