Terminal.cs 80 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651
  1. using Terminal;
  2. using db;
  3. using System.Collections.Generic;
  4. using System.Threading.Tasks;
  5. using PLCS7;
  6. using System;
  7. using System.Text;
  8. using MySql.Data.MySqlClient;
  9. using System.Threading;
  10. using BroadcastModule;
  11. using parkMonitor.LOG;
  12. using centralController.model;
  13. namespace Terminal
  14. {
  15. public class Terminal
  16. {
  17. public static List<TerminalStru> terminalInfo = new List<PLCS7.TerminalStru>();
  18. /// <summary>
  19. /// 记录地面停车位id与获取号牌映射
  20. /// </summary>
  21. private static Dictionary<int, string> idLicMap = new Dictionary<int, string>();
  22. /// <summary>
  23. /// 记录地面停车位id与凭证号映射
  24. /// </summary>
  25. private static Dictionary<int, int> idReceiptMap = new Dictionary<int, int>();
  26. /// <summary>
  27. /// 取车地面位id与是否已计费标记映射
  28. /// </summary>
  29. public static Dictionary<int, bool> termCalcMap = new Dictionary<int, bool>();
  30. /// <summary>
  31. /// 终端ID与取车完成标志映射
  32. /// </summary>
  33. public static Dictionary<int, bool> fetchCompleteMap = new Dictionary<int, bool>();
  34. /// <summary>
  35. /// 终端ID与取车信息映射
  36. /// </summary>
  37. private static Dictionary<int, FetchInfo> fetchInfoMap = new Dictionary<int, FetchInfo>();
  38. private static List<bool> lockList = new List<bool>();
  39. public static bool isClosing = false;
  40. /// <summary>
  41. /// 从终端结构体中获得车牌号
  42. /// </summary>
  43. /// <param name="ts"></param>
  44. /// <returns></returns>
  45. private static string GetLicenseFromTerm(TerminalStru ts)
  46. {
  47. string header = Encoding.ASCII.GetString(BitConverter.GetBytes(ts.licenseCodeB));
  48. string identityA = Encoding.ASCII.GetString(BitConverter.GetBytes(ts.licenseCodeC));
  49. byte[] bytes = BitConverter.GetBytes(ts.licenseCodeD);
  50. List<byte> newBytes = new List<byte>();
  51. for (int i = 0; i < bytes.Length; i++)
  52. {
  53. if (bytes[i] != 0x00) { newBytes.Add(bytes[i]); }
  54. }
  55. string identityB = Encoding.ASCII.GetString(newBytes.ToArray());
  56. Log.WriteLog(LogType.process, LogFile.INFO, "已从终端" + ts.terminalID + "获得号牌:" + header + identityA + identityB);
  57. //根据省份对应的两位数字查找汉字
  58. string province = header.Substring(0, 2);
  59. string provinceIndex = header.Substring(2);
  60. string provinceQuerySql = "select NumberPlateHeader from numberplatemapping where mappedString = " + province + ";";
  61. if (province != "/0/0")
  62. {
  63. lock (Monitor.Monitor.localDBOper)
  64. {
  65. //object[] result = Monitor.Monitor.localDBOper.Query(provinceQuerySql);
  66. MySqlDataReader reader = Monitor.Monitor.localDBOper.Query(provinceQuerySql);
  67. try
  68. {
  69. if (reader != null && reader.Read() && reader.HasRows)
  70. {
  71. province = reader.GetString("NumberPlateHeader");
  72. //Console.WriteLine(province);
  73. }
  74. }
  75. catch { }
  76. try
  77. {
  78. //if (result!=null && result.Length > 0) { province = (string)result[0]; }
  79. if (reader != null)
  80. {
  81. reader.Close();
  82. reader.Dispose();
  83. }
  84. }
  85. catch { }
  86. }
  87. return province + provinceIndex + identityA + identityB;
  88. }
  89. else
  90. return "";
  91. }
  92. /// <summary>
  93. /// 更新所有车位信息
  94. /// </summary>
  95. private static void UpdateAllParkingSpace(bool remote)
  96. {
  97. string findParkingSpace = "select parkingSpaceID from parkingspace;";
  98. HashSet<int> recordsIDSet = new HashSet<int>();
  99. DBOperation dbHandle = null;
  100. if (!remote)
  101. {
  102. dbHandle = Monitor.Monitor.localDBOper;
  103. }
  104. else
  105. {
  106. dbHandle = Monitor.Monitor.remoteDBOper;
  107. }
  108. lock (dbHandle)
  109. {
  110. MySqlDataReader reader = dbHandle.Query(findParkingSpace);
  111. if (reader != null)
  112. {
  113. try
  114. {
  115. while (reader.Read())
  116. {
  117. if (reader.HasRows)
  118. {
  119. recordsIDSet.Add(reader.GetInt32("parkingSpaceID"));
  120. }
  121. }
  122. }
  123. catch { Log.WriteLog(LogType.process, LogFile.INFO, "数据库车位查询异常"); }
  124. try
  125. {
  126. reader.Close();
  127. reader.Dispose();
  128. }
  129. catch { }
  130. }
  131. }
  132. List<string> updateSpaceList = new List<string>();
  133. List<string> insertSpaceList = new List<string>();
  134. string updateParkingSpace = "";
  135. string insertParkingSpace = "";
  136. for (int i = 0; i < Monitor.Monitor.parkingSpaceInfo.Count; i++)
  137. {
  138. if (recordsIDSet.Contains(Monitor.Monitor.parkingSpaceInfo[i].parkingSpace))
  139. {
  140. updateParkingSpace = "update parkingspace set parkingSpaceX = " + Monitor.Monitor.parkingSpaceInfo[i].coordX +
  141. ",parkingSpaceY = " + Monitor.Monitor.parkingSpaceInfo[i].coordY + ",parkingSpaceZ = " + Monitor.Monitor.parkingSpaceInfo[i].floorNo + ",parkingSpaceState = " + Monitor.Monitor.parkingSpaceInfo[i].spaceStatus + " where (parkingSpaceID = " + Monitor.Monitor.parkingSpaceInfo[i].parkingSpace + ");";
  142. updateSpaceList.Add(updateParkingSpace);
  143. }
  144. else
  145. {
  146. if (!remote)
  147. {
  148. insertParkingSpace = "insert into parkingspace (parkingSpaceID,parkingSpaceX,parkingSpaceY,parkingSpaceZ,parkingSpaceState) values (" + Monitor.Monitor.parkingSpaceInfo[i].parkingSpace + "," + Monitor.Monitor.parkingSpaceInfo[i].coordX +
  149. "," + Monitor.Monitor.parkingSpaceInfo[i].coordY + "," + Monitor.Monitor.parkingSpaceInfo[i].floorNo + "," + Monitor.Monitor.parkingSpaceInfo[i].spaceStatus + ");";
  150. insertSpaceList.Add(insertParkingSpace);
  151. }
  152. else
  153. {
  154. insertParkingSpace = "insert into parkingspace (parkingSpaceID,parkingSpaceX,parkingSpaceY,parkingSpaceZ,parkingSpaceState,garageID,parkingSpaceName) values (" + Monitor.Monitor.parkingSpaceInfo[i].parkingSpace + "," + Monitor.Monitor.parkingSpaceInfo[i].coordX +
  155. "," + Monitor.Monitor.parkingSpaceInfo[i].coordY + "," + Monitor.Monitor.parkingSpaceInfo[i].floorNo + "," + Monitor.Monitor.parkingSpaceInfo[i].spaceStatus + "," + Monitor.Monitor.garageID + ",'默认');";
  156. insertSpaceList.Add(insertParkingSpace);
  157. }
  158. }
  159. }
  160. try
  161. {
  162. lock (dbHandle)
  163. {
  164. int id = 0;
  165. dbHandle.UpdateTransaction(updateSpaceList);
  166. dbHandle.Insert(insertSpaceList, out id);
  167. }
  168. }
  169. catch (Exception e) { Log.WriteLog(LogType.process, LogFile.ERROR, "更新本地所有车位异常"); Console.WriteLine("更新本地所有车位异常" + e.Message); }
  170. }
  171. /// <summary>
  172. /// 更新车辆状态
  173. /// </summary>
  174. /// <param name="lic"></param>
  175. /// <param name="state"></param>
  176. private static void UpdateVehicle(string lic, int state, int parkingRecordsID, bool park, bool remote, int parkingSpaceID)
  177. {
  178. if (lic != "")
  179. {
  180. MySqlDataReader reader;
  181. //查询车辆是否在车辆表中
  182. string checkVehicleState = "select * from vehicle where numberPlate = '" + lic + "';";
  183. if (!remote)
  184. {
  185. reader = Monitor.Monitor.localDBOper.Query(checkVehicleState);
  186. }
  187. else
  188. {
  189. //Log.WriteLog(LogType.database, "update, query: \n");
  190. reader = Monitor.Monitor.remoteDBOper.Query(checkVehicleState);
  191. //Log.WriteLog(LogType.database, "update, query: \n" + checkVehicleState);
  192. }
  193. if (reader != null)
  194. {
  195. if (reader.Read() && reader.HasRows)
  196. {
  197. //更新车辆状态
  198. string updateVehicleState = "";
  199. string updateRemoteVehicleState = "";
  200. if (park)
  201. {
  202. if (parkingRecordsID > 0)
  203. {
  204. if (parkingSpaceID == 0)
  205. {
  206. updateVehicleState = "update vehicle set vehiclepParkState = " + state + " ,parkingRecordsID = " + parkingRecordsID + " where numberPlate = '" + lic + "';";
  207. updateRemoteVehicleState = "update vehicle set vehiclepParkState = " + state + " ,parkingRecordsID = " + parkingRecordsID + ",garageID = " + Monitor.Monitor.garageID + " where numberPlate = '" + lic + "';";
  208. }
  209. else
  210. {
  211. updateVehicleState = "update vehicle set vehiclepParkState = " + state + " ,parkingRecordsID = " + parkingRecordsID + ",parkingSpaceID = " + parkingSpaceID + " where numberPlate = '" + lic + "';";
  212. updateRemoteVehicleState = "update vehicle set vehiclepParkState = " + state + " ,parkingRecordsID = " + parkingRecordsID + ",parkingSpaceID = " + parkingSpaceID + ",garageID = " + Monitor.Monitor.garageID + " where numberPlate = '" + lic + "';";
  213. }
  214. }
  215. else
  216. {
  217. updateVehicleState = "update vehicle set vehiclepParkState = " + state + " where numberPlate = '" + lic + "';";
  218. updateRemoteVehicleState = updateVehicleState;
  219. }
  220. }
  221. else
  222. {
  223. updateVehicleState = "update vehicle set vehiclepParkState = " + state + " where numberPlate = '" + lic + "';";
  224. updateRemoteVehicleState = updateVehicleState;
  225. }
  226. List<string> list = new List<string>();
  227. if (!remote)
  228. {
  229. list.Add(updateVehicleState);
  230. Monitor.Monitor.localDBOper.UpdateTransaction(list);
  231. }
  232. else
  233. {
  234. //Log.WriteLog(LogType.database, "update, update: \n");
  235. list.Add(updateRemoteVehicleState);
  236. Monitor.Monitor.remoteDBOper.UpdateTransaction(list);
  237. //Log.WriteLog(LogType.database, "update, update: \n" + updateRemoteVehicleState);
  238. }
  239. }
  240. else
  241. {
  242. //插入车辆
  243. string insertVehicleWithState = "";
  244. if (park)
  245. {
  246. if (parkingRecordsID > 0)
  247. insertVehicleWithState = "insert into vehicle (numberPlate,vehicleTypeID,vehiclepParkState,parkingRecordsID) values " +
  248. "('" + lic + "',NULL,'" + state + "'," + parkingRecordsID + ");";
  249. else
  250. insertVehicleWithState = "insert into vehicle (numberPlate,vehicleTypeID,vehiclepParkState) values " +
  251. "('" + lic + "',NULL,'" + state + "');";
  252. }
  253. else
  254. {
  255. Log.WriteLog(LogType.process, LogFile.ERROR, "取车无法获得车辆信息");
  256. Console.WriteLine("明显异常,取车发现无车辆");
  257. try
  258. {
  259. reader.Close();
  260. reader.Dispose();
  261. }
  262. catch { }
  263. return;
  264. }
  265. List<string> list = new List<string>();
  266. list.Add(insertVehicleWithState);
  267. int id = 0;
  268. if (!remote)
  269. {
  270. Monitor.Monitor.localDBOper.Insert(list, out id);
  271. }
  272. else
  273. {
  274. Monitor.Monitor.remoteDBOper.Insert(list, out id);
  275. }
  276. }
  277. try
  278. {
  279. reader.Close();
  280. reader.Dispose();
  281. }
  282. catch { }
  283. }
  284. }
  285. }
  286. /// <summary>
  287. /// 流程结束清除终端相关信息,同时允许再次根据地感拍号牌
  288. /// </summary>
  289. /// <param name="id"></param>
  290. private static void ClearTerminal(int id, bool removeReceipt)
  291. {
  292. for (int i = 0; i < terminalInfo.Count; i++)
  293. {
  294. if (terminalInfo[i].terminalID == id)
  295. {
  296. Log.WriteLog(LogType.process, LogFile.WARNING, "即将删除终端" + id + "数据:" + terminalInfo[i].ToString());
  297. lockList[i] = false;
  298. }
  299. }
  300. TerminalStru tsFromCentral = new TerminalStru
  301. {
  302. terminalID = (short)id,
  303. parkingFee = (short)32767,
  304. receiptNum = removeReceipt ? 0 : (short)-1
  305. };
  306. TerminalStru tsFromTerminal = new TerminalStru
  307. {
  308. terminalID = (short)id,
  309. btnStatus = (short)0,
  310. receiptNum = removeReceipt ? 0 : (short)-1
  311. };
  312. Monitor.Monitor.PLC.WriteToPLC(tsFromCentral, PLCDataType.central);
  313. Thread.Sleep(300);
  314. Monitor.Monitor.PLC.WriteToPLC(tsFromTerminal, PLCDataType.terminal);
  315. }
  316. /// <summary>
  317. /// 清除流程完成标记
  318. /// </summary>
  319. private static void ResetCompleteSignal()
  320. {
  321. MainBlockStru mbs = new MainBlockStru
  322. {
  323. centralHearbeat = (short)-1,
  324. bookParkCmd = -1,
  325. bookFetchCmd = -1,
  326. processCompleted = (short)0,
  327. licenseReceived = (short)-1
  328. };
  329. Monitor.Monitor.PLC.WriteToPLC(mbs, PLCDataType.central);
  330. }
  331. /// <summary>
  332. /// 更新PLC提供的特定车位状态
  333. /// </summary>
  334. /// <param name="state"></param>
  335. private static void UpdateSpecificParkingSpace()
  336. {
  337. try
  338. {
  339. lock (Monitor.Monitor.PLCReadLock)
  340. {
  341. //获取当前车位ID
  342. int parkingSpaceID = Monitor.Monitor.mainBlockInfo.currentParkingSpaceID;
  343. //获取车位状态
  344. List<object> received = Monitor.Monitor.PLC.ReadFromPLC(PLCDataType.parkingSpace, parkingSpaceID);
  345. //本地车位更新
  346. for (int i = 0; i < Monitor.Monitor.parkingSpaceInfo.Count; i++)
  347. {
  348. if (Monitor.Monitor.parkingSpaceInfo[i].parkingSpace == parkingSpaceID)
  349. {
  350. ParkingSpaceStru ps = Monitor.Monitor.parkingSpaceInfo[i];
  351. ps.spaceStatus = (short)((ParkingSpaceStru)received[0]).spaceStatus;
  352. ps.receiptNum = ((ParkingSpaceStru)received[0]).receiptNum;
  353. ps.length = (short)((ParkingSpaceStru)received[0]).length;
  354. ps.width = (short)((ParkingSpaceStru)received[0]).width;
  355. ps.height = (short)((ParkingSpaceStru)received[0]).height;
  356. Monitor.Monitor.parkingSpaceInfo[i] = ps;
  357. break;
  358. }
  359. }
  360. }
  361. }
  362. catch { Console.WriteLine("更新此车位异常"); }
  363. }
  364. /// <summary>
  365. /// 验证会员信息
  366. /// </summary>
  367. /// <param name="ts"></param>
  368. /// <param name="userID"></param>
  369. /// <param name="license"></param>
  370. /// <param name="status"></param>
  371. private static void ValidateUserInfo(TerminalStru ts, int userID, string license, out int status)
  372. {
  373. status = 0;
  374. //与云端数据比对
  375. string checkNetSql = "select * from user where userID = 1;";
  376. MySqlDataReader readerTest = Monitor.Monitor.remoteDBOper.Query(checkNetSql);
  377. if (readerTest != null)
  378. {
  379. if (readerTest.Read() && readerTest.HasRows)
  380. {
  381. try
  382. {
  383. readerTest.Close();
  384. readerTest.Dispose();
  385. }
  386. catch { }
  387. string userInfoCheckSql = "select * from usercarrelation where userID = '" + userID + "' and numberPlate = '" + license + "';";
  388. MySqlDataReader reader = Monitor.Monitor.remoteDBOper.Query(userInfoCheckSql);
  389. if (reader != null && reader.Read() && reader.HasRows && userID != 0 && license != "")
  390. {
  391. ts.licVerification = 1;//验证成功
  392. Monitor.Monitor.PLC.WriteToPLC(ts, PLCDataType.central);
  393. status = 1;
  394. Log.WriteLog(LogType.process, LogFile.INFO, "号牌验证成功");
  395. Monitor.Monitor.SetNotification("注册用户,号牌验证成功", parkMonitor.model.TextColor.Info);
  396. }
  397. else
  398. {
  399. ts.licVerification = 1;//验证失败
  400. Monitor.Monitor.PLC.WriteToPLC(ts, PLCDataType.central);
  401. status = 2;
  402. Log.WriteLog(LogType.process, LogFile.WARNING, "号牌验证失败");
  403. Monitor.Monitor.SetNotification("注册用户,号牌验证失败", parkMonitor.model.TextColor.Error);
  404. }
  405. try
  406. {
  407. reader.Close();
  408. reader.Dispose();
  409. }
  410. catch { }
  411. }
  412. else
  413. {
  414. try
  415. {
  416. readerTest.Close();
  417. readerTest.Dispose();
  418. }
  419. catch { }
  420. ts.licVerification = 1;//网络异常,跳过验证
  421. Monitor.Monitor.PLC.WriteToPLC(ts, PLCDataType.central);
  422. status = 1;
  423. Log.WriteLog(LogType.process, LogFile.ERROR, "网络异常,无法验证号牌");
  424. }
  425. }
  426. }
  427. /// <summary>
  428. /// 查询停车记录id
  429. /// </summary>
  430. /// <param name="querySql"></param>
  431. /// <param name="recordsID"></param>
  432. /// <param name="remote"></param>
  433. private static void QueryParkingRecordsID(string querySql, out int recordsID, bool remote)
  434. {
  435. recordsID = 0;
  436. MySqlDataReader reader = null;
  437. if (!remote)
  438. {
  439. reader = Monitor.Monitor.localDBOper.Query(querySql);
  440. }
  441. else
  442. {
  443. reader = Monitor.Monitor.remoteDBOper.Query(querySql);
  444. }
  445. if (reader != null)
  446. {
  447. try
  448. {
  449. while (reader.Read())
  450. {
  451. if (reader.HasRows)
  452. recordsID = reader.GetInt32("parkingRecordsID");
  453. }
  454. }
  455. catch (Exception e) { Log.WriteLog(LogType.process, LogFile.ERROR, "查询停车记录id失败"); Console.WriteLine(e.Message); };
  456. try
  457. {
  458. reader.Close();
  459. reader.Dispose();
  460. }
  461. catch { }
  462. }
  463. }
  464. //private static void BookedCarProcess()
  465. //{
  466. // for (int i = 0; i < terminalInfo.Count; i++)
  467. // {
  468. // if (terminalInfo[i].groundStatus == 1 && terminalInfo[i].btnStatus == 0)
  469. // {
  470. // string license = Monitor.Monitor.numMachineLinker.GetLicensePlate(terminalInfo[i].terminalID);
  471. // if (license == "") { break; }
  472. // else
  473. // {
  474. // }
  475. // }
  476. // }
  477. //}
  478. #region 获取号牌方法,已调整
  479. /// <summary>
  480. /// 停车流程,收到号牌机启动后操作过程
  481. /// </summary>
  482. private static void ParkNumSubProcess()
  483. {
  484. for (int i = 0; i < terminalInfo.Count; i++)
  485. {
  486. //启动指令与终端id匹配
  487. //if (numMachineLaunch == terminalInfo[i].terminalID)
  488. if (terminalInfo[i].numMachineLaunch == 1 && terminalInfo[i].licVerification == 0)
  489. {
  490. if (!Monitor.Monitor.globalStatus)
  491. {
  492. Monitor.Monitor.SetNotification("号牌系统已暂停,将清除终端数据", parkMonitor.model.TextColor.Warning);
  493. ClearTerminal(i, true);
  494. Thread.Sleep(5000);
  495. return;
  496. }
  497. int numReceivedStatus = 0;//1获得,2终止
  498. TerminalStru term = terminalInfo[i];
  499. if (term.terminalStatus == (short)1)
  500. {
  501. string license = "";
  502. license = Monitor.Monitor.numMachineLinker.GetLicensePlate(term.terminalID);
  503. //判断之前是否已拍摄号牌
  504. if (!idLicMap.ContainsKey(term.terminalID))
  505. {
  506. Monitor.Monitor.SetNotification("启动" + term.terminalID + "号号牌机,号牌:[" + license + "]", parkMonitor.model.TextColor.Info);
  507. }
  508. else
  509. {
  510. string lic = "";
  511. idLicMap.TryGetValue(term.terminalID, out lic);
  512. if (license != lic && lic != "")
  513. {
  514. Monitor.Monitor.SetNotification("与地感获得号牌[" + lic + "]不一致,启动" + term.terminalID + "号号牌机,号牌:[" + license + "],最终使用[" + lic + "]停车", parkMonitor.model.TextColor.Warning);
  515. license = lic;
  516. }
  517. }
  518. //记录或更新当前号牌,若无则填入默认号牌
  519. string currentLic = "";
  520. lock (idLicMap)
  521. {
  522. if (license == "")
  523. {
  524. currentLic = Monitor.Monitor.defaultLic;
  525. Monitor.Monitor.SetNotification("使用默认号牌,凭证号" + term.receiptNum, parkMonitor.model.TextColor.Error);
  526. Log.WriteLog(LogType.process, LogFile.ERROR, term.terminalID + "号号牌机未获得号牌,使用默认号牌,凭证号:" + term.receiptNum);
  527. }
  528. else
  529. {
  530. currentLic = license;
  531. }
  532. try
  533. {
  534. if (idLicMap.ContainsKey(term.terminalID))
  535. {
  536. if (!idLicMap[term.terminalID].Equals(currentLic))
  537. idLicMap[term.terminalID] = currentLic;
  538. }
  539. else
  540. {
  541. idLicMap.Add(term.terminalID, currentLic);
  542. }
  543. }
  544. catch (Exception e) { Log.WriteLog(LogType.process, LogFile.ERROR, "号牌" + license + "记录号牌异常\n" + e.StackTrace); }
  545. }
  546. Log.WriteLog(LogType.process, LogFile.INFO, "号牌" + license + "已记录");
  547. ////未获得号牌,告知PLC终止,告诉终端提示用户重新操作
  548. //if (currentLic == "")
  549. //{
  550. // MainBlockStru mbs = new MainBlockStru
  551. // {
  552. // centralHearbeat = (short)-1,
  553. // bookParkCmd = -1,
  554. // bookFetchCmd = -1,
  555. // processCompleted = (short)-1,
  556. // licenseReceived = (short)2
  557. // };
  558. // Monitor.Monitor.PLC.WriteToPLC(mbs, PLCDataType.central);
  559. // TerminalStru ts = new TerminalStru
  560. // {
  561. // terminalID = (short)term.terminalID,
  562. // paymentStatus = -1,
  563. // parkingFee = -1,
  564. // userType = -1,
  565. // licVerification = (short)1
  566. // };
  567. // Monitor.Monitor.PLC.WriteToPLC(ts, PLCDataType.central);
  568. // Thread.Sleep(500);
  569. // ClearTerminal(term.terminalID, false);
  570. // ResetCompleteSignal();
  571. // Log.WriteLog(LogType.process, LogFile.ERROR, "未获得号牌");
  572. //}
  573. //else
  574. //{
  575. TerminalStru ts = new TerminalStru
  576. {
  577. terminalID = (short)term.terminalID,
  578. paymentStatus = -1,
  579. parkingFee = -1,
  580. userType = -1
  581. };
  582. //注册用户
  583. if (term.btnStatus == (short)2 || term.btnStatus == (short)3)
  584. {
  585. int userID = term.licenseCodeA;
  586. string userLicense = GetLicenseFromTerm(term);
  587. //注册用户缺ID信息,转为普通用户停车,终端将限制该情况发生
  588. if (userID == 0)
  589. {
  590. term.btnStatus = 1;
  591. }
  592. else
  593. {
  594. //与云端数据比对,比对失败转普通用户停车
  595. ValidateUserInfo(ts, userID, userLicense, out numReceivedStatus);
  596. if (numReceivedStatus == 2)
  597. {
  598. term.btnStatus = 1;
  599. //idLicMap.Remove(term.terminalID);
  600. }
  601. }
  602. }
  603. //非注册用户
  604. if (term.btnStatus == (short)1 || term.btnStatus == (short)4)
  605. {
  606. numReceivedStatus = 1;
  607. ts.licVerification = 1;
  608. Monitor.Monitor.PLC.WriteToPLC(ts, PLCDataType.central);
  609. }
  610. if (term.btnStatus == (short)0)
  611. {
  612. ts.licVerification = 1;
  613. Monitor.Monitor.PLC.WriteToPLC(ts, PLCDataType.central);
  614. Log.WriteLog(LogType.process, LogFile.ERROR, "空按钮状态拍号牌");
  615. }
  616. //无论是否注册,皆告知PLC,已获取号牌或比对异常、终止流程
  617. MainBlockStru mbst = new MainBlockStru
  618. {
  619. centralHearbeat = -1,
  620. bookFetchCmd = -1,
  621. bookParkCmd = -1,
  622. processCompleted = (short)-1,
  623. licenseReceived = (short)numReceivedStatus
  624. };
  625. Monitor.Monitor.PLC.WriteToPLC(mbst, PLCDataType.central);
  626. int receiptCount = 6;
  627. while (receiptCount-- > 0)
  628. {
  629. term = terminalInfo[i];
  630. try
  631. {
  632. if (idReceiptMap.ContainsKey(term.terminalID))
  633. {
  634. if (!idReceiptMap[term.terminalID].Equals(term.receiptNum))
  635. idReceiptMap[term.terminalID] = term.receiptNum;
  636. }
  637. else
  638. {
  639. idReceiptMap.Add(term.terminalID, term.receiptNum);
  640. }
  641. Log.WriteLog(LogType.process, LogFile.INFO, "记录凭证号:" + term.receiptNum + "\n");
  642. if (term.receiptNum != 0)
  643. break;
  644. }
  645. catch (Exception e) { Log.WriteLog(LogType.process, LogFile.ERROR, "凭证号" + term.receiptNum + "记录凭证号异常\n" + e.StackTrace); }
  646. Thread.Sleep(1000);
  647. }
  648. //号牌获取结果被清零才跳出
  649. Monitor.Monitor.SetNotification("已写入号牌获取结果" + numReceivedStatus + ",等待号牌机启动指令清零", parkMonitor.model.TextColor.Info);
  650. //}
  651. int countdown = 10;
  652. while (countdown-- > 0)
  653. {
  654. if (terminalInfo[i].numMachineLaunch == 0)
  655. {
  656. Monitor.Monitor.SetNotification("号牌机启动指令已被清零", parkMonitor.model.TextColor.Info); break;
  657. }
  658. else
  659. Thread.Sleep(500);
  660. }
  661. if (countdown == 0)
  662. Monitor.Monitor.SetNotification("提醒:未检测到号牌机启动指令被清零", parkMonitor.model.TextColor.Warning);
  663. }
  664. }
  665. }
  666. }
  667. #endregion
  668. /// <summary>
  669. /// 停车流程,收到PLC停车完成信号后操作过程
  670. /// </summary>
  671. private static void ParkCompleteSubProcess()
  672. {
  673. //Console.WriteLine(Monitor.Monitor.mainBlockInfo.parkingRunning+","+ Monitor.Monitor.mainBlockInfo.processCompleted);
  674. int processAttrib = Monitor.Monitor.mainBlockInfo.parkingRunning;
  675. //int processCompleted = Monitor.Monitor.mainBlockInfo.processCompleted;
  676. int currentTerm = Monitor.Monitor.mainBlockInfo.terminalID;
  677. int parkingSpaceID = 0;
  678. if (processAttrib == 1)
  679. {
  680. TerminalStru term = new TerminalStru();
  681. string license;
  682. //等待完成信号
  683. while (true)
  684. {
  685. if (Monitor.Monitor.mainBlockInfo.processStopped == 1 || !Monitor.Monitor.globalStatus)
  686. {
  687. Log.WriteLog(LogType.process, LogFile.ERROR, "停车流程中断");
  688. Monitor.Monitor.SetNotification("停车流程中断", parkMonitor.model.TextColor.Warning);
  689. Thread.Sleep(500);
  690. ClearTerminal(currentTerm, false);
  691. ResetCompleteSignal();
  692. //流程终端清除记录的号牌
  693. try { idLicMap.Remove(currentTerm); }
  694. catch { }
  695. return;
  696. }
  697. if (Monitor.Monitor.mainBlockInfo.processCompleted == 1)
  698. {
  699. if (!idLicMap.ContainsKey(currentTerm))
  700. {
  701. Thread.Sleep(500);
  702. ClearTerminal(currentTerm, false);
  703. ResetCompleteSignal();
  704. Log.WriteLog(LogType.process, LogFile.ERROR, "停车结束时未找到号牌");
  705. }
  706. break;
  707. }
  708. Thread.Sleep(200);
  709. }
  710. //找到终端号,判断是否注册用户
  711. //拿到号牌
  712. if (/*terminalInfo[i].terminalID == currentTerm && */idLicMap.TryGetValue(currentTerm, out license) && license != "")
  713. {
  714. UpdateSpecificParkingSpace();
  715. for (int i = 0; i < terminalInfo.Count; i++)
  716. {
  717. if (terminalInfo[i].terminalID == currentTerm)
  718. term = terminalInfo[i];
  719. }
  720. //term = terminalInfo[currentTerm - 1];
  721. Thread.Sleep(500);
  722. parkingSpaceID = Monitor.Monitor.mainBlockInfo.currentParkingSpaceID;
  723. int receipt = 0;
  724. idReceiptMap.TryGetValue(term.terminalID, out receipt);
  725. //无车位信息则跳出当前循环
  726. if (parkingSpaceID == 0 || receipt == 0)
  727. {
  728. try
  729. {
  730. idLicMap.Remove(currentTerm);
  731. ClearTerminal(term.terminalID, false);
  732. }
  733. catch { }
  734. Monitor.Monitor.SetNotification("无车位或凭证号,车位:" + parkingSpaceID + ",凭证号:" + receipt, parkMonitor.model.TextColor.Warning);
  735. return;
  736. }
  737. //中控清除车牌、凭证号、号牌验证等信息
  738. ClearTerminal(term.terminalID, false);
  739. //停车流程确保已清除中控块完成信号
  740. ResetCompleteSignal();
  741. // LED屏显示,停车完成可能不提示
  742. //if (Monitor.Monitor.allInOneMachine.boardList.Count >= currentTerm)
  743. //{
  744. // Monitor.Monitor.allInOneMachine.boardList[currentTerm - 1].UpdateText("停车完成", 60, 2);
  745. // Monitor.Monitor.allInOneMachine.boardList[currentTerm - 1].UpdateArrow(-1, 2, 0);
  746. //}
  747. UpdateVehicle(license, 0, 0, true, false, 0);
  748. UpdateVehicle(license, 0, 0, true, true, 0);
  749. //插入停车记录
  750. string parkingRecordsSql = "";
  751. if (term.licenseCodeA != 0)
  752. {
  753. parkingRecordsSql = "INSERT INTO parkingrecords (userID, numberPlate,parkingSpaceID,garageID,parkingRecordsState,realParkTime,receiptNum,parkingPrice)" +
  754. "values ('" + term.licenseCodeA + "','" + license + "','" + parkingSpaceID + "','" + Monitor.Monitor.garageID + "',3,'" + DateTime.Now.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss") + "','" + receipt + "',NULL);";
  755. Monitor.Monitor.SetNotification("用户" + term.licenseCodeA + "插入停车记录", parkMonitor.model.TextColor.Info);
  756. Log.WriteLog(LogType.process, LogFile.INFO, "用户" + term.licenseCodeA + "插入停车记录," + license + "停在" + parkingSpaceID + ",凭证号:" + receipt);
  757. }
  758. else
  759. {
  760. parkingRecordsSql = "INSERT INTO parkingrecords (userID, numberPlate,parkingSpaceID,garageID,parkingRecordsState,realParkTime,receiptNum,parkingPrice)" +
  761. "values ('" + 30 + "','" + license + "','" + parkingSpaceID + "','" + Monitor.Monitor.garageID + "',3,'" + DateTime.Now.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss") + "','" + receipt + "',NULL);";
  762. Monitor.Monitor.SetNotification("管理员用户,插入停车记录," + license + "停在" + parkingSpaceID, parkMonitor.model.TextColor.Info);
  763. Log.WriteLog(LogType.process, LogFile.INFO, "管理员用户,插入停车记录,凭证号: " + receipt + ",终端块数据:" + term.ToString());
  764. }
  765. List<string> list = new List<string>();
  766. list.Add(parkingRecordsSql);
  767. int parkingRecordsID = 0;
  768. int remoteParkingRecordsID = 0;
  769. Monitor.Monitor.localDBOper.Insert(list, out parkingRecordsID);
  770. bool remote_insert_record = Monitor.Monitor.remoteDBOper.Insert(list, out remoteParkingRecordsID);
  771. //Log.WriteLog(LogType.database, "insert, record: \n" + parkingRecordsSql);
  772. //查询记录ID号
  773. //string findRecordSql = "select parkingRecordsID from parkingrecords where receiptNum = " + term.receiptNum + ";";
  774. //QueryParkingRecordsID(findRecordSql, out parkingRecordsID, false);
  775. //QueryParkingRecordsID(findRecordSql, out remoteParkingRecordsID, true);
  776. //更新车辆表
  777. if (parkingRecordsID != 0)
  778. {
  779. UpdateVehicle(license, 1, parkingRecordsID, true, false, parkingSpaceID);
  780. }
  781. if (remoteParkingRecordsID != 0)
  782. {
  783. UpdateVehicle(license, 1, remoteParkingRecordsID, true, true, parkingSpaceID);
  784. }
  785. Log.WriteLog(LogType.process, LogFile.INFO, "停车记录表已更新");
  786. //更新车位
  787. UpdateAllParkingSpace(false);
  788. //Monitor.Monitor.AddNotification("停车数据库已更新,等待流程结束状态清零。");
  789. //while (Monitor.Monitor.mainBlockInfo.processCompleted != 0)
  790. //{
  791. // Thread.Sleep(1000);
  792. //}
  793. Thread.Sleep(500);
  794. try { idLicMap.Remove(currentTerm); }
  795. catch { }
  796. Monitor.Monitor.SetNotification(license + " 数据库已更新,停车流程结束", parkMonitor.model.TextColor.Info);
  797. Log.WriteLog(LogType.process, LogFile.INFO, license + " 停车流程结束");
  798. Log.WriteLog(LogType.process, LogFile.INFO, "--------------------------------");
  799. }
  800. }
  801. }
  802. /// <summary>
  803. /// 预约车辆检测
  804. /// </summary>
  805. private static void ReservedCarCheck()
  806. {
  807. if (lockList.Count != terminalInfo.Count)
  808. {
  809. lockList.Clear();
  810. for (int i = 0; i < terminalInfo.Count; i++)
  811. {
  812. lockList.Add(false);
  813. }
  814. }
  815. for (int i = 0; i < terminalInfo.Count; i++)
  816. {
  817. //Console.WriteLine(i);
  818. //找到停车终端,且有地感无按钮数据,拍摄号牌
  819. if (terminalInfo[i].terminalStatus == 1 && terminalInfo[i].groundStatus == 1 && terminalInfo[i].btnStatus == 0 && !lockList[i])
  820. {
  821. lockList[i] = true;
  822. Action<int> reserveAction = new Action<int>(ReservedOper);
  823. reserveAction(i);
  824. //找到停车终端,且无地感有按钮数据,空闲状态,清除按钮状态
  825. }
  826. else if (terminalInfo[i].terminalStatus == 1 && terminalInfo[i].groundStatus == 0 && terminalInfo[i].btnStatus != 0 && terminalInfo[i].cmd == 0)
  827. {
  828. TerminalStru ts = new TerminalStru
  829. {
  830. terminalID = terminalInfo[i].terminalID,
  831. paymentStatus = (short)-1,
  832. btnStatus = 0,
  833. cmd = (short)-1,
  834. licenseCodeA = -1,
  835. licenseCodeB = -1,
  836. licenseCodeC = -1,
  837. licenseCodeD = -1,
  838. receiptNum = -1
  839. };
  840. Monitor.Monitor.PLC.WriteToPLC(ts, PLCDataType.terminal);
  841. Log.WriteLog(LogType.process, LogFile.INFO, "清除按钮状态,写入PLC:" + ts.btnStatus);
  842. lockList[i] = false;
  843. }
  844. //else if (lockList[i] && terminalInfo[i].terminalID == 1)
  845. //{
  846. // Log.WriteLog(LogType.process, LogFile.INFO, "停车终端,根据地感号牌获取中......");
  847. //}
  848. }
  849. }
  850. private static void ReservedOper(int index)
  851. {
  852. Task.Factory.StartNew(() =>
  853. {
  854. string license = "";
  855. int countdown = 5;
  856. short registered = 4;
  857. while (license == "" && countdown-- > 0)
  858. {
  859. license = Monitor.Monitor.numMachineLinker.GetLicensePlate(terminalInfo[index].terminalID);
  860. }
  861. if (license != "")
  862. {
  863. Monitor.Monitor.SetNotification(terminalInfo[index].terminalID + "号车位收到地感,拍到" + license, parkMonitor.model.TextColor.Log);
  864. //map中加入或更新号牌,供完成时写入数据库用
  865. if (idLicMap.ContainsKey(terminalInfo[index].terminalID))
  866. {
  867. idLicMap[terminalInfo[index].terminalID] = license;
  868. }
  869. else
  870. {
  871. idLicMap.Add(terminalInfo[index].terminalID, license);
  872. }
  873. if (Monitor.Monitor.webServer.ReservedCarCheck(license))
  874. {
  875. registered = 3;
  876. Monitor.Monitor.SetNotification("预约车辆入场", parkMonitor.model.TextColor.Info);
  877. }
  878. #region 通过数据库查询是否预约车,方法待定
  879. //int vehicleState = -1;
  880. //string vehicleStateCheckSql = "select vehiclepParkState from vehicle where numberPlate = '" + license + "';";
  881. //MySqlDataReader reader = Monitor.Monitor.localDBOper.Query(vehicleStateCheckSql);
  882. //if (reader != null)
  883. //{
  884. // try
  885. // {
  886. // if (reader.Read())
  887. // {
  888. // vehicleState = reader.GetInt32("vehiclepParkState");
  889. // }
  890. // }
  891. // catch (Exception e) { Log.WriteLog(LogType.process, LogFile.ERROR, "预约检测,查询车辆状态异常"); ; Console.WriteLine(e.Message); };
  892. // try
  893. // {
  894. // reader.Close();
  895. // reader.Dispose();
  896. // }
  897. // catch { }
  898. //}
  899. //已预约车辆入场
  900. //if (vehicleState == 4)
  901. //{
  902. // registered = 3;
  903. //}
  904. #endregion
  905. TerminalStru ts = new TerminalStru
  906. {
  907. terminalID = terminalInfo[index].terminalID,
  908. paymentStatus = (short)-1,
  909. btnStatus = registered,
  910. cmd = (short)-1,
  911. licenseCodeA = -1,
  912. licenseCodeB = -1,
  913. licenseCodeC = -1,
  914. licenseCodeD = -1,
  915. receiptNum = -1
  916. };
  917. Monitor.Monitor.PLC.WriteToPLC(ts, PLCDataType.terminal);
  918. Monitor.Monitor.SetNotification("指令写入PLC:" + ts.btnStatus, parkMonitor.model.TextColor.Log);
  919. Log.WriteLog(LogType.process, LogFile.INFO, "指令写入PLC:" + ts.btnStatus);
  920. Thread.Sleep(1000);
  921. lockList[index] = false;
  922. }
  923. else
  924. {
  925. Monitor.Monitor.SetNotification("收到地感后,尝试5次未拍到号牌。", parkMonitor.model.TextColor.Log);
  926. Log.WriteLog(LogType.process, LogFile.ERROR, "收到地感后,尝试5次未拍到号牌。");
  927. Thread.Sleep(10000);
  928. lockList[index] = false;
  929. }
  930. });
  931. }
  932. private static void UpdateLedForBarrier()
  933. {
  934. for (int i = 0; i < terminalInfo.Count; i++)
  935. {
  936. // 停车终端,收到地感,尚无停车指令,提示扫描结果
  937. bool condition = terminalInfo[i].terminalStatus == (short)1 && terminalInfo[i].groundStatus == (short)1 && terminalInfo[i].cmd != 1;
  938. int scanState = -1;
  939. switch (terminalInfo[i].terminalID)
  940. {
  941. case 1:
  942. scanState = Monitor.Monitor.PLCScanInfo.scanStateTerm1; break;
  943. case 2:
  944. scanState = Monitor.Monitor.PLCScanInfo.scanStateTerm2; break;
  945. case 3:
  946. scanState = Monitor.Monitor.PLCScanInfo.scanStateTerm3; break;
  947. case 4:
  948. scanState = Monitor.Monitor.PLCScanInfo.scanStateTerm4; break;
  949. case 5:
  950. scanState = Monitor.Monitor.PLCScanInfo.scanStateTerm5; break;
  951. case 6:
  952. scanState = Monitor.Monitor.PLCScanInfo.scanStateTerm6; break;
  953. }
  954. if (scanState != -1)
  955. {
  956. LedDisplay(terminalInfo[i].terminalID, scanState, condition);
  957. }
  958. }
  959. }
  960. private static void LedDisplay(int termID, int state, bool condition)
  961. {
  962. if (Monitor.Monitor.allInOneMachine.boardList.Count >= termID)
  963. {
  964. if (state != Monitor.Monitor.allInOneMachine.boardList[termID - 1].ledScanState)
  965. {
  966. if (state == 0)
  967. {
  968. Monitor.Monitor.allInOneMachine.boardList[termID - 1].UpdateText("欢迎光临智象停车", 60, 0, 5);
  969. Monitor.Monitor.allInOneMachine.boardList[termID - 1].ledScanState = state;
  970. }
  971. else if (condition)
  972. {
  973. Monitor.Monitor.allInOneMachine.boardList[termID - 1].ledScanState = state;
  974. switch (state)
  975. {
  976. //case 0:
  977. // Monitor.Monitor.allInOneMachine.boardList[termID - 1].UpdateText("欢迎光临", 60, 2);
  978. // //Monitor.Monitor.allInOneMachine.boardList[termID - 1].UpdateArrow(-1, 2, 0);
  979. // break;
  980. case 1:
  981. Monitor.Monitor.allInOneMachine.boardList[termID - 1].UpdateText("车辆位置正常", 60, 2, 5);
  982. //Monitor.Monitor.allInOneMachine.boardList[termID - 1].UpdateArrow(-1, 2, 0);
  983. break;
  984. case 2:
  985. Monitor.Monitor.allInOneMachine.boardList[termID - 1].UpdateText("前超界,请向后移动", 30, 2, 5);
  986. Monitor.Monitor.allInOneMachine.boardList[termID - 1].UpdateArrow(1, 30, 2);
  987. break;
  988. case 3:
  989. Monitor.Monitor.allInOneMachine.boardList[termID - 1].UpdateText("后超界,请向前移动", 30, 2, 5);
  990. Monitor.Monitor.allInOneMachine.boardList[termID - 1].UpdateArrow(0, 30, 2);
  991. break;
  992. case 4:
  993. Monitor.Monitor.allInOneMachine.boardList[termID - 1].UpdateText("左超界,请向右移动", 30, 2, 5);
  994. Monitor.Monitor.allInOneMachine.boardList[termID - 1].UpdateArrow(3, 30, 2);
  995. break;
  996. case 5:
  997. Monitor.Monitor.allInOneMachine.boardList[termID - 1].UpdateText("右超界,请向左移动", 30, 2, 5);
  998. Monitor.Monitor.allInOneMachine.boardList[termID - 1].UpdateArrow(2, 30, 2);
  999. break;
  1000. case 6:
  1001. Monitor.Monitor.allInOneMachine.boardList[termID - 1].UpdateText("检测中,请稍候", 30, 2, 5);
  1002. Monitor.Monitor.allInOneMachine.boardList[termID - 1].UpdateArrow(-1, 2, 0);
  1003. break;
  1004. }
  1005. }
  1006. }
  1007. }
  1008. }
  1009. /// <summary>
  1010. /// 停车相关操作
  1011. /// 0.观测到地感信号,且按钮状态不为3,则启动号牌机获取号牌,并判断是否预约车
  1012. /// 1.读取到号牌机启动指令,启动号牌机并根据是否注册用户进行操作
  1013. /// 非注册拿到号牌后记录并告知plc
  1014. /// 注册用户,核对号牌与用户关联信息
  1015. /// 2.停车流程结束,写数据库
  1016. /// </summary>
  1017. ///
  1018. private static void ParkProcess()
  1019. {
  1020. Task.Factory.StartNew(() =>
  1021. {
  1022. while (!isClosing)
  1023. {
  1024. ParkNumSubProcess();
  1025. Thread.Sleep(Monitor.Monitor.plcRefreshInterval * 5);
  1026. }
  1027. });
  1028. Task.Factory.StartNew(() =>
  1029. {
  1030. while (!isClosing)
  1031. {
  1032. ParkCompleteSubProcess();
  1033. Thread.Sleep(Monitor.Monitor.plcRefreshInterval * 5);
  1034. }
  1035. });
  1036. Task.Factory.StartNew(() =>
  1037. {
  1038. try
  1039. {
  1040. while (!isClosing)
  1041. {
  1042. ReservedCarCheck();
  1043. Thread.Sleep(Monitor.Monitor.plcRefreshInterval * 5);
  1044. }
  1045. }
  1046. catch (Exception e) { Log.WriteLog(LogType.process, LogFile.ERROR, "预约异常," + e.Message + ", " + e.StackTrace); }
  1047. Log.WriteLog(LogType.process, LogFile.ERROR, "预约线程退出");
  1048. });
  1049. Task.Factory.StartNew(() =>
  1050. {
  1051. while (!isClosing)
  1052. {
  1053. UpdateLedForBarrier();
  1054. Thread.Sleep(Monitor.Monitor.plcRefreshInterval * 5);
  1055. }
  1056. });
  1057. }
  1058. /// <summary>
  1059. /// 根据凭证号查询停车记录
  1060. /// </summary>
  1061. /// <param name="receipt"></param>
  1062. /// <param name="recordID"></param>
  1063. /// <param name="userID"></param>
  1064. /// <param name="license"></param>
  1065. /// <param name="realParkTime"></param>
  1066. private static bool FindLocalParkingRecord(int receipt, out int recordID, out int userID, out string license, out string realParkTime)
  1067. {
  1068. recordID = 0;
  1069. userID = 0;
  1070. license = "";
  1071. realParkTime = "";
  1072. bool result = false;
  1073. string parkRecordsSql = "select parkingRecordsID,userID,numberPlate,realParkTime from parkingrecords where receiptNum = " + receipt + ";";
  1074. MySqlDataReader reader = Monitor.Monitor.localDBOper.Query(parkRecordsSql);
  1075. try
  1076. {
  1077. if (reader != null && reader.Read())
  1078. {
  1079. object[] receiver = new object[4];
  1080. reader.GetValues(receiver);
  1081. recordID = (int)receiver[0];
  1082. userID = (int)receiver[1];
  1083. license = (string)receiver[2];
  1084. realParkTime = (string)receiver[3];
  1085. result = true;
  1086. }
  1087. else
  1088. {
  1089. Log.WriteLog(LogType.process, LogFile.ERROR, "根据凭证号" + receipt + "查询停车记录失败");
  1090. Monitor.Monitor.SetNotification("取车流程, 根据凭证号查询停车记录失败", parkMonitor.model.TextColor.Error);
  1091. result = false;
  1092. }
  1093. //if (reader != null)
  1094. //{
  1095. // reader.Close();
  1096. // reader.Dispose();
  1097. //}
  1098. }
  1099. catch (Exception e) { Log.WriteLog(LogType.process, LogFile.ERROR, "根据凭证号" + receipt + "查询停车记录失败"); Console.WriteLine(e.Message); result = false; }
  1100. try
  1101. {
  1102. if (reader != null)
  1103. {
  1104. reader.Close();
  1105. reader.Dispose();
  1106. }
  1107. }
  1108. catch { }
  1109. if (result)
  1110. Log.WriteLog(LogType.process, LogFile.INFO, "根据凭证号查询停车记录成功");
  1111. return result;
  1112. }
  1113. private static bool FindRemoteParkingRecord(int receipt, out int recordID)
  1114. {
  1115. recordID = 0;
  1116. bool result = false;
  1117. string remoteParkRecordsSql = "select parkingRecordsID from parkingrecords where receiptNum = " + receipt + ";";
  1118. //Log.WriteLog(LogType.database, "find record: \n");
  1119. MySqlDataReader reader = Monitor.Monitor.remoteDBOper.Query(remoteParkRecordsSql);
  1120. //Log.WriteLog(LogType.database, "find record: \n" + remoteParkRecordsSql);
  1121. try
  1122. {
  1123. if (reader != null && reader.Read())
  1124. {
  1125. object[] receiver = new object[1];
  1126. reader.GetValues(receiver);
  1127. recordID = (int)receiver[0];
  1128. result = true;
  1129. }
  1130. }
  1131. catch (Exception e) { Console.WriteLine(e.Message); result = false; }
  1132. try
  1133. {
  1134. if (reader != null)
  1135. {
  1136. reader.Close();
  1137. reader.Dispose();
  1138. }
  1139. }
  1140. catch (Exception e) { Console.WriteLine(e.Message); result = false; }
  1141. return result;
  1142. }
  1143. /// <summary>
  1144. /// 根据号牌获取本地与远端用户VIP月卡及预约信息
  1145. /// </summary>
  1146. /// <param name="license"></param>
  1147. /// <param name="orderRecordsID"></param>
  1148. /// <param name="monthCardType"></param>
  1149. /// <param name="monthCardTimeLength"></param>
  1150. /// <param name="orderTimeLength"></param>
  1151. /// <returns></returns>
  1152. private static bool FindVipInfo(string license, ref int orderRecordsID, ref int monthCardType, ref TimeSpan monthCardTimeLength, ref TimeSpan orderTimeLength)
  1153. {
  1154. bool result = true;
  1155. string monthCardTime = "";
  1156. //本地VIP信息
  1157. string vipInfoSql = "select orderRecordsID,monthCardType,monthCardTime from vehicle where numberPlate = '" + license + "';";
  1158. MySqlDataReader reader = null;
  1159. try
  1160. {
  1161. reader = Monitor.Monitor.localDBOper.Query(vipInfoSql);
  1162. if (reader != null && reader.Read())
  1163. {
  1164. object[] receiver = new object[3];
  1165. reader.GetValues(receiver);
  1166. Console.WriteLine(receiver[2].GetType());
  1167. if (!receiver[0].GetType().Equals(typeof(DBNull)))
  1168. {
  1169. orderRecordsID = (int)receiver[0];
  1170. }
  1171. if (!receiver[1].GetType().Equals(typeof(DBNull)))
  1172. {
  1173. monthCardType = (int)(UInt32)receiver[1];
  1174. }
  1175. if (!receiver[2].GetType().Equals(typeof(DBNull)))
  1176. {
  1177. monthCardTime = (string)receiver[2];
  1178. }
  1179. //orderRecordsID = (Int32)receiver[0];
  1180. //monthCardType = (Int32)receiver[1];
  1181. //monthCardTime = (string)receiver[2];
  1182. monthCardTimeLength = DateTime.Parse(monthCardTime) - DateTime.Now;
  1183. if (monthCardTimeLength.TotalHours <= 0)
  1184. {
  1185. monthCardType = 0;
  1186. }
  1187. Log.WriteLog(LogType.process, LogFile.INFO, "已获取本地预约与月卡信息");
  1188. }
  1189. }
  1190. catch (Exception e) { Console.WriteLine(e.Message); result = false; }
  1191. try
  1192. {
  1193. if (reader != null)
  1194. {
  1195. reader.Close();
  1196. reader.Dispose();
  1197. }
  1198. }
  1199. catch (Exception e) { Console.WriteLine(e.Message); result = false; }
  1200. //云端VIP信息
  1201. try
  1202. {
  1203. reader = Monitor.Monitor.remoteDBOper.Query(vipInfoSql);
  1204. if (reader != null && reader.Read())
  1205. {
  1206. object[] receiver = new object[3];
  1207. reader.GetValues(receiver);
  1208. int cardType = (int)(UInt32)receiver[1];
  1209. string CardTime = (string)receiver[2];
  1210. TimeSpan t = DateTime.Parse(CardTime) - DateTime.Now;
  1211. //云端
  1212. if (t.TotalHours > 0 && cardType > monthCardType)
  1213. {
  1214. monthCardType = cardType;
  1215. monthCardTimeLength = t;
  1216. }
  1217. Log.WriteLog(LogType.process, LogFile.INFO, "已获取云端预约与月卡信息");
  1218. }
  1219. }
  1220. catch (Exception e) { Console.WriteLine(e.Message); result = false; }
  1221. try
  1222. {
  1223. if (reader != null)
  1224. {
  1225. reader.Close();
  1226. reader.Dispose();
  1227. }
  1228. }
  1229. catch (Exception e) { Console.WriteLine(e.Message); result = false; }
  1230. //有预约记录,判断记录有效性,有效则获取预约时长
  1231. if (orderRecordsID != 0)
  1232. {
  1233. //修改orderTimeLength
  1234. string orderInfoSql = "select bookHour from orderrecords where orderRecordsID = '" + orderRecordsID + "';";
  1235. try
  1236. {
  1237. reader = Monitor.Monitor.localDBOper.Query(vipInfoSql);
  1238. if (reader != null && reader.Read())
  1239. {
  1240. orderTimeLength = new TimeSpan(reader.GetInt32("bookHour"), 0, 0);
  1241. }
  1242. }
  1243. catch { }
  1244. }
  1245. try
  1246. {
  1247. if (reader != null)
  1248. {
  1249. reader.Close();
  1250. reader.Dispose();
  1251. }
  1252. }
  1253. catch (Exception e) { Console.WriteLine(e.Message); }
  1254. return result;
  1255. }
  1256. /// <summary>
  1257. /// 预约与停车费用计算
  1258. /// </summary>
  1259. /// <param name="scheme"></param>
  1260. /// <param name="parkTime"></param>
  1261. /// <param name="orderTimeLength"></param>
  1262. /// <returns></returns>
  1263. private static int FeeCalc(PaymentScheme scheme, DateTime parkTime, TimeSpan orderTimeLength)
  1264. {
  1265. try
  1266. {
  1267. int orderFee = scheme.bookCharge * (int)orderTimeLength.TotalHours;
  1268. int parkFee = 0;
  1269. int hours = (int)(DateTime.Now - parkTime).TotalHours;
  1270. switch (scheme.schemeType)
  1271. {
  1272. //按时计费
  1273. case 1:
  1274. if (hours > scheme.firstChargeTime + scheme.freeTime)
  1275. {
  1276. if (hours > 24)
  1277. {
  1278. parkFee = hours / 24 * scheme.upperBound + Math.Min(scheme.intervalCharge * (hours % 24) / scheme.chargeInterval, scheme.upperBound);
  1279. }
  1280. else
  1281. {
  1282. parkFee = Math.Min(scheme.firstCharge + scheme.intervalCharge * hours / scheme.chargeInterval, scheme.upperBound);
  1283. }
  1284. }
  1285. else if (hours > scheme.freeTime)
  1286. {
  1287. parkFee = scheme.firstCharge;
  1288. }
  1289. else
  1290. {
  1291. parkFee = 0;
  1292. }
  1293. break;
  1294. //按次计费
  1295. case 2:
  1296. //Console.WriteLine(DateTime.Now.Date.ToString()+","+ parkTime.Date.ToString());
  1297. int overnightCount = (DateTime.Now.Date - parkTime.Date).Days;
  1298. parkFee = scheme.eachCharge + overnightCount * scheme.overnightCharge;
  1299. break;
  1300. //按时间段计费
  1301. case 3:
  1302. TimeSpan currentTimeOfDay = DateTime.Now.TimeOfDay;
  1303. TimeSpan parkTimeOfDay = parkTime.TimeOfDay;
  1304. TimeSpan startTimeOfDay = DateTime.Parse(scheme.startChargeTime).TimeOfDay;
  1305. TimeSpan endTimeOfDay = DateTime.Parse(scheme.endChargeTime).TimeOfDay;
  1306. double countingHoursOfDay = endTimeOfDay.TotalHours - startTimeOfDay.TotalHours;
  1307. int days = (int)((DateTime.Now - parkTime).TotalHours - currentTimeOfDay.TotalHours + parkTimeOfDay.TotalHours);
  1308. int previousOffset = (int)(-(Math.Max(0, parkTimeOfDay.TotalHours - startTimeOfDay.TotalHours)));
  1309. int currentOffset = (int)Math.Min((currentTimeOfDay.TotalHours - startTimeOfDay.TotalHours), countingHoursOfDay);
  1310. int peakTimeLength = days * (int)countingHoursOfDay + previousOffset + currentOffset;
  1311. parkFee = peakTimeLength * scheme.chargeStandard + ((int)((DateTime.Now - parkTime).TotalHours) - peakTimeLength) * scheme.intervalCharge;
  1312. break;
  1313. }
  1314. Log.WriteLog(LogType.process, LogFile.INFO, "停车费用" + parkFee);
  1315. return parkFee;
  1316. }
  1317. catch (Exception e) { Console.WriteLine("费用计算异常"); return -1; }
  1318. }
  1319. /// <summary>
  1320. /// 取车计费子操作
  1321. /// </summary>
  1322. private static void FetchFeeCalcSubProcess()
  1323. {
  1324. int receiptNum = 0;
  1325. int termIndex = -1;
  1326. bool failed = false;
  1327. TerminalStru ts = new TerminalStru();
  1328. for (int i = 0; i < terminalInfo.Count; i++)
  1329. {
  1330. ts = terminalInfo[i];
  1331. termIndex = ts.terminalID;
  1332. receiptNum = ts.receiptNum;
  1333. //取车状态、凭证号不为空,查询数据库计费
  1334. //Console.WriteLine((termIndex != -1) + "," + (termUsedMap.Count >= termIndex) + "," + termUsedMap.TryGetValue(termIndex, out bool valuee) + "," + (!valuee) + "," + (fetchState == 1) + "," + (receiptNum != 0));
  1335. bool value = false;
  1336. if (termIndex != -1 && termCalcMap.Count >= termIndex && termCalcMap.TryGetValue(termIndex, out value) && !value && ts.cmd == 2 && receiptNum != 0)
  1337. {
  1338. if (!Monitor.Monitor.globalStatus)
  1339. {
  1340. Monitor.Monitor.SetNotification("取车计费系统已暂停,请检查无误后手动开启", parkMonitor.model.TextColor.Warning);
  1341. ClearTerminal(termIndex, true);
  1342. Thread.Sleep(5000);
  1343. return;
  1344. }
  1345. //fetchState = Monitor.Monitor.mainBlockInfo.fetchingRunning;
  1346. Monitor.Monitor.SetNotification(termIndex + "号终端准备计算费用", parkMonitor.model.TextColor.Log);
  1347. termCalcMap[termIndex] = true;
  1348. //Console.WriteLine("终端编号" + termIndex);
  1349. int parkingRecordsID = 0;
  1350. int remoteParkingRecordsID = 0;
  1351. int userID = 0;
  1352. string license = "";
  1353. string realParkTime = "";
  1354. //1.根据凭证号查询停车记录
  1355. if (!FindLocalParkingRecord(receiptNum, out parkingRecordsID, out userID, out license, out realParkTime))
  1356. {
  1357. failed = true;
  1358. //return;
  1359. }
  1360. else
  1361. {
  1362. FindRemoteParkingRecord(receiptNum, out remoteParkingRecordsID);
  1363. }
  1364. //本地存在号牌,后续操作
  1365. //2.根据号牌查询车辆月卡信息与预约记录
  1366. int orderRecordsID = 0;
  1367. int monthCardType = -1;
  1368. string monthCardTime = "";
  1369. TimeSpan monthCardTimeLength = new TimeSpan(0);
  1370. TimeSpan orderTimeLength = new TimeSpan(0);
  1371. if (license != "")
  1372. {
  1373. bool getVIP = FindVipInfo(license, ref orderRecordsID, ref monthCardType, ref monthCardTimeLength, ref orderTimeLength);
  1374. //Log.WriteLog(LogType.database, "get vip: " + getVIP);
  1375. }
  1376. if (monthCardType == -1) monthCardType = 0;
  1377. //3.获取停车时刻,根据用户类型计费发送给PLC,暂认为无预约
  1378. DateTime parkTime = DateTime.Now, currentTime = DateTime.Now;
  1379. try
  1380. {
  1381. parkTime = DateTime.Parse(realParkTime);
  1382. }
  1383. catch { failed = true; }
  1384. int fee = 32767;
  1385. if (failed) { monthCardType = 0; }
  1386. if (PaymentScheme.ins != null)
  1387. {
  1388. if (monthCardTimeLength.TotalHours > 0)
  1389. {
  1390. fee = 0;
  1391. }
  1392. else if (failed)
  1393. {
  1394. fee = 0;
  1395. }
  1396. else
  1397. {
  1398. fee = FeeCalc(PaymentScheme.ins, parkTime, orderTimeLength);
  1399. }
  1400. try
  1401. {
  1402. if (Monitor.Monitor.PLC != null)
  1403. {
  1404. TerminalStru FeeMsg = new TerminalStru();
  1405. FeeMsg.terminalID = (short)termIndex;
  1406. FeeMsg.paymentStatus = (short)-1;
  1407. FeeMsg.licVerification = (short)-1;
  1408. FeeMsg.parkingFee = (short)fee;
  1409. FeeMsg.userType = (short)(monthCardType + 1);
  1410. Console.WriteLine(FeeMsg);
  1411. Monitor.Monitor.PLC.WriteToPLC(FeeMsg, PLCDataType.central);
  1412. Log.WriteLog(LogType.process, LogFile.INFO, "停车费用已发送至PLC");
  1413. }
  1414. }
  1415. catch { Console.WriteLine("error"); }
  1416. }
  1417. Monitor.Monitor.SetNotification("用户类型:" + (monthCardType + 1) + ",费用:" + fee + ",等待凭证号被清除且流程结束后更新车辆状态", parkMonitor.model.TextColor.Log);
  1418. FetchInfo fetchInfo = new FetchInfo(license, parkingRecordsID, remoteParkingRecordsID, fee, receiptNum);
  1419. if (!fetchInfoMap.ContainsKey(termIndex))
  1420. {
  1421. fetchInfoMap.Add(termIndex, fetchInfo);
  1422. fetchCompleteMap.Add(termIndex, true);
  1423. }
  1424. else
  1425. {
  1426. fetchInfoMap[termIndex] = fetchInfo;
  1427. fetchCompleteMap[termIndex] = true;
  1428. }
  1429. }
  1430. }
  1431. }
  1432. private static void FetchCompleteProcess()
  1433. {
  1434. int fetchState = Monitor.Monitor.mainBlockInfo.fetchingRunning;
  1435. int termID = -1;
  1436. try
  1437. {
  1438. if (fetchState == 1)
  1439. {
  1440. //找到当前取车终端
  1441. for (int i = 0; i < terminalInfo.Count; i++)
  1442. {
  1443. if (terminalInfo[i].terminalID == Monitor.Monitor.mainBlockInfo.terminalID && Monitor.Monitor.mainBlockInfo.terminalID != 0)
  1444. {
  1445. termID = terminalInfo[i].terminalID;
  1446. break;
  1447. }
  1448. }
  1449. if (fetchCompleteMap.ContainsKey(termID) && fetchCompleteMap[termID])
  1450. {
  1451. fetchCompleteMap[termID] = false;
  1452. Task.Factory.StartNew(() =>
  1453. {
  1454. //4.等待终端获得收费完成信号且将凭证号清除后,清除收费完成信号并将信息写入数据库
  1455. int count = 0;
  1456. while (!isClosing && termID != -1)
  1457. {
  1458. if (Monitor.Monitor.mainBlockInfo.processStopped == 1 || !Monitor.Monitor.globalStatus)
  1459. {
  1460. Log.WriteLog(LogType.process, LogFile.INFO, "取车流程中断");
  1461. Monitor.Monitor.SetNotification("取车流程中断", parkMonitor.model.TextColor.Warning);
  1462. ClearTerminal(termID, false);
  1463. //停车流程确保已清除中控块完成信号
  1464. Thread.Sleep(500);
  1465. ResetCompleteSignal();
  1466. break;
  1467. }
  1468. if (Monitor.Monitor.mainBlockInfo.processCompleted == 1)
  1469. {
  1470. if (Monitor.Monitor.allInOneMachine.boardList.Count >= termID)
  1471. {
  1472. Monitor.Monitor.allInOneMachine.boardList[termID - 1].UpdateText("取车完成,请将车辆驶离车库,智象停车祝您一路顺风。", 60, 2);
  1473. Monitor.Monitor.allInOneMachine.boardList[termID - 1].UpdateArrow(-1, 2, 0);
  1474. }
  1475. UpdateSpecificParkingSpace();
  1476. //while (terminalInfo[termIndex].receiptNum != 0)
  1477. //{
  1478. // count++;
  1479. // if (count == 1)
  1480. // Monitor.Monitor.SetNotification("等待凭证号清除", parkMonitor.model.TextColor.Log);
  1481. // if (count > 10000)//避免int型数据溢出
  1482. // count = 2;
  1483. // Thread.Sleep(200);
  1484. //}
  1485. int paymentStatus = 0;
  1486. for (int i = 0; i < terminalInfo.Count; i++)
  1487. {
  1488. if (terminalInfo[i].terminalID == Monitor.Monitor.mainBlockInfo.terminalID)
  1489. {
  1490. paymentStatus = terminalInfo[i].paymentStatus;
  1491. break;
  1492. }
  1493. }
  1494. //Log.WriteLog(LogType.process, LogFile.INFO, "检测到凭证号已被清除");
  1495. FetchInfo fi = null;
  1496. ClearTerminal(termID, false);
  1497. //停车流程确保已清除中控块完成信号
  1498. Thread.Sleep(500);
  1499. ResetCompleteSignal();
  1500. UpdateAllParkingSpace(false);
  1501. if (fetchInfoMap.ContainsKey(termID))
  1502. {
  1503. fi = fetchInfoMap[termID];
  1504. }
  1505. else
  1506. {
  1507. Monitor.Monitor.SetNotification("未查询到该取车终端存在计费操作", parkMonitor.model.TextColor.Error);
  1508. Log.WriteLog(LogType.process, LogFile.ERROR, "终端" + termID + "无计费操作");
  1509. return;
  1510. }
  1511. //TerminalStru fetchReset = new TerminalStru
  1512. //{
  1513. // terminalID = (short)termIndex,
  1514. // paymentStatus = (short)0,
  1515. // licVerification = (short)0,
  1516. // parkingFee = (short)32767,
  1517. // userType = (short)0
  1518. //};
  1519. //Monitor.Monitor.PLC.WriteToPLC(fetchReset, PLCDataType.central);
  1520. //更新停车记录与车辆状态
  1521. string updateParkingRecordsSql = "update parkingrecords set parkingRecordsState = 6,realGetTime = '" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") +
  1522. "',parkingPrice = " + fi.fee + ",paymentStatus = " + paymentStatus + " where receiptNum = '" + fi.receiptNum + "';";
  1523. List<string> list = new List<string>();
  1524. list.Add(updateParkingRecordsSql);
  1525. lock (Monitor.Monitor.localDBOper)
  1526. {
  1527. Monitor.Monitor.localDBOper.UpdateTransaction(list);
  1528. UpdateVehicle(fi.license, 0, fi.parkingRecordsID, false, false, 0);
  1529. }
  1530. lock (Monitor.Monitor.remoteDBOper)
  1531. {
  1532. //Log.WriteLog(LogType.database, "update fetch record: " + updateParkingRecordsSql);
  1533. Monitor.Monitor.remoteDBOper.UpdateTransaction(list);
  1534. UpdateVehicle(fi.license, 0, fi.remoteParkingRecordsID, false, true, 0);
  1535. }
  1536. Monitor.Monitor.SetNotification(fi.license + " 取车流程结束", parkMonitor.model.TextColor.Info);
  1537. Log.WriteLog(LogType.process, LogFile.INFO, fi.license + " 取车流程结束");
  1538. Log.WriteLog(LogType.process, LogFile.INFO, "--------------------------------");
  1539. break;
  1540. }
  1541. Thread.Sleep(200);
  1542. }
  1543. termCalcMap[termID] = false;
  1544. fetchInfoMap.Remove(termID);
  1545. fetchCompleteMap.Remove(termID);
  1546. });
  1547. }
  1548. }
  1549. }
  1550. catch (Exception ex) { Log.WriteLog(LogType.process, LogFile.ERROR, "取车完成流程异常," + ex.StackTrace); }
  1551. }
  1552. /// <summary>
  1553. /// 取车相关操作
  1554. ///
  1555. /// </summary>
  1556. private static void FetchProcess()
  1557. {
  1558. Task.Factory.StartNew(() =>
  1559. {
  1560. while (!isClosing)
  1561. {
  1562. FetchFeeCalcSubProcess();
  1563. Thread.Sleep(Monitor.Monitor.plcRefreshInterval);
  1564. }
  1565. });
  1566. Task.Factory.StartNew(() =>
  1567. {
  1568. while (!isClosing)
  1569. {
  1570. FetchCompleteProcess();
  1571. Thread.Sleep(Monitor.Monitor.plcRefreshInterval);
  1572. }
  1573. });
  1574. }
  1575. public static void Start()
  1576. {
  1577. for (int i = 0; i < Monitor.Monitor.plcTerminalCount; i++)
  1578. {
  1579. lockList.Add(false);
  1580. }
  1581. ResetCompleteSignal();
  1582. ParkProcess();
  1583. FetchProcess();
  1584. //定时更新云端车位,5min
  1585. Task.Factory.StartNew(() =>
  1586. {
  1587. while (!isClosing)
  1588. {
  1589. UpdateAllParkingSpace(true);
  1590. Thread.Sleep(300000);
  1591. }
  1592. });
  1593. }
  1594. public static void Stop()
  1595. {
  1596. isClosing = true;
  1597. }
  1598. public class FetchInfo
  1599. {
  1600. public string license;
  1601. public int parkingRecordsID;
  1602. public int remoteParkingRecordsID;
  1603. public int fee;
  1604. public int receiptNum;
  1605. public FetchInfo(string license, int parkingRecordsID, int remoteParkingRecordsID, int fee, int receiptNum)
  1606. {
  1607. this.license = license;
  1608. this.parkingRecordsID = parkingRecordsID;
  1609. this.remoteParkingRecordsID = remoteParkingRecordsID;
  1610. this.fee = fee;
  1611. this.receiptNum = receiptNum;
  1612. }
  1613. }
  1614. }
  1615. }