|
@@ -0,0 +1,157 @@
|
|
|
+using parkMonitor.DBLocation;
|
|
|
+using parkMonitor.entity;
|
|
|
+using parkMonitor.model;
|
|
|
+using parkMonitor.server.uiLogServer;
|
|
|
+using System;
|
|
|
+using System.Collections.Generic;
|
|
|
+using System.Linq;
|
|
|
+using System.Text;
|
|
|
+using System.Threading;
|
|
|
+using System.Threading.Tasks;
|
|
|
+
|
|
|
+namespace parkMonitor
|
|
|
+{
|
|
|
+ public class ManualParkingSimul
|
|
|
+ {
|
|
|
+ public static ManualParkingSimul ins;
|
|
|
+ private const string userId = "18202736439";
|
|
|
+ private const string garageId = "1";
|
|
|
+ private const string header = "鄂A";
|
|
|
+ private const int licInterval = 90000;//90秒
|
|
|
+ private Random rnd;
|
|
|
+ private Dictionary<int, CarStatusStru> numStatusMap = new Dictionary<int, CarStatusStru>();
|
|
|
+ Command storeCmd = new Command();
|
|
|
+ IEquipments queue;
|
|
|
+ DBLocationOperator locationOper = new DBLocationOperator();
|
|
|
+
|
|
|
+ public ManualParkingSimul()
|
|
|
+ {
|
|
|
+ Task.Factory.StartNew(() =>
|
|
|
+ {
|
|
|
+ for (int i = 0; i < 10; i++)
|
|
|
+ {
|
|
|
+ numStatusMap.Add(i, new CarStatusStru(header + (i * 11111).ToString("D5"), 0));
|
|
|
+ }
|
|
|
+ while (queue == null)
|
|
|
+ {
|
|
|
+ queue = EquipmentSimpleFactory.ins.FindEquipment(EquipmentName.Queue);
|
|
|
+ }
|
|
|
+ }).Wait();
|
|
|
+ Task.Factory.StartNew(() =>
|
|
|
+ {
|
|
|
+ Run();
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ public void Store(string lic)
|
|
|
+ {
|
|
|
+ storeCmd.manual = true;
|
|
|
+ storeCmd.commandType = 's';
|
|
|
+ storeCmd.userID = locationOper.GetUserID(userId).ToString();
|
|
|
+ storeCmd.LicenseNum = lic;
|
|
|
+ try
|
|
|
+ {
|
|
|
+ storeCmd.garageID = Convert.ToInt32(garageId);
|
|
|
+ }
|
|
|
+ catch { UILogServer.ins.error("非法车库号,请重新输入"); return; }
|
|
|
+ int garageFreeSpace = 0;
|
|
|
+ bool isTelRegister = locationOper.IsTelRegister(userId);
|
|
|
+ if (isTelRegister == false)
|
|
|
+ {
|
|
|
+ UILogServer.ins.error("该号码未被注册,请先注册");
|
|
|
+ }
|
|
|
+ else if (storeCmd.garageID != 0)
|
|
|
+ {
|
|
|
+ garageFreeSpace = locationOper.getGarageFreeSpace(storeCmd.garageID);
|
|
|
+ if (garageFreeSpace > 0)
|
|
|
+ {
|
|
|
+ if (storeCmd.userID != "" && storeCmd.LicenseNum != "")
|
|
|
+ {
|
|
|
+ queue.SetMessage((Command)storeCmd.Clone());
|
|
|
+ UILogServer.ins.info("发送成功");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ UILogServer.ins.error("该车库没有剩余车位");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void Fetch(string lic)
|
|
|
+ {
|
|
|
+ storeCmd.manual = true;
|
|
|
+ storeCmd.commandType = 'f';
|
|
|
+ storeCmd.userID = locationOper.GetUserID(userId).ToString();
|
|
|
+ storeCmd.LicenseNum = lic;
|
|
|
+ storeCmd.TimeRecord = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
|
|
+ try
|
|
|
+ {
|
|
|
+ storeCmd.garageID = Convert.ToInt32(garageId);
|
|
|
+ }
|
|
|
+ catch { UILogServer.ins.error("非法车库号,请重新输入"); return; }
|
|
|
+ bool isTelRegister = locationOper.IsTelRegister(userId);
|
|
|
+ bool isNumberPlate = locationOper.IsNumberPlate(storeCmd.LicenseNum, storeCmd.garageID);
|
|
|
+ if (isTelRegister == false)
|
|
|
+ {
|
|
|
+ UILogServer.ins.error("该号码未被注册,请先注册");
|
|
|
+ }
|
|
|
+ else if (isNumberPlate == false)
|
|
|
+ {
|
|
|
+ UILogServer.ins.error("车库中查无此车");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ storeCmd.parkingRecordsID = locationOper.GetParkingRecordsID(storeCmd.LicenseNum);
|
|
|
+ if (storeCmd.userID != "" && storeCmd.LicenseNum != "" && storeCmd.parkingRecordsID != 0)
|
|
|
+ {
|
|
|
+ queue.SetMessage((Command)storeCmd.Clone());
|
|
|
+ UILogServer.ins.info("发送成功");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ UILogServer.ins.error("电话号码或号牌错误");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public void Run()
|
|
|
+ {
|
|
|
+ while (true)
|
|
|
+ {
|
|
|
+ rnd = new Random(DateTime.Now.Millisecond);
|
|
|
+ if (numStatusMap.Count > 0)
|
|
|
+ {
|
|
|
+ int index = rnd.Next(0, numStatusMap.Count);
|
|
|
+ int status = numStatusMap[index].status;
|
|
|
+ if(status == 0)
|
|
|
+ {
|
|
|
+ Store(numStatusMap[index].licNum);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Fetch(numStatusMap[index].licNum);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Thread.Sleep(licInterval);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ class CarStatusStru
|
|
|
+ {
|
|
|
+ public string licNum { get; set; }
|
|
|
+ public int status { get; set; }
|
|
|
+ public CarStatusStru()
|
|
|
+ {
|
|
|
+ licNum = "";
|
|
|
+ status = 0;
|
|
|
+ }
|
|
|
+ public CarStatusStru(string str, int stat)
|
|
|
+ {
|
|
|
+ licNum = str;
|
|
|
+ status = stat;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|