Terminal.cs 55 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212
  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. public static Dictionary<int, bool> termUsedMap = new Dictionary<int, bool>();
  26. private static Dictionary<int, FetchInfo> fetchMap = new Dictionary<int, FetchInfo>();
  27. private static List<object> lockList = new List<object>();
  28. public static bool isClosing = false;
  29. public void FeeCal()
  30. {
  31. }
  32. public void GetTerminalState()
  33. {
  34. }
  35. private object SearchPaymentScheme()
  36. {
  37. return null;
  38. }
  39. private void UpdateParkingRecords(int Object)
  40. {
  41. }
  42. /// <summary>
  43. /// 从终端结构体中获得车牌号
  44. /// </summary>
  45. /// <param name="ts"></param>
  46. /// <returns></returns>
  47. private static string GetLicenseFromTerm(TerminalStru ts)
  48. {
  49. string header = Encoding.ASCII.GetString(BitConverter.GetBytes(ts.licenseCodeB));
  50. string identityA = Encoding.ASCII.GetString(BitConverter.GetBytes(ts.licenseCodeC));
  51. byte[] bytes = BitConverter.GetBytes(ts.licenseCodeD);
  52. List<byte> newBytes = new List<byte>();
  53. for (int i = 0; i < bytes.Length; i++)
  54. {
  55. if (bytes[i] != 0x00) { newBytes.Add(bytes[i]); }
  56. }
  57. string identityB = Encoding.ASCII.GetString(newBytes.ToArray());
  58. Log.WriteLog(LogType.process, LogFile.INFO, "已从终端" + ts.terminalID + "获得号牌:" + header + identityA + identityB);
  59. //根据省份对应的两位数字查找汉字
  60. string province = header.Substring(0, 2);
  61. string provinceIndex = header.Substring(2);
  62. string provinceQuerySql = "select NumberPlateHeader from numberplatemapping where mappedString = " + province + ";";
  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. /// <summary>
  90. /// 更新所有车位信息
  91. /// </summary>
  92. private static void UpdateAllParkingSpace()
  93. {
  94. string findParkingSpace = "select parkingSpaceID from parkingspace;";
  95. HashSet<int> recordsIDSet = new HashSet<int>();
  96. lock (Monitor.Monitor.localDBOper)
  97. {
  98. //object[] result = Monitor.Monitor.localDBOper.Query(findParkingSpace);
  99. //if(result!=null && result.Length > 0)
  100. //{
  101. // for (int i = 0; i < result.Length; i++)
  102. // {
  103. // recordsIDSet.Add((int)result[i]);
  104. // }
  105. //}
  106. MySqlDataReader reader = Monitor.Monitor.localDBOper.Query(findParkingSpace);
  107. if (reader != null)
  108. {
  109. try
  110. {
  111. while (reader.Read())
  112. {
  113. if (reader.HasRows)
  114. {
  115. recordsIDSet.Add(reader.GetInt32("parkingSpaceID"));
  116. }
  117. }
  118. }
  119. catch { }
  120. try
  121. {
  122. reader.Close();
  123. reader.Dispose();
  124. }
  125. catch { }
  126. }
  127. }
  128. List<string> updateSpaceList = new List<string>();
  129. List<string> insertSpaceList = new List<string>();
  130. string updateParkingSpace = "";
  131. string insertParkingSpace = "";
  132. for (int i = 0; i < Monitor.Monitor.parkingSpaceInfo.Count; i++)
  133. {
  134. if (recordsIDSet.Contains(Monitor.Monitor.parkingSpaceInfo[i].parkingSpace))
  135. {
  136. updateParkingSpace = "update parkingspace set parkingSpaceX = " + Monitor.Monitor.parkingSpaceInfo[i].coordX +
  137. ",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 + ");";
  138. updateSpaceList.Add(updateParkingSpace);
  139. }
  140. else
  141. {
  142. insertParkingSpace = "insert into parkingspace (parkingSpaceID,parkingSpaceX,parkingSpaceY,parkingSpaceZ,parkingSpaceState) values (" + Monitor.Monitor.parkingSpaceInfo[i].parkingSpace + "," + Monitor.Monitor.parkingSpaceInfo[i].coordX +
  143. "," + Monitor.Monitor.parkingSpaceInfo[i].coordY + "," + Monitor.Monitor.parkingSpaceInfo[i].floorNo + "," + Monitor.Monitor.parkingSpaceInfo[i].spaceStatus + ");";
  144. insertSpaceList.Add(insertParkingSpace);
  145. }
  146. }
  147. try
  148. {
  149. lock (Monitor.Monitor.localDBOper)
  150. {
  151. Monitor.Monitor.localDBOper.UpdateTransaction(updateSpaceList);
  152. Monitor.Monitor.localDBOper.Insert(insertSpaceList);
  153. }
  154. }
  155. catch (Exception e) { Log.WriteLog(LogType.process, LogFile.ERROR, "更新本地所有车位异常"); Console.WriteLine("更新本地所有车位异常" + e.Message); }
  156. }
  157. /// <summary>
  158. /// 更新车辆状态
  159. /// </summary>
  160. /// <param name="lic"></param>
  161. /// <param name="state"></param>
  162. private static void UpdateVehicle(string lic, int state, int parkingRecordsID, bool park, bool remote, int parkingSpaceID)
  163. {
  164. if (lic != "")
  165. {
  166. MySqlDataReader reader;
  167. //查询车辆是否在车辆表中
  168. string checkVehicleState = "select * from vehicle where numberPlate = '" + lic + "';";
  169. if (!remote)
  170. {
  171. reader = Monitor.Monitor.localDBOper.Query(checkVehicleState);
  172. }
  173. else
  174. {
  175. reader = Monitor.Monitor.remoteDBOper.Query(checkVehicleState);
  176. }
  177. if (reader != null)
  178. {
  179. if (reader.Read() && reader.HasRows)
  180. {
  181. //更新车辆状态
  182. string updateVehicleState = "";
  183. string updateRemoteVehicleState = "";
  184. if (park)
  185. {
  186. if (parkingRecordsID > 0)
  187. {
  188. if (parkingSpaceID == 0)
  189. {
  190. updateVehicleState = "update vehicle set vehiclepParkState = " + state + " ,parkingRecordsID = " + parkingRecordsID + " where numberPlate = '" + lic + "';";
  191. updateRemoteVehicleState = "update vehicle set vehiclepParkState = " + state + " ,parkingRecordsID = " + parkingRecordsID + ",garageID = " + Monitor.Monitor.garageID + " where numberPlate = '" + lic + "';";
  192. }
  193. else
  194. {
  195. updateVehicleState = "update vehicle set vehiclepParkState = " + state + " ,parkingRecordsID = " + parkingRecordsID + ",parkingSpaceID = " + parkingSpaceID + " where numberPlate = '" + lic + "';";
  196. updateRemoteVehicleState = "update vehicle set vehiclepParkState = " + state + " ,parkingRecordsID = " + parkingRecordsID + ",parkingSpaceID = " + parkingSpaceID + ",garageID = " + Monitor.Monitor.garageID + " where numberPlate = '" + lic + "';";
  197. }
  198. }
  199. else
  200. {
  201. updateVehicleState = "update vehicle set vehiclepParkState = " + state + " where numberPlate = '" + lic + "';";
  202. updateRemoteVehicleState = updateVehicleState;
  203. }
  204. }
  205. else
  206. {
  207. updateVehicleState = "update vehicle set vehiclepParkState = " + state + " where numberPlate = '" + lic + "';";
  208. updateRemoteVehicleState = updateVehicleState;
  209. }
  210. List<string> list = new List<string>();
  211. if (!remote)
  212. {
  213. list.Add(updateVehicleState);
  214. Monitor.Monitor.localDBOper.UpdateTransaction(list);
  215. }
  216. else
  217. {
  218. list.Add(updateRemoteVehicleState);
  219. Monitor.Monitor.remoteDBOper.UpdateTransaction(list);
  220. }
  221. }
  222. else
  223. {
  224. //插入车辆
  225. string insertVehicleWithState = "";
  226. if (park)
  227. {
  228. if (parkingRecordsID > 0)
  229. insertVehicleWithState = "insert into vehicle (numberPlate,vehicleTypeID,vehiclepParkState,parkingRecordsID) values " +
  230. "('" + lic + "',NULL,'" + state + "'," + parkingRecordsID + ");";
  231. else
  232. insertVehicleWithState = "insert into vehicle (numberPlate,vehicleTypeID,vehiclepParkState) values " +
  233. "('" + lic + "',NULL,'" + state + "');";
  234. }
  235. else
  236. {
  237. Log.WriteLog(LogType.process, LogFile.ERROR, "取车无法获得车辆信息");
  238. Console.WriteLine("明显异常,取车发现无车辆");
  239. try
  240. {
  241. reader.Close();
  242. reader.Dispose();
  243. }
  244. catch { }
  245. return;
  246. }
  247. List<string> list = new List<string>();
  248. list.Add(insertVehicleWithState);
  249. if (!remote)
  250. {
  251. Monitor.Monitor.localDBOper.Insert(list);
  252. }
  253. else
  254. {
  255. Monitor.Monitor.remoteDBOper.Insert(list);
  256. }
  257. }
  258. try
  259. {
  260. reader.Close();
  261. reader.Dispose();
  262. }
  263. catch { }
  264. }
  265. }
  266. }
  267. /// <summary>
  268. /// 流程结束清除终端相关信息
  269. /// </summary>
  270. /// <param name="id"></param>
  271. private static void ClearTerminal(int id)
  272. {
  273. TerminalStru tsFromCentral = new TerminalStru
  274. {
  275. terminalID = (short)id,
  276. parkingFee = (short)32767,
  277. };
  278. TerminalStru tsFromTerminal = new TerminalStru
  279. {
  280. terminalID = (short)id,
  281. btnStatus = (short)0,
  282. };
  283. Monitor.Monitor.PLC.WriteToPLC(tsFromCentral, PLCDataType.central);
  284. Monitor.Monitor.PLC.WriteToPLC(tsFromTerminal, PLCDataType.terminal);
  285. }
  286. /// <summary>
  287. /// 验证会员信息
  288. /// </summary>
  289. /// <param name="ts"></param>
  290. /// <param name="userID"></param>
  291. /// <param name="license"></param>
  292. /// <param name="status"></param>
  293. private static void ValidateUserInfo(TerminalStru ts, int userID, string license, out int status)
  294. {
  295. status = 0;
  296. //与云端数据比对
  297. string checkNetSql = "select * from user where userID = 1;";
  298. MySqlDataReader readerTest = Monitor.Monitor.remoteDBOper.Query(checkNetSql);
  299. if (readerTest != null)
  300. {
  301. if (readerTest.Read() && readerTest.HasRows)
  302. {
  303. string userInfoCheckSql = "select * from usercarrelation where userID = '" + userID + "'and numberPlate = '" + license + "';";
  304. MySqlDataReader reader = Monitor.Monitor.remoteDBOper.Query(userInfoCheckSql);
  305. if (reader != null && reader.Read() && reader.HasRows && userID != 0 && license != "")
  306. {
  307. ts.licVerification = 1;//验证成功
  308. Monitor.Monitor.PLC.WriteToPLC(ts, PLCDataType.central);
  309. status = 1;
  310. Log.WriteLog(LogType.process, LogFile.INFO, "号牌验证成功");
  311. Monitor.Monitor.SetNotification("注册用户,号牌验证成功");
  312. }
  313. else
  314. {
  315. ts.licVerification = 2;//验证失败
  316. Monitor.Monitor.PLC.WriteToPLC(ts, PLCDataType.central);
  317. status = 2;
  318. Log.WriteLog(LogType.process, LogFile.WARNING, "号牌验证失败");
  319. Monitor.Monitor.SetNotification("注册用户,号牌验证失败");
  320. }
  321. try
  322. {
  323. reader.Close();
  324. reader.Dispose();
  325. }
  326. catch { }
  327. }
  328. else
  329. {
  330. ts.licVerification = 1;//网络异常,跳过验证
  331. Monitor.Monitor.PLC.WriteToPLC(ts, PLCDataType.central);
  332. status = 1;
  333. Log.WriteLog(LogType.process, LogFile.ERROR, "网络异常,无法验证号牌");
  334. }
  335. try
  336. {
  337. readerTest.Close();
  338. readerTest.Dispose();
  339. }
  340. catch { }
  341. }
  342. }
  343. /// <summary>
  344. /// 查询停车记录id
  345. /// </summary>
  346. /// <param name="querySql"></param>
  347. /// <param name="recordsID"></param>
  348. /// <param name="remote"></param>
  349. private static void QueryParkingRecordsID(string querySql, out int recordsID, bool remote)
  350. {
  351. recordsID = 0;
  352. MySqlDataReader reader = null;
  353. if (!remote)
  354. {
  355. reader = Monitor.Monitor.localDBOper.Query(querySql);
  356. }
  357. else
  358. {
  359. reader = Monitor.Monitor.remoteDBOper.Query(querySql);
  360. }
  361. if (reader != null)
  362. {
  363. try
  364. {
  365. if (reader.Read())
  366. {
  367. recordsID = reader.GetInt32("parkingRecordsID");
  368. }
  369. }
  370. catch (Exception e) { Log.WriteLog(LogType.process, LogFile.ERROR, "查询停车记录id失败"); ; Console.WriteLine(e.Message); };
  371. try
  372. {
  373. reader.Close();
  374. reader.Dispose();
  375. }
  376. catch { }
  377. }
  378. }
  379. private static void BookedCarProcess()
  380. {
  381. for (int i = 0; i < terminalInfo.Count; i++)
  382. {
  383. if (terminalInfo[i].groundStatus == 1 && terminalInfo[i].btnStatus == 0)
  384. {
  385. string license = Monitor.Monitor.numMachineLinker.GetLicensePlate(terminalInfo[i].terminalID);
  386. if (license == "") { break; }
  387. else
  388. {
  389. }
  390. }
  391. }
  392. }
  393. #region 早期获取号牌方法,已弃用
  394. /// <summary>
  395. /// 停车流程,收到号牌机启动后操作过程
  396. /// </summary>
  397. //private static void ParkNumSubProcess()
  398. //{
  399. // //int numMachineLaunch = Monitor.Monitor.mainBlockInfo.numMachineLaunch;
  400. // //if (numMachineLaunch != 0)
  401. // //{
  402. // for (int i = 0; i < terminalInfo.Count; i++)
  403. // {
  404. // //启动指令与终端id匹配
  405. // //if (numMachineLaunch == terminalInfo[i].terminalID)
  406. // if (terminalInfo[i].numMachineLaunch == 1 && !idLicMap.ContainsKey(terminalInfo[i].terminalID) && terminalInfo[i].licVerification == 0)
  407. // {
  408. // int numReceivedStatus = 0;//1获得,2终止
  409. // TerminalStru term = terminalInfo[i];
  410. // if (term.terminalStatus == (short)1)
  411. // {
  412. // string license = Monitor.Monitor.numMachineLinker.GetLicensePlate(terminalInfo[i].terminalID);
  413. // Monitor.Monitor.SetNotification("启动" + terminalInfo[i].terminalID + "号号牌机,号牌:" + license);
  414. // //未获得号牌,告知PLC终止,告诉终端提示用户重新操作
  415. // if (license == "")
  416. // {
  417. // MainBlockStru mb = new MainBlockStru
  418. // {
  419. // licenseReceived = (short)2
  420. // };
  421. // Monitor.Monitor.PLC.WriteToPLC(mb, PLCDataType.central);
  422. // TerminalStru ts = new TerminalStru
  423. // {
  424. // terminalID = (short)terminalInfo[i].terminalID,
  425. // paymentStatus = -1,
  426. // parkingFee = -1,
  427. // userType = -1,
  428. // licVerification = (short)2
  429. // };
  430. // Monitor.Monitor.PLC.WriteToPLC(ts, PLCDataType.central);
  431. // Log.WriteLog(LogType.process, LogFile.ERROR, "未获得号牌");
  432. // }
  433. // else
  434. // {
  435. // //记录或更新当前号牌
  436. // lock (idLicMap)
  437. // {
  438. // if (idLicMap.ContainsKey(terminalInfo[i].terminalID))
  439. // {
  440. // idLicMap[terminalInfo[i].terminalID] = license;
  441. // }
  442. // else
  443. // {
  444. // idLicMap.Add(terminalInfo[i].terminalID, license);
  445. // }
  446. // }
  447. // Log.WriteLog(LogType.process, LogFile.ERROR, "号牌" + license + "已记录");
  448. // TerminalStru ts = new TerminalStru
  449. // {
  450. // terminalID = (short)terminalInfo[i].terminalID,
  451. // paymentStatus = -1,
  452. // parkingFee = -1,
  453. // userType = -1
  454. // };
  455. // //注册用户
  456. // if (term.btnStatus == (short)2)
  457. // {
  458. // int userID = term.licenseCodeA;
  459. // string userLicense = GetLicenseFromTerm(term);
  460. // //与云端数据比对
  461. // ValidateUserInfo(ts, userID, userLicense, out numReceivedStatus);
  462. // if (numReceivedStatus == 2)
  463. // {
  464. // idLicMap.Remove(terminalInfo[i].terminalID);
  465. // }
  466. // }
  467. // //非注册用户
  468. // else if (term.btnStatus == (short)1)
  469. // {
  470. // numReceivedStatus = 1;
  471. // ts.licVerification = 1;
  472. // Monitor.Monitor.PLC.WriteToPLC(ts, PLCDataType.central);
  473. // }
  474. // //无论是否注册,皆告知PLC,已获取号牌或比对异常、终止流程
  475. // MainBlockStru mb = new MainBlockStru
  476. // {
  477. // licenseReceived = (short)numReceivedStatus
  478. // };
  479. // Monitor.Monitor.PLC.WriteToPLC(mb, PLCDataType.central);
  480. // //号牌获取结果被清零才跳出
  481. // Monitor.Monitor.SetNotification("已写入号牌获取结果,等待号牌机启动指令清零");
  482. // }
  483. // while (term.numMachineLaunch != 0)
  484. // {
  485. // Thread.Sleep(1000);
  486. // }
  487. // Monitor.Monitor.SetNotification("号牌机启动指令已被清零");
  488. // }
  489. // }
  490. // }
  491. //}
  492. #endregion
  493. /// <summary>
  494. /// 停车流程,收到PLC停车完成信号后操作过程
  495. /// </summary>
  496. private static void ParkCompleteSubProcess()
  497. {
  498. int processAttrib = Monitor.Monitor.mainBlockInfo.parkingRunning;
  499. //int processCompleted = Monitor.Monitor.mainBlockInfo.processCompleted;
  500. int currentTerm = Monitor.Monitor.mainBlockInfo.terminalID;
  501. int parkingSpaceID = 0;
  502. if (processAttrib == 1)
  503. {
  504. TerminalStru term;
  505. string license;
  506. //等待完成信号
  507. while (Monitor.Monitor.mainBlockInfo.processCompleted != 1)
  508. {
  509. Thread.Sleep(200);
  510. if (Monitor.Monitor.mainBlockInfo.processStopped == 1)
  511. return;
  512. Thread.Sleep(200);
  513. }
  514. //找到终端号,判断是否注册用户
  515. //拿到号牌
  516. if (/*terminalInfo[i].terminalID == currentTerm && */idLicMap.TryGetValue(currentTerm, out license) && license != "")
  517. {
  518. term = terminalInfo[currentTerm - 1];
  519. Thread.Sleep(1500);
  520. //找到停车位置
  521. for (int s = 0; s < Monitor.Monitor.parkingSpaceInfo.Count; s++)
  522. {
  523. Console.WriteLine(Monitor.Monitor.parkingSpaceInfo[s].receiptNum + "," + term.receiptNum);
  524. if (Monitor.Monitor.parkingSpaceInfo[s].receiptNum == term.receiptNum)
  525. {
  526. parkingSpaceID = Monitor.Monitor.parkingSpaceInfo[s].parkingSpace;
  527. break;
  528. }
  529. }
  530. //无车位信息则跳出当前循环
  531. if (parkingSpaceID == 0 || term.receiptNum == 0)
  532. {
  533. try { idLicMap.Remove(currentTerm); } catch { }
  534. Monitor.Monitor.SetNotification("无车位或凭证号");
  535. return;
  536. }
  537. UpdateVehicle(license, 0, 0, true, false, 0);
  538. UpdateVehicle(license, 0, 0, true, true, 0);
  539. //插入停车记录
  540. string parkingRecordsSql = "";
  541. if (term.licenseCodeA != 0)
  542. {
  543. parkingRecordsSql = "INSERT INTO parkingrecords (userID, numberPlate,parkingSpaceID,garageID,parkingRecordsState,realParkTime,receiptNum,parkingPrice)" +
  544. "values ('" + term.licenseCodeA + "','" + license + "','" + parkingSpaceID + "','" + Monitor.Monitor.garageID + "',3,'" + DateTime.Now.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss") + "','" + term.receiptNum + "',NULL);";
  545. }
  546. else
  547. {
  548. parkingRecordsSql = "INSERT INTO parkingrecords (userID, numberPlate,parkingSpaceID,garageID,parkingRecordsState,realParkTime,receiptNum,parkingPrice)" +
  549. "values ('" + 1 + "','" + license + "','" + parkingSpaceID + "','" + Monitor.Monitor.garageID + "',3,'" + DateTime.Now.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss") + "','" + term.receiptNum + "',NULL);";
  550. }
  551. List<string> list = new List<string>();
  552. list.Add(parkingRecordsSql);
  553. Monitor.Monitor.localDBOper.Insert(list);
  554. Monitor.Monitor.remoteDBOper.Insert(list);
  555. Log.WriteLog(LogType.process, LogFile.INFO, "停车记录已插入," + license + "停在" + parkingSpaceID + ",凭证号:" + term.receiptNum);
  556. Monitor.Monitor.SetNotification("停车记录已插入");
  557. ////注册用户记录插入云端
  558. //if (term.btnStatus == 0)
  559. //{
  560. //Monitor.Monitor.remoteDBOper.Insert(list);
  561. //}
  562. //查询记录ID号
  563. string findRecordSql = "select parkingRecordsID from parkingrecords where receiptNum = " + term.receiptNum + ";";
  564. int parkingRecordsID = 0;
  565. int remoteParkingRecordsID = 0;
  566. QueryParkingRecordsID(findRecordSql, out parkingRecordsID, false);
  567. QueryParkingRecordsID(findRecordSql, out remoteParkingRecordsID, true);
  568. //更新本地车辆表
  569. if (parkingRecordsID != 0)
  570. {
  571. UpdateVehicle(license, 1, parkingRecordsID, true, false, parkingSpaceID);
  572. }
  573. if (remoteParkingRecordsID != 0)
  574. {
  575. UpdateVehicle(license, 1, remoteParkingRecordsID, true, true, parkingSpaceID);
  576. }
  577. Log.WriteLog(LogType.process, LogFile.INFO, "停车记录表已更新");
  578. //更新本地车位
  579. UpdateAllParkingSpace();
  580. //Monitor.Monitor.AddNotification("停车数据库已更新,等待流程结束状态清零。");
  581. //while (Monitor.Monitor.mainBlockInfo.processCompleted != 0)
  582. //{
  583. // Thread.Sleep(1000);
  584. //}
  585. //中控清除车牌、凭证号、号牌验证等信息
  586. ClearTerminal(term.terminalID);
  587. try { idLicMap.Remove(currentTerm); } catch { }
  588. Monitor.Monitor.SetNotification(license + " 数据库已更新,停车流程结束");
  589. }
  590. }
  591. }
  592. /// <summary>
  593. /// 预约车辆检测
  594. /// </summary>
  595. private static void ReservedCarCheck()
  596. {
  597. if (lockList.Count != terminalInfo.Count)
  598. {
  599. lockList.Clear();
  600. for (int i = 0; i < terminalInfo.Count; i++)
  601. {
  602. lockList.Add(new object());
  603. }
  604. }
  605. //找到停车终端,且有地感无按钮数据
  606. for (int i = 0; i < terminalInfo.Count; i++)
  607. {
  608. if (terminalInfo[i].terminalStatus == 1 && terminalInfo[i].groundStatus == 1 && terminalInfo[i].btnStatus == 0)
  609. {
  610. Task.Factory.StartNew(() =>
  611. {
  612. lock (lockList[i])
  613. {
  614. string license = "";
  615. int countdown = 2;
  616. short registered = 4;
  617. while (license == "" && countdown-- > 0)
  618. {
  619. license = Monitor.Monitor.numMachineLinker.GetLicensePlate(terminalInfo[i].terminalID);
  620. }
  621. if (license != "")
  622. {
  623. //map中加入或更新号牌,供完成时写入数据库用
  624. if (idLicMap.ContainsKey(terminalInfo[i].terminalID))
  625. {
  626. idLicMap[terminalInfo[i].terminalID] = license;
  627. }
  628. else
  629. {
  630. idLicMap.Add(terminalInfo[i].terminalID, license);
  631. }
  632. if (Monitor.Monitor.webServer.ReservedCarCheck(license))
  633. {
  634. registered = 3;
  635. }
  636. #region 通过数据库查询是否预约车,方法待定
  637. //int vehicleState = -1;
  638. //string vehicleStateCheckSql = "select vehiclepParkState from vehicle where numberPlate = '" + license + "';";
  639. //MySqlDataReader reader = Monitor.Monitor.localDBOper.Query(vehicleStateCheckSql);
  640. //if (reader != null)
  641. //{
  642. // try
  643. // {
  644. // if (reader.Read())
  645. // {
  646. // vehicleState = reader.GetInt32("vehiclepParkState");
  647. // }
  648. // }
  649. // catch (Exception e) { Log.WriteLog(LogType.process, LogFile.ERROR, "预约检测,查询车辆状态异常"); ; Console.WriteLine(e.Message); };
  650. // try
  651. // {
  652. // reader.Close();
  653. // reader.Dispose();
  654. // }
  655. // catch { }
  656. //}
  657. //已预约车辆入场
  658. //if (vehicleState == 4)
  659. //{
  660. // registered = 3;
  661. //}
  662. #endregion
  663. TerminalStru ts = new TerminalStru
  664. {
  665. terminalID = terminalInfo[i].terminalID,
  666. paymentStatus = (short)-1,
  667. btnStatus = registered,
  668. cmd = (short)-1,
  669. licenseCodeA = -1,
  670. licenseCodeB = -1,
  671. licenseCodeC = -1,
  672. licenseCodeD = -1,
  673. receiptNum = -1
  674. };
  675. Monitor.Monitor.PLC.WriteToPLC(ts, PLCDataType.terminal);
  676. }
  677. Thread.Sleep(500);
  678. }
  679. });
  680. }
  681. }
  682. }
  683. /// <summary>
  684. /// 停车相关操作
  685. /// 0.观测到地感信号,且按钮状态不为3,则启动号牌机获取号牌,并判断是否预约车
  686. /// 1.读取到号牌机启动指令,启动号牌机并根据是否注册用户进行操作
  687. /// 非注册拿到号牌后记录并告知plc
  688. /// 注册用户,核对号牌与用户关联信息
  689. /// 2.停车流程结束,写数据库
  690. /// </summary>
  691. ///
  692. private static void ParkProcess()
  693. {
  694. //Task.Factory.StartNew(() =>
  695. //{
  696. // while (!isClosing)
  697. // {
  698. // ParkNumSubProcess();
  699. // Thread.Sleep(Monitor.Monitor.plcRefreshInterval*5);
  700. // }
  701. //});
  702. Task.Factory.StartNew(() =>
  703. {
  704. while (!isClosing)
  705. {
  706. ParkCompleteSubProcess();
  707. Thread.Sleep(Monitor.Monitor.plcRefreshInterval * 5);
  708. }
  709. });
  710. Task.Factory.StartNew(() =>
  711. {
  712. while (!isClosing)
  713. {
  714. ReservedCarCheck();
  715. Thread.Sleep(Monitor.Monitor.plcRefreshInterval * 5);
  716. }
  717. });
  718. }
  719. /// <summary>
  720. /// 根据凭证号查询停车记录
  721. /// </summary>
  722. /// <param name="receipt"></param>
  723. /// <param name="recordID"></param>
  724. /// <param name="userID"></param>
  725. /// <param name="license"></param>
  726. /// <param name="realParkTime"></param>
  727. private static bool FindLocalParkingRecord(int receipt, out int recordID, out int userID, out string license, out string realParkTime)
  728. {
  729. recordID = 0;
  730. userID = 0;
  731. license = "";
  732. realParkTime = "";
  733. bool result = false;
  734. string parkRecordsSql = "select parkingRecordsID,userID,numberPlate,realParkTime from parkingrecords where receiptNum = " + receipt + ";";
  735. MySqlDataReader reader = Monitor.Monitor.localDBOper.Query(parkRecordsSql);
  736. try
  737. {
  738. if (reader != null && reader.Read())
  739. {
  740. object[] receiver = new object[4];
  741. reader.GetValues(receiver);
  742. recordID = (int)receiver[0];
  743. userID = (int)receiver[1];
  744. license = (string)receiver[2];
  745. realParkTime = (string)receiver[3];
  746. result = true;
  747. }
  748. else
  749. {
  750. Log.WriteLog(LogType.process, LogFile.ERROR, "根据凭证号查询停车记录失败");
  751. Monitor.Monitor.SetNotification("取车流程, 根据凭证号查询停车记录失败");
  752. result = false;
  753. }
  754. //if (reader != null)
  755. //{
  756. // reader.Close();
  757. // reader.Dispose();
  758. //}
  759. }
  760. catch (Exception e) { Log.WriteLog(LogType.process, LogFile.ERROR, "根据凭证号查询停车记录失败"); Console.WriteLine(e.Message); result = false; }
  761. try
  762. {
  763. if (reader != null)
  764. {
  765. reader.Close();
  766. reader.Dispose();
  767. }
  768. }
  769. catch { }
  770. Log.WriteLog(LogType.process, LogFile.INFO, "根据凭证号查询停车记录成功");
  771. return result;
  772. }
  773. private static bool FindRemoteParkingRecord(int receipt, out int recordID)
  774. {
  775. recordID = 0;
  776. bool result = false;
  777. string remoteParkRecordsSql = "select parkingRecordsID from parkingrecords where receiptNum = " + receipt + ";";
  778. MySqlDataReader reader = Monitor.Monitor.remoteDBOper.Query(remoteParkRecordsSql);
  779. try
  780. {
  781. if (reader != null && reader.Read())
  782. {
  783. object[] receiver = new object[1];
  784. reader.GetValues(receiver);
  785. recordID = (int)receiver[0];
  786. result = true;
  787. }
  788. }
  789. catch (Exception e) { Console.WriteLine(e.Message); result = false; }
  790. try
  791. {
  792. if (reader != null)
  793. {
  794. reader.Close();
  795. reader.Dispose();
  796. }
  797. }
  798. catch (Exception e) { Console.WriteLine(e.Message); result = false; }
  799. return result;
  800. }
  801. /// <summary>
  802. /// 根据号牌获取本地与远端用户VIP月卡及预约信息
  803. /// </summary>
  804. /// <param name="license"></param>
  805. /// <param name="orderRecordsID"></param>
  806. /// <param name="monthCardType"></param>
  807. /// <param name="monthCardTimeLength"></param>
  808. /// <param name="orderTimeLength"></param>
  809. /// <returns></returns>
  810. private static bool FindVipInfo(string license, ref int orderRecordsID, ref int monthCardType, ref TimeSpan monthCardTimeLength, ref TimeSpan orderTimeLength)
  811. {
  812. bool result = true;
  813. string monthCardTime = "";
  814. //本地VIP信息
  815. string vipInfoSql = "select orderRecordsID,monthCardType,monthCardTime from vehicle where numberPlate = '" + license + "';";
  816. MySqlDataReader reader = null;
  817. try
  818. {
  819. reader = Monitor.Monitor.localDBOper.Query(vipInfoSql);
  820. if (reader != null && reader.Read())
  821. {
  822. object[] receiver = new object[3];
  823. reader.GetValues(receiver);
  824. Console.WriteLine(receiver[2].GetType());
  825. if (!receiver[0].GetType().Equals(typeof(DBNull)))
  826. {
  827. orderRecordsID = (int)receiver[0];
  828. }
  829. if (!receiver[1].GetType().Equals(typeof(DBNull)))
  830. {
  831. monthCardType = (int)(UInt32)receiver[1];
  832. }
  833. if (!receiver[2].GetType().Equals(typeof(DBNull)))
  834. {
  835. monthCardTime = (string)receiver[2];
  836. }
  837. //orderRecordsID = (Int32)receiver[0];
  838. //monthCardType = (Int32)receiver[1];
  839. //monthCardTime = (string)receiver[2];
  840. monthCardTimeLength = DateTime.Parse(monthCardTime) - DateTime.Now;
  841. if (monthCardTimeLength.TotalHours <= 0)
  842. {
  843. monthCardType = 0;
  844. }
  845. Log.WriteLog(LogType.process, LogFile.INFO, "已获取本地预约与月卡信息");
  846. }
  847. }
  848. catch (Exception e) { Console.WriteLine(e.Message); result = false; }
  849. try
  850. {
  851. if (reader != null)
  852. {
  853. reader.Close();
  854. reader.Dispose();
  855. }
  856. }
  857. catch (Exception e) { Console.WriteLine(e.Message); result = false; }
  858. //云端VIP信息
  859. try
  860. {
  861. reader = Monitor.Monitor.remoteDBOper.Query(vipInfoSql);
  862. if (reader != null && reader.Read())
  863. {
  864. object[] receiver = new object[3];
  865. reader.GetValues(receiver);
  866. int cardType = (int)(UInt32)receiver[1];
  867. string CardTime = (string)receiver[2];
  868. TimeSpan t = DateTime.Parse(CardTime) - DateTime.Now;
  869. //云端
  870. if (t.TotalHours > 0 && cardType > monthCardType)
  871. {
  872. monthCardType = cardType;
  873. monthCardTimeLength = t;
  874. }
  875. Log.WriteLog(LogType.process, LogFile.INFO, "已获取云端预约与月卡信息");
  876. }
  877. }
  878. catch (Exception e) { Console.WriteLine(e.Message); result = false; }
  879. try
  880. {
  881. if (reader != null)
  882. {
  883. reader.Close();
  884. reader.Dispose();
  885. }
  886. }
  887. catch (Exception e) { Console.WriteLine(e.Message); result = false; }
  888. //有预约记录,判断记录有效性,有效则获取预约时长
  889. if (orderRecordsID != 0)
  890. {
  891. //修改orderTimeLength
  892. }
  893. return result;
  894. }
  895. /// <summary>
  896. /// 预约与停车费用计算
  897. /// </summary>
  898. /// <param name="scheme"></param>
  899. /// <param name="parkTime"></param>
  900. /// <param name="orderTimeLength"></param>
  901. /// <returns></returns>
  902. private static int FeeCalc(PaymentScheme scheme, DateTime parkTime, TimeSpan orderTimeLength)
  903. {
  904. try
  905. {
  906. int orderFee = scheme.bookCharge * (int)orderTimeLength.TotalHours;
  907. int parkFee = 0;
  908. int hours = (int)(DateTime.Now - parkTime).TotalHours;
  909. switch (scheme.schemeType)
  910. {
  911. //按时计费
  912. case 1:
  913. if (hours > scheme.firstChargeTime)
  914. {
  915. parkFee = Math.Min(scheme.firstCharge + scheme.intervalCharge * hours / scheme.chargeInterval, scheme.upperBound);
  916. }
  917. else if (hours > scheme.firstChargeTime - scheme.freeTime)
  918. {
  919. parkFee = scheme.firstCharge;
  920. }
  921. else
  922. {
  923. parkFee = 0;
  924. }
  925. break;
  926. //按次计费
  927. case 2:
  928. int overnightCount = hours / 24;
  929. parkFee = scheme.eachCharge + overnightCount * scheme.overnightCharge;
  930. break;
  931. //按时间段计费
  932. case 3:
  933. TimeSpan currentTimeOfDay = DateTime.Now.TimeOfDay;
  934. TimeSpan parkTimeOfDay = parkTime.TimeOfDay;
  935. TimeSpan startTimeOfDay = DateTime.Parse(scheme.startChargeTime).TimeOfDay;
  936. TimeSpan endTimeOfDay = DateTime.Parse(scheme.endChargeTime).TimeOfDay;
  937. double countingHoursOfDay = endTimeOfDay.TotalHours - startTimeOfDay.TotalHours;
  938. int days = (int)((DateTime.Now - parkTime).TotalHours - currentTimeOfDay.TotalHours + parkTimeOfDay.TotalHours);
  939. int previousOffset = (int)(-(Math.Max(0, parkTimeOfDay.TotalHours - startTimeOfDay.TotalHours)));
  940. int currentOffset = (int)Math.Min((currentTimeOfDay.TotalHours - startTimeOfDay.TotalHours), countingHoursOfDay);
  941. int peakTimeLength = days * (int)countingHoursOfDay + previousOffset + currentOffset;
  942. parkFee = peakTimeLength * scheme.chargeStandard + ((int)((DateTime.Now - parkTime).TotalHours) - peakTimeLength) * scheme.intervalCharge;
  943. break;
  944. }
  945. Log.WriteLog(LogType.process, LogFile.INFO, "停车费用" + parkFee);
  946. return parkFee;
  947. }
  948. catch (Exception e) { Console.WriteLine("费用计算异常"); return -1; }
  949. }
  950. /// <summary>
  951. /// 取车计费子操作
  952. /// </summary>
  953. private static void FetchFeeCalcSubProcess()
  954. {
  955. int receiptNum = 0;
  956. int termIndex = -1;
  957. bool failed = false;
  958. TerminalStru ts = new TerminalStru();
  959. for (int i = 0; i < terminalInfo.Count; i++)
  960. {
  961. ts = terminalInfo[i];
  962. termIndex = ts.terminalID;
  963. receiptNum = ts.receiptNum;
  964. //取车状态、凭证号不为空,查询数据库计费
  965. //Console.WriteLine((termIndex != -1) + "," + (termUsedMap.Count >= termIndex) + "," + termUsedMap.TryGetValue(termIndex, out bool valuee) + "," + (!valuee) + "," + (fetchState == 1) + "," + (receiptNum != 0));
  966. if (termIndex != -1 && termUsedMap.Count >= termIndex && termUsedMap.TryGetValue(termIndex, out bool value) && !value && ts.cmd == 2 && receiptNum != 0)
  967. {
  968. //fetchState = Monitor.Monitor.mainBlockInfo.fetchingRunning;
  969. Monitor.Monitor.SetNotification(termIndex + "号终端准备计算费用");
  970. termUsedMap[termIndex] = true;
  971. Console.WriteLine("终端编号" + termIndex);
  972. int parkingRecordsID = 0;
  973. int remoteParkingRecordsID = 0;
  974. int userID = 0;
  975. string license = "";
  976. string realParkTime = "";
  977. //1.根据凭证号查询停车记录
  978. if (!FindLocalParkingRecord(receiptNum, out parkingRecordsID, out userID, out license, out realParkTime))
  979. {
  980. failed = true;
  981. //return;
  982. }
  983. else
  984. {
  985. FindRemoteParkingRecord(receiptNum, out remoteParkingRecordsID);
  986. }
  987. //本地存在号牌,后续操作
  988. //2.根据号牌查询车辆月卡信息与预约记录
  989. int orderRecordsID = 0;
  990. int monthCardType = -1;
  991. string monthCardTime = "";
  992. TimeSpan monthCardTimeLength = new TimeSpan(0);
  993. TimeSpan orderTimeLength = new TimeSpan(0);
  994. if (license != "")
  995. {
  996. FindVipInfo(license, ref orderRecordsID, ref monthCardType, ref monthCardTimeLength, ref orderTimeLength);
  997. }
  998. //3.获取停车时刻,根据用户类型计费发送给PLC,暂认为无预约
  999. DateTime parkTime = DateTime.Parse(realParkTime);
  1000. DateTime currentTime = DateTime.Now;
  1001. int fee = 32767;
  1002. if (failed) { monthCardType = -1; }
  1003. if (PaymentScheme.ins != null)
  1004. {
  1005. if (monthCardTimeLength.TotalHours > 0)
  1006. {
  1007. fee = 0;
  1008. }
  1009. else if (failed)
  1010. {
  1011. fee = 0;
  1012. }
  1013. else
  1014. {
  1015. fee = FeeCalc(PaymentScheme.ins, parkTime, orderTimeLength);
  1016. }
  1017. try
  1018. {
  1019. if (Monitor.Monitor.PLC != null)
  1020. {
  1021. TerminalStru FeeMsg = new TerminalStru();
  1022. FeeMsg.terminalID = (short)termIndex;
  1023. FeeMsg.paymentStatus = (short)-1;
  1024. FeeMsg.licVerification = (short)-1;
  1025. FeeMsg.parkingFee = (short)fee;
  1026. FeeMsg.userType = (short)(monthCardType + 1);
  1027. Console.WriteLine(FeeMsg);
  1028. Monitor.Monitor.PLC.WriteToPLC(FeeMsg, PLCDataType.central);
  1029. Log.WriteLog(LogType.process, LogFile.INFO, "停车费用已发送至PLC");
  1030. }
  1031. }
  1032. catch { Console.WriteLine("error"); }
  1033. }
  1034. Monitor.Monitor.SetNotification("用户类型:" + monthCardType + ",费用:" + fee + ",等待凭证号被清除且流程结束后更新车辆状态");
  1035. FetchInfo fetchInfo = new FetchInfo(license, parkingRecordsID, remoteParkingRecordsID, fee, receiptNum);
  1036. if (!fetchMap.ContainsKey(termIndex))
  1037. fetchMap.Add(termIndex, fetchInfo);
  1038. else
  1039. fetchMap[termIndex] = fetchInfo;
  1040. }
  1041. }
  1042. }
  1043. private static void FetchCompleteProcess()
  1044. {
  1045. int fetchState = Monitor.Monitor.mainBlockInfo.fetchingRunning;
  1046. int termIndex = -1;
  1047. TerminalStru ts = new TerminalStru();
  1048. if (fetchState == 1)
  1049. {
  1050. //找到当前取车终端
  1051. for (int i = 0; i < terminalInfo.Count; i++)
  1052. {
  1053. if (terminalInfo[i].terminalID == Monitor.Monitor.mainBlockInfo.terminalID)
  1054. {
  1055. ts = terminalInfo[i];
  1056. termIndex = ts.terminalID;
  1057. break;
  1058. }
  1059. }
  1060. //4.等待终端获得收费完成信号且将凭证号清除后,清除收费完成信号并将信息写入数据库
  1061. int count = 0;
  1062. while (!isClosing && termIndex != -1)
  1063. {
  1064. if (Monitor.Monitor.mainBlockInfo.processCompleted == 1)
  1065. {
  1066. while (terminalInfo[termIndex - 1].receiptNum != 0)
  1067. {
  1068. count++;
  1069. if (count == 1)
  1070. Monitor.Monitor.SetNotification("等待凭证号清除");
  1071. }
  1072. int paymentStatus = 0;
  1073. for (int i = 0; i < terminalInfo.Count; i++)
  1074. {
  1075. if (terminalInfo[i].terminalID == Monitor.Monitor.mainBlockInfo.terminalID)
  1076. {
  1077. paymentStatus = terminalInfo[i].paymentStatus;
  1078. break;
  1079. }
  1080. }
  1081. Log.WriteLog(LogType.process, LogFile.INFO, "检测到凭证号已被清除");
  1082. FetchInfo fi = null;
  1083. if (fetchMap.ContainsKey(termIndex))
  1084. {
  1085. fi = fetchMap[termIndex];
  1086. }
  1087. else
  1088. {
  1089. Monitor.Monitor.SetNotification("未查询到该取车终端存在计费操作");
  1090. return;
  1091. }
  1092. //TerminalStru fetchReset = new TerminalStru
  1093. //{
  1094. // terminalID = (short)termIndex,
  1095. // paymentStatus = (short)0,
  1096. // licVerification = (short)0,
  1097. // parkingFee = (short)32767,
  1098. // userType = (short)0
  1099. //};
  1100. //Monitor.Monitor.PLC.WriteToPLC(fetchReset, PLCDataType.central);
  1101. ClearTerminal(termIndex);
  1102. //更新停车记录与车辆状态
  1103. string updateParkingRecordsSql = "update parkingrecords set parkingRecordsState = 6,realGetTime = '" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") +
  1104. "',parkingPrice = " + fi.fee + ",paymentStatus = " + paymentStatus + " where receiptNum = '" + fi.receiptNum + "';";
  1105. List<string> list = new List<string>();
  1106. list.Add(updateParkingRecordsSql);
  1107. lock (Monitor.Monitor.localDBOper)
  1108. {
  1109. Monitor.Monitor.localDBOper.UpdateTransaction(list);
  1110. UpdateVehicle(fi.license, 0, fi.parkingRecordsID, false, false, 0);
  1111. }
  1112. lock (Monitor.Monitor.remoteDBOper)
  1113. {
  1114. Monitor.Monitor.remoteDBOper.UpdateTransaction(list);
  1115. UpdateVehicle(fi.license, 0, fi.remoteParkingRecordsID, false, true, 0);
  1116. }
  1117. Monitor.Monitor.SetNotification(fi.license + " 取车流程结束");
  1118. break;
  1119. }
  1120. Thread.Sleep(1000);
  1121. }
  1122. termUsedMap[termIndex] = false;
  1123. fetchMap.Remove(termIndex);
  1124. }
  1125. }
  1126. /// <summary>
  1127. /// 取车相关操作
  1128. ///
  1129. /// </summary>
  1130. private static void FetchProcess()
  1131. {
  1132. Task.Factory.StartNew(() =>
  1133. {
  1134. while (!isClosing)
  1135. {
  1136. FetchFeeCalcSubProcess();
  1137. Thread.Sleep(Monitor.Monitor.plcRefreshInterval);
  1138. }
  1139. });
  1140. Task.Factory.StartNew(() =>
  1141. {
  1142. while (!isClosing)
  1143. {
  1144. FetchCompleteProcess();
  1145. Thread.Sleep(Monitor.Monitor.plcRefreshInterval);
  1146. }
  1147. });
  1148. }
  1149. public static void Start()
  1150. {
  1151. for (int i = 0; i < Monitor.Monitor.plcTerminalCount; i++)
  1152. {
  1153. lockList.Add(new object());
  1154. }
  1155. ParkProcess();
  1156. FetchProcess();
  1157. }
  1158. public static void Stop()
  1159. {
  1160. isClosing = true;
  1161. }
  1162. public class FetchInfo
  1163. {
  1164. public string license;
  1165. public int parkingRecordsID;
  1166. public int remoteParkingRecordsID;
  1167. public int fee;
  1168. public int receiptNum;
  1169. public FetchInfo(string license, int parkingRecordsID, int remoteParkingRecordsID, int fee, int receiptNum)
  1170. {
  1171. this.license = license;
  1172. this.parkingRecordsID = parkingRecordsID;
  1173. this.remoteParkingRecordsID = remoteParkingRecordsID;
  1174. this.fee = fee;
  1175. this.receiptNum = receiptNum;
  1176. }
  1177. }
  1178. }
  1179. }