Terminal.cs 55 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232
  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<bool> lockList = new List<bool>();
  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 && 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 = "";
  413. //判断之前是否已拍摄号牌
  414. if (!idLicMap.ContainsKey(terminalInfo[i].terminalID))
  415. {
  416. license = Monitor.Monitor.numMachineLinker.GetLicensePlate(terminalInfo[i].terminalID);
  417. Monitor.Monitor.SetNotification("启动" + terminalInfo[i].terminalID + "号号牌机,号牌:" + license);
  418. }
  419. else
  420. {
  421. idLicMap.TryGetValue(terminalInfo[i].terminalID, out license);
  422. }
  423. //未获得号牌,告知PLC终止,告诉终端提示用户重新操作
  424. if (license == "")
  425. {
  426. MainBlockStru mb = new MainBlockStru
  427. {
  428. licenseReceived = (short)2
  429. };
  430. Monitor.Monitor.PLC.WriteToPLC(mb, PLCDataType.central);
  431. TerminalStru ts = new TerminalStru
  432. {
  433. terminalID = (short)terminalInfo[i].terminalID,
  434. paymentStatus = -1,
  435. parkingFee = -1,
  436. userType = -1,
  437. licVerification = (short)2
  438. };
  439. Monitor.Monitor.PLC.WriteToPLC(ts, PLCDataType.central);
  440. Log.WriteLog(LogType.process, LogFile.ERROR, "未获得号牌");
  441. }
  442. else
  443. {
  444. //记录或更新当前号牌
  445. lock (idLicMap)
  446. {
  447. if (idLicMap.ContainsKey(terminalInfo[i].terminalID) && idLicMap[terminalInfo[i].terminalID] != license)
  448. {
  449. idLicMap[terminalInfo[i].terminalID] = license;
  450. }
  451. else
  452. {
  453. idLicMap.Add(terminalInfo[i].terminalID, license);
  454. }
  455. }
  456. Log.WriteLog(LogType.process, LogFile.ERROR, "号牌" + license + "已记录");
  457. TerminalStru ts = new TerminalStru
  458. {
  459. terminalID = (short)terminalInfo[i].terminalID,
  460. paymentStatus = -1,
  461. parkingFee = -1,
  462. userType = -1
  463. };
  464. //注册用户
  465. if (term.btnStatus == (short)2)
  466. {
  467. int userID = term.licenseCodeA;
  468. string userLicense = GetLicenseFromTerm(term);
  469. //与云端数据比对
  470. ValidateUserInfo(ts, userID, userLicense, out numReceivedStatus);
  471. if (numReceivedStatus == 2)
  472. {
  473. idLicMap.Remove(terminalInfo[i].terminalID);
  474. }
  475. }
  476. //非注册用户
  477. else if (term.btnStatus == (short)1)
  478. {
  479. numReceivedStatus = 1;
  480. ts.licVerification = 1;
  481. Monitor.Monitor.PLC.WriteToPLC(ts, PLCDataType.central);
  482. }
  483. //无论是否注册,皆告知PLC,已获取号牌或比对异常、终止流程
  484. MainBlockStru mb = new MainBlockStru
  485. {
  486. licenseReceived = (short)numReceivedStatus
  487. };
  488. Monitor.Monitor.PLC.WriteToPLC(mb, PLCDataType.central);
  489. //号牌获取结果被清零才跳出
  490. Monitor.Monitor.SetNotification("已写入号牌获取结果,等待号牌机启动指令清零");
  491. }
  492. while (term.numMachineLaunch != 0)
  493. {
  494. Thread.Sleep(1000);
  495. }
  496. Monitor.Monitor.SetNotification("号牌机启动指令已被清零");
  497. }
  498. }
  499. }
  500. }
  501. #endregion
  502. //private static void ParkNumSubProcess()
  503. //{
  504. //}
  505. /// <summary>
  506. /// 停车流程,收到PLC停车完成信号后操作过程
  507. /// </summary>
  508. private static void ParkCompleteSubProcess()
  509. {
  510. int processAttrib = Monitor.Monitor.mainBlockInfo.parkingRunning;
  511. //int processCompleted = Monitor.Monitor.mainBlockInfo.processCompleted;
  512. int currentTerm = Monitor.Monitor.mainBlockInfo.terminalID;
  513. int parkingSpaceID = 0;
  514. if (processAttrib == 1)
  515. {
  516. TerminalStru term;
  517. string license;
  518. //等待完成信号
  519. while (Monitor.Monitor.mainBlockInfo.processCompleted != 1)
  520. {
  521. Thread.Sleep(200);
  522. if (Monitor.Monitor.mainBlockInfo.processStopped == 1)
  523. return;
  524. Thread.Sleep(200);
  525. }
  526. //找到终端号,判断是否注册用户
  527. //拿到号牌
  528. if (/*terminalInfo[i].terminalID == currentTerm && */idLicMap.TryGetValue(currentTerm, out license) && license != "")
  529. {
  530. term = terminalInfo[currentTerm - 1];
  531. Thread.Sleep(1500);
  532. //找到停车位置
  533. for (int s = 0; s < Monitor.Monitor.parkingSpaceInfo.Count; s++)
  534. {
  535. Console.WriteLine(Monitor.Monitor.parkingSpaceInfo[s].receiptNum + "," + term.receiptNum);
  536. if (Monitor.Monitor.parkingSpaceInfo[s].receiptNum == term.receiptNum)
  537. {
  538. parkingSpaceID = Monitor.Monitor.parkingSpaceInfo[s].parkingSpace;
  539. break;
  540. }
  541. }
  542. //无车位信息则跳出当前循环
  543. if (parkingSpaceID == 0 || term.receiptNum == 0)
  544. {
  545. try { idLicMap.Remove(currentTerm); } catch { }
  546. Monitor.Monitor.SetNotification("无车位或凭证号");
  547. return;
  548. }
  549. UpdateVehicle(license, 0, 0, true, false, 0);
  550. UpdateVehicle(license, 0, 0, true, true, 0);
  551. //插入停车记录
  552. string parkingRecordsSql = "";
  553. if (term.licenseCodeA != 0)
  554. {
  555. parkingRecordsSql = "INSERT INTO parkingrecords (userID, numberPlate,parkingSpaceID,garageID,parkingRecordsState,realParkTime,receiptNum,parkingPrice)" +
  556. "values ('" + term.licenseCodeA + "','" + license + "','" + parkingSpaceID + "','" + Monitor.Monitor.garageID + "',3,'" + DateTime.Now.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss") + "','" + term.receiptNum + "',NULL);";
  557. }
  558. else
  559. {
  560. parkingRecordsSql = "INSERT INTO parkingrecords (userID, numberPlate,parkingSpaceID,garageID,parkingRecordsState,realParkTime,receiptNum,parkingPrice)" +
  561. "values ('" + 1 + "','" + license + "','" + parkingSpaceID + "','" + Monitor.Monitor.garageID + "',3,'" + DateTime.Now.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss") + "','" + term.receiptNum + "',NULL);";
  562. }
  563. List<string> list = new List<string>();
  564. list.Add(parkingRecordsSql);
  565. Monitor.Monitor.localDBOper.Insert(list);
  566. Monitor.Monitor.remoteDBOper.Insert(list);
  567. Log.WriteLog(LogType.process, LogFile.INFO, "停车记录已插入," + license + "停在" + parkingSpaceID + ",凭证号:" + term.receiptNum);
  568. Monitor.Monitor.SetNotification("停车记录已插入");
  569. ////注册用户记录插入云端
  570. //if (term.btnStatus == 0)
  571. //{
  572. //Monitor.Monitor.remoteDBOper.Insert(list);
  573. //}
  574. //查询记录ID号
  575. string findRecordSql = "select parkingRecordsID from parkingrecords where receiptNum = " + term.receiptNum + ";";
  576. int parkingRecordsID = 0;
  577. int remoteParkingRecordsID = 0;
  578. QueryParkingRecordsID(findRecordSql, out parkingRecordsID, false);
  579. QueryParkingRecordsID(findRecordSql, out remoteParkingRecordsID, true);
  580. //更新本地车辆表
  581. if (parkingRecordsID != 0)
  582. {
  583. UpdateVehicle(license, 1, parkingRecordsID, true, false, parkingSpaceID);
  584. }
  585. if (remoteParkingRecordsID != 0)
  586. {
  587. UpdateVehicle(license, 1, remoteParkingRecordsID, true, true, parkingSpaceID);
  588. }
  589. Log.WriteLog(LogType.process, LogFile.INFO, "停车记录表已更新");
  590. //更新本地车位
  591. UpdateAllParkingSpace();
  592. //Monitor.Monitor.AddNotification("停车数据库已更新,等待流程结束状态清零。");
  593. //while (Monitor.Monitor.mainBlockInfo.processCompleted != 0)
  594. //{
  595. // Thread.Sleep(1000);
  596. //}
  597. //中控清除车牌、凭证号、号牌验证等信息
  598. ClearTerminal(term.terminalID);
  599. try { idLicMap.Remove(currentTerm); } catch { }
  600. Monitor.Monitor.SetNotification(license + " 数据库已更新,停车流程结束");
  601. }
  602. }
  603. }
  604. /// <summary>
  605. /// 预约车辆检测
  606. /// </summary>
  607. private static void ReservedCarCheck()
  608. {
  609. if (lockList.Count != terminalInfo.Count)
  610. {
  611. lockList.Clear();
  612. for (int i = 0; i < terminalInfo.Count; i++)
  613. {
  614. lockList.Add(false);
  615. }
  616. }
  617. //找到停车终端,且有地感无按钮数据
  618. for (int i = 0; i < terminalInfo.Count; i++)
  619. {
  620. //Console.WriteLine(i);
  621. if (terminalInfo[i].terminalStatus == 1 && terminalInfo[i].groundStatus == 1 && terminalInfo[i].btnStatus == 0 && !lockList[i])
  622. {
  623. Action<int> reserveAction = new Action<int>(ReservedOper);
  624. reserveAction(i);
  625. }
  626. }
  627. }
  628. private static void ReservedOper(int index)
  629. {
  630. Task.Factory.StartNew(() =>
  631. {
  632. lockList[index] = true;
  633. string license = "";
  634. int countdown = 2;
  635. short registered = 4;
  636. while (license == "" && countdown-- > 0)
  637. {
  638. license = Monitor.Monitor.numMachineLinker.GetLicensePlate(terminalInfo[index].terminalID);
  639. }
  640. if (license != "")
  641. {
  642. //map中加入或更新号牌,供完成时写入数据库用
  643. if (idLicMap.ContainsKey(terminalInfo[index].terminalID))
  644. {
  645. idLicMap[terminalInfo[index].terminalID] = license;
  646. }
  647. else
  648. {
  649. idLicMap.Add(terminalInfo[index].terminalID, license);
  650. }
  651. if (Monitor.Monitor.webServer.ReservedCarCheck(license))
  652. {
  653. registered = 3;
  654. }
  655. #region 通过数据库查询是否预约车,方法待定
  656. //int vehicleState = -1;
  657. //string vehicleStateCheckSql = "select vehiclepParkState from vehicle where numberPlate = '" + license + "';";
  658. //MySqlDataReader reader = Monitor.Monitor.localDBOper.Query(vehicleStateCheckSql);
  659. //if (reader != null)
  660. //{
  661. // try
  662. // {
  663. // if (reader.Read())
  664. // {
  665. // vehicleState = reader.GetInt32("vehiclepParkState");
  666. // }
  667. // }
  668. // catch (Exception e) { Log.WriteLog(LogType.process, LogFile.ERROR, "预约检测,查询车辆状态异常"); ; Console.WriteLine(e.Message); };
  669. // try
  670. // {
  671. // reader.Close();
  672. // reader.Dispose();
  673. // }
  674. // catch { }
  675. //}
  676. //已预约车辆入场
  677. //if (vehicleState == 4)
  678. //{
  679. // registered = 3;
  680. //}
  681. #endregion
  682. TerminalStru ts = new TerminalStru
  683. {
  684. terminalID = terminalInfo[index].terminalID,
  685. paymentStatus = (short)-1,
  686. btnStatus = registered,
  687. cmd = (short)-1,
  688. licenseCodeA = -1,
  689. licenseCodeB = -1,
  690. licenseCodeC = -1,
  691. licenseCodeD = -1,
  692. receiptNum = -1
  693. };
  694. Monitor.Monitor.PLC.WriteToPLC(ts, PLCDataType.terminal);
  695. Thread.Sleep(1000);
  696. }
  697. else
  698. {
  699. Thread.Sleep(500);
  700. }
  701. lockList[index] = false;
  702. });
  703. }
  704. /// <summary>
  705. /// 停车相关操作
  706. /// 0.观测到地感信号,且按钮状态不为3,则启动号牌机获取号牌,并判断是否预约车
  707. /// 1.读取到号牌机启动指令,启动号牌机并根据是否注册用户进行操作
  708. /// 非注册拿到号牌后记录并告知plc
  709. /// 注册用户,核对号牌与用户关联信息
  710. /// 2.停车流程结束,写数据库
  711. /// </summary>
  712. ///
  713. private static void ParkProcess()
  714. {
  715. Task.Factory.StartNew(() =>
  716. {
  717. while (!isClosing)
  718. {
  719. ParkNumSubProcess();
  720. Thread.Sleep(Monitor.Monitor.plcRefreshInterval * 5);
  721. }
  722. });
  723. Task.Factory.StartNew(() =>
  724. {
  725. while (!isClosing)
  726. {
  727. ParkCompleteSubProcess();
  728. Thread.Sleep(Monitor.Monitor.plcRefreshInterval * 5);
  729. }
  730. });
  731. Task.Factory.StartNew(() =>
  732. {
  733. while (!isClosing)
  734. {
  735. ReservedCarCheck();
  736. Thread.Sleep(Monitor.Monitor.plcRefreshInterval * 5);
  737. }
  738. });
  739. }
  740. /// <summary>
  741. /// 根据凭证号查询停车记录
  742. /// </summary>
  743. /// <param name="receipt"></param>
  744. /// <param name="recordID"></param>
  745. /// <param name="userID"></param>
  746. /// <param name="license"></param>
  747. /// <param name="realParkTime"></param>
  748. private static bool FindLocalParkingRecord(int receipt, out int recordID, out int userID, out string license, out string realParkTime)
  749. {
  750. recordID = 0;
  751. userID = 0;
  752. license = "";
  753. realParkTime = "";
  754. bool result = false;
  755. string parkRecordsSql = "select parkingRecordsID,userID,numberPlate,realParkTime from parkingrecords where receiptNum = " + receipt + ";";
  756. MySqlDataReader reader = Monitor.Monitor.localDBOper.Query(parkRecordsSql);
  757. try
  758. {
  759. if (reader != null && reader.Read())
  760. {
  761. object[] receiver = new object[4];
  762. reader.GetValues(receiver);
  763. recordID = (int)receiver[0];
  764. userID = (int)receiver[1];
  765. license = (string)receiver[2];
  766. realParkTime = (string)receiver[3];
  767. result = true;
  768. }
  769. else
  770. {
  771. Log.WriteLog(LogType.process, LogFile.ERROR, "根据凭证号查询停车记录失败");
  772. Monitor.Monitor.SetNotification("取车流程, 根据凭证号查询停车记录失败");
  773. result = false;
  774. }
  775. //if (reader != null)
  776. //{
  777. // reader.Close();
  778. // reader.Dispose();
  779. //}
  780. }
  781. catch (Exception e) { Log.WriteLog(LogType.process, LogFile.ERROR, "根据凭证号查询停车记录失败"); Console.WriteLine(e.Message); result = false; }
  782. try
  783. {
  784. if (reader != null)
  785. {
  786. reader.Close();
  787. reader.Dispose();
  788. }
  789. }
  790. catch { }
  791. Log.WriteLog(LogType.process, LogFile.INFO, "根据凭证号查询停车记录成功");
  792. return result;
  793. }
  794. private static bool FindRemoteParkingRecord(int receipt, out int recordID)
  795. {
  796. recordID = 0;
  797. bool result = false;
  798. string remoteParkRecordsSql = "select parkingRecordsID from parkingrecords where receiptNum = " + receipt + ";";
  799. MySqlDataReader reader = Monitor.Monitor.remoteDBOper.Query(remoteParkRecordsSql);
  800. try
  801. {
  802. if (reader != null && reader.Read())
  803. {
  804. object[] receiver = new object[1];
  805. reader.GetValues(receiver);
  806. recordID = (int)receiver[0];
  807. result = true;
  808. }
  809. }
  810. catch (Exception e) { Console.WriteLine(e.Message); result = false; }
  811. try
  812. {
  813. if (reader != null)
  814. {
  815. reader.Close();
  816. reader.Dispose();
  817. }
  818. }
  819. catch (Exception e) { Console.WriteLine(e.Message); result = false; }
  820. return result;
  821. }
  822. /// <summary>
  823. /// 根据号牌获取本地与远端用户VIP月卡及预约信息
  824. /// </summary>
  825. /// <param name="license"></param>
  826. /// <param name="orderRecordsID"></param>
  827. /// <param name="monthCardType"></param>
  828. /// <param name="monthCardTimeLength"></param>
  829. /// <param name="orderTimeLength"></param>
  830. /// <returns></returns>
  831. private static bool FindVipInfo(string license, ref int orderRecordsID, ref int monthCardType, ref TimeSpan monthCardTimeLength, ref TimeSpan orderTimeLength)
  832. {
  833. bool result = true;
  834. string monthCardTime = "";
  835. //本地VIP信息
  836. string vipInfoSql = "select orderRecordsID,monthCardType,monthCardTime from vehicle where numberPlate = '" + license + "';";
  837. MySqlDataReader reader = null;
  838. try
  839. {
  840. reader = Monitor.Monitor.localDBOper.Query(vipInfoSql);
  841. if (reader != null && reader.Read())
  842. {
  843. object[] receiver = new object[3];
  844. reader.GetValues(receiver);
  845. Console.WriteLine(receiver[2].GetType());
  846. if (!receiver[0].GetType().Equals(typeof(DBNull)))
  847. {
  848. orderRecordsID = (int)receiver[0];
  849. }
  850. if (!receiver[1].GetType().Equals(typeof(DBNull)))
  851. {
  852. monthCardType = (int)(UInt32)receiver[1];
  853. }
  854. if (!receiver[2].GetType().Equals(typeof(DBNull)))
  855. {
  856. monthCardTime = (string)receiver[2];
  857. }
  858. //orderRecordsID = (Int32)receiver[0];
  859. //monthCardType = (Int32)receiver[1];
  860. //monthCardTime = (string)receiver[2];
  861. monthCardTimeLength = DateTime.Parse(monthCardTime) - DateTime.Now;
  862. if (monthCardTimeLength.TotalHours <= 0)
  863. {
  864. monthCardType = 0;
  865. }
  866. Log.WriteLog(LogType.process, LogFile.INFO, "已获取本地预约与月卡信息");
  867. }
  868. }
  869. catch (Exception e) { Console.WriteLine(e.Message); result = false; }
  870. try
  871. {
  872. if (reader != null)
  873. {
  874. reader.Close();
  875. reader.Dispose();
  876. }
  877. }
  878. catch (Exception e) { Console.WriteLine(e.Message); result = false; }
  879. //云端VIP信息
  880. try
  881. {
  882. reader = Monitor.Monitor.remoteDBOper.Query(vipInfoSql);
  883. if (reader != null && reader.Read())
  884. {
  885. object[] receiver = new object[3];
  886. reader.GetValues(receiver);
  887. int cardType = (int)(UInt32)receiver[1];
  888. string CardTime = (string)receiver[2];
  889. TimeSpan t = DateTime.Parse(CardTime) - DateTime.Now;
  890. //云端
  891. if (t.TotalHours > 0 && cardType > monthCardType)
  892. {
  893. monthCardType = cardType;
  894. monthCardTimeLength = t;
  895. }
  896. Log.WriteLog(LogType.process, LogFile.INFO, "已获取云端预约与月卡信息");
  897. }
  898. }
  899. catch (Exception e) { Console.WriteLine(e.Message); result = false; }
  900. try
  901. {
  902. if (reader != null)
  903. {
  904. reader.Close();
  905. reader.Dispose();
  906. }
  907. }
  908. catch (Exception e) { Console.WriteLine(e.Message); result = false; }
  909. //有预约记录,判断记录有效性,有效则获取预约时长
  910. if (orderRecordsID != 0)
  911. {
  912. //修改orderTimeLength
  913. }
  914. return result;
  915. }
  916. /// <summary>
  917. /// 预约与停车费用计算
  918. /// </summary>
  919. /// <param name="scheme"></param>
  920. /// <param name="parkTime"></param>
  921. /// <param name="orderTimeLength"></param>
  922. /// <returns></returns>
  923. private static int FeeCalc(PaymentScheme scheme, DateTime parkTime, TimeSpan orderTimeLength)
  924. {
  925. try
  926. {
  927. int orderFee = scheme.bookCharge * (int)orderTimeLength.TotalHours;
  928. int parkFee = 0;
  929. int hours = (int)(DateTime.Now - parkTime).TotalHours;
  930. switch (scheme.schemeType)
  931. {
  932. //按时计费
  933. case 1:
  934. if (hours > scheme.firstChargeTime)
  935. {
  936. parkFee = Math.Min(scheme.firstCharge + scheme.intervalCharge * hours / scheme.chargeInterval, scheme.upperBound);
  937. }
  938. else if (hours > scheme.firstChargeTime - scheme.freeTime)
  939. {
  940. parkFee = scheme.firstCharge;
  941. }
  942. else
  943. {
  944. parkFee = 0;
  945. }
  946. break;
  947. //按次计费
  948. case 2:
  949. int overnightCount = hours / 24;
  950. parkFee = scheme.eachCharge + overnightCount * scheme.overnightCharge;
  951. break;
  952. //按时间段计费
  953. case 3:
  954. TimeSpan currentTimeOfDay = DateTime.Now.TimeOfDay;
  955. TimeSpan parkTimeOfDay = parkTime.TimeOfDay;
  956. TimeSpan startTimeOfDay = DateTime.Parse(scheme.startChargeTime).TimeOfDay;
  957. TimeSpan endTimeOfDay = DateTime.Parse(scheme.endChargeTime).TimeOfDay;
  958. double countingHoursOfDay = endTimeOfDay.TotalHours - startTimeOfDay.TotalHours;
  959. int days = (int)((DateTime.Now - parkTime).TotalHours - currentTimeOfDay.TotalHours + parkTimeOfDay.TotalHours);
  960. int previousOffset = (int)(-(Math.Max(0, parkTimeOfDay.TotalHours - startTimeOfDay.TotalHours)));
  961. int currentOffset = (int)Math.Min((currentTimeOfDay.TotalHours - startTimeOfDay.TotalHours), countingHoursOfDay);
  962. int peakTimeLength = days * (int)countingHoursOfDay + previousOffset + currentOffset;
  963. parkFee = peakTimeLength * scheme.chargeStandard + ((int)((DateTime.Now - parkTime).TotalHours) - peakTimeLength) * scheme.intervalCharge;
  964. break;
  965. }
  966. Log.WriteLog(LogType.process, LogFile.INFO, "停车费用" + parkFee);
  967. return parkFee;
  968. }
  969. catch (Exception e) { Console.WriteLine("费用计算异常"); return -1; }
  970. }
  971. /// <summary>
  972. /// 取车计费子操作
  973. /// </summary>
  974. private static void FetchFeeCalcSubProcess()
  975. {
  976. int receiptNum = 0;
  977. int termIndex = -1;
  978. bool failed = false;
  979. TerminalStru ts = new TerminalStru();
  980. for (int i = 0; i < terminalInfo.Count; i++)
  981. {
  982. ts = terminalInfo[i];
  983. termIndex = ts.terminalID;
  984. receiptNum = ts.receiptNum;
  985. //取车状态、凭证号不为空,查询数据库计费
  986. //Console.WriteLine((termIndex != -1) + "," + (termUsedMap.Count >= termIndex) + "," + termUsedMap.TryGetValue(termIndex, out bool valuee) + "," + (!valuee) + "," + (fetchState == 1) + "," + (receiptNum != 0));
  987. if (termIndex != -1 && termUsedMap.Count >= termIndex && termUsedMap.TryGetValue(termIndex, out bool value) && !value && ts.cmd == 2 && receiptNum != 0)
  988. {
  989. //fetchState = Monitor.Monitor.mainBlockInfo.fetchingRunning;
  990. Monitor.Monitor.SetNotification(termIndex + "号终端准备计算费用");
  991. termUsedMap[termIndex] = true;
  992. Console.WriteLine("终端编号" + termIndex);
  993. int parkingRecordsID = 0;
  994. int remoteParkingRecordsID = 0;
  995. int userID = 0;
  996. string license = "";
  997. string realParkTime = "";
  998. //1.根据凭证号查询停车记录
  999. if (!FindLocalParkingRecord(receiptNum, out parkingRecordsID, out userID, out license, out realParkTime))
  1000. {
  1001. failed = true;
  1002. //return;
  1003. }
  1004. else
  1005. {
  1006. FindRemoteParkingRecord(receiptNum, out remoteParkingRecordsID);
  1007. }
  1008. //本地存在号牌,后续操作
  1009. //2.根据号牌查询车辆月卡信息与预约记录
  1010. int orderRecordsID = 0;
  1011. int monthCardType = -1;
  1012. string monthCardTime = "";
  1013. TimeSpan monthCardTimeLength = new TimeSpan(0);
  1014. TimeSpan orderTimeLength = new TimeSpan(0);
  1015. if (license != "")
  1016. {
  1017. FindVipInfo(license, ref orderRecordsID, ref monthCardType, ref monthCardTimeLength, ref orderTimeLength);
  1018. }
  1019. //3.获取停车时刻,根据用户类型计费发送给PLC,暂认为无预约
  1020. DateTime parkTime = DateTime.Parse(realParkTime);
  1021. DateTime currentTime = DateTime.Now;
  1022. int fee = 32767;
  1023. if (failed) { monthCardType = -1; }
  1024. if (PaymentScheme.ins != null)
  1025. {
  1026. if (monthCardTimeLength.TotalHours > 0)
  1027. {
  1028. fee = 0;
  1029. }
  1030. else if (failed)
  1031. {
  1032. fee = 0;
  1033. }
  1034. else
  1035. {
  1036. fee = FeeCalc(PaymentScheme.ins, parkTime, orderTimeLength);
  1037. }
  1038. try
  1039. {
  1040. if (Monitor.Monitor.PLC != null)
  1041. {
  1042. TerminalStru FeeMsg = new TerminalStru();
  1043. FeeMsg.terminalID = (short)termIndex;
  1044. FeeMsg.paymentStatus = (short)-1;
  1045. FeeMsg.licVerification = (short)-1;
  1046. FeeMsg.parkingFee = (short)fee;
  1047. FeeMsg.userType = (short)(monthCardType + 1);
  1048. Console.WriteLine(FeeMsg);
  1049. Monitor.Monitor.PLC.WriteToPLC(FeeMsg, PLCDataType.central);
  1050. Log.WriteLog(LogType.process, LogFile.INFO, "停车费用已发送至PLC");
  1051. }
  1052. }
  1053. catch { Console.WriteLine("error"); }
  1054. }
  1055. Monitor.Monitor.SetNotification("用户类型:" + monthCardType + ",费用:" + fee + ",等待凭证号被清除且流程结束后更新车辆状态");
  1056. FetchInfo fetchInfo = new FetchInfo(license, parkingRecordsID, remoteParkingRecordsID, fee, receiptNum);
  1057. if (!fetchMap.ContainsKey(termIndex))
  1058. fetchMap.Add(termIndex, fetchInfo);
  1059. else
  1060. fetchMap[termIndex] = fetchInfo;
  1061. }
  1062. }
  1063. }
  1064. private static void FetchCompleteProcess()
  1065. {
  1066. int fetchState = Monitor.Monitor.mainBlockInfo.fetchingRunning;
  1067. int termIndex = -1;
  1068. TerminalStru ts = new TerminalStru();
  1069. if (fetchState == 1)
  1070. {
  1071. //找到当前取车终端
  1072. for (int i = 0; i < terminalInfo.Count; i++)
  1073. {
  1074. if (terminalInfo[i].terminalID == Monitor.Monitor.mainBlockInfo.terminalID)
  1075. {
  1076. ts = terminalInfo[i];
  1077. termIndex = ts.terminalID;
  1078. break;
  1079. }
  1080. }
  1081. //4.等待终端获得收费完成信号且将凭证号清除后,清除收费完成信号并将信息写入数据库
  1082. int count = 0;
  1083. while (!isClosing && termIndex != -1)
  1084. {
  1085. if (Monitor.Monitor.mainBlockInfo.processCompleted == 1)
  1086. {
  1087. while (terminalInfo[termIndex - 1].receiptNum != 0)
  1088. {
  1089. count++;
  1090. if (count == 1)
  1091. Monitor.Monitor.SetNotification("等待凭证号清除");
  1092. }
  1093. int paymentStatus = 0;
  1094. for (int i = 0; i < terminalInfo.Count; i++)
  1095. {
  1096. if (terminalInfo[i].terminalID == Monitor.Monitor.mainBlockInfo.terminalID)
  1097. {
  1098. paymentStatus = terminalInfo[i].paymentStatus;
  1099. break;
  1100. }
  1101. }
  1102. Log.WriteLog(LogType.process, LogFile.INFO, "检测到凭证号已被清除");
  1103. FetchInfo fi = null;
  1104. if (fetchMap.ContainsKey(termIndex))
  1105. {
  1106. fi = fetchMap[termIndex];
  1107. }
  1108. else
  1109. {
  1110. Monitor.Monitor.SetNotification("未查询到该取车终端存在计费操作");
  1111. return;
  1112. }
  1113. //TerminalStru fetchReset = new TerminalStru
  1114. //{
  1115. // terminalID = (short)termIndex,
  1116. // paymentStatus = (short)0,
  1117. // licVerification = (short)0,
  1118. // parkingFee = (short)32767,
  1119. // userType = (short)0
  1120. //};
  1121. //Monitor.Monitor.PLC.WriteToPLC(fetchReset, PLCDataType.central);
  1122. ClearTerminal(termIndex);
  1123. //更新停车记录与车辆状态
  1124. string updateParkingRecordsSql = "update parkingrecords set parkingRecordsState = 6,realGetTime = '" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") +
  1125. "',parkingPrice = " + fi.fee + ",paymentStatus = " + paymentStatus + " where receiptNum = '" + fi.receiptNum + "';";
  1126. List<string> list = new List<string>();
  1127. list.Add(updateParkingRecordsSql);
  1128. lock (Monitor.Monitor.localDBOper)
  1129. {
  1130. Monitor.Monitor.localDBOper.UpdateTransaction(list);
  1131. UpdateVehicle(fi.license, 0, fi.parkingRecordsID, false, false, 0);
  1132. }
  1133. lock (Monitor.Monitor.remoteDBOper)
  1134. {
  1135. Monitor.Monitor.remoteDBOper.UpdateTransaction(list);
  1136. UpdateVehicle(fi.license, 0, fi.remoteParkingRecordsID, false, true, 0);
  1137. }
  1138. Monitor.Monitor.SetNotification(fi.license + " 取车流程结束");
  1139. break;
  1140. }
  1141. Thread.Sleep(1000);
  1142. }
  1143. termUsedMap[termIndex] = false;
  1144. fetchMap.Remove(termIndex);
  1145. }
  1146. }
  1147. /// <summary>
  1148. /// 取车相关操作
  1149. ///
  1150. /// </summary>
  1151. private static void FetchProcess()
  1152. {
  1153. Task.Factory.StartNew(() =>
  1154. {
  1155. while (!isClosing)
  1156. {
  1157. FetchFeeCalcSubProcess();
  1158. Thread.Sleep(Monitor.Monitor.plcRefreshInterval);
  1159. }
  1160. });
  1161. Task.Factory.StartNew(() =>
  1162. {
  1163. while (!isClosing)
  1164. {
  1165. FetchCompleteProcess();
  1166. Thread.Sleep(Monitor.Monitor.plcRefreshInterval);
  1167. }
  1168. });
  1169. }
  1170. public static void Start()
  1171. {
  1172. for (int i = 0; i < Monitor.Monitor.plcTerminalCount; i++)
  1173. {
  1174. lockList.Add(false);
  1175. }
  1176. ParkProcess();
  1177. FetchProcess();
  1178. }
  1179. public static void Stop()
  1180. {
  1181. isClosing = true;
  1182. }
  1183. public class FetchInfo
  1184. {
  1185. public string license;
  1186. public int parkingRecordsID;
  1187. public int remoteParkingRecordsID;
  1188. public int fee;
  1189. public int receiptNum;
  1190. public FetchInfo(string license, int parkingRecordsID, int remoteParkingRecordsID, int fee, int receiptNum)
  1191. {
  1192. this.license = license;
  1193. this.parkingRecordsID = parkingRecordsID;
  1194. this.remoteParkingRecordsID = remoteParkingRecordsID;
  1195. this.fee = fee;
  1196. this.receiptNum = receiptNum;
  1197. }
  1198. }
  1199. }
  1200. }