ClientFactory.java 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659
  1. package com.tokheim.client.itouch;
  2. import com.alibaba.fastjson.JSONArray;
  3. import com.alibaba.fastjson.JSONObject;
  4. import com.tokheim.client.manager.factory.AsyncFactory;
  5. import com.tokheim.client.manager.factory.SocketFactory;
  6. import com.tokheim.client.utils.ByteUtils;
  7. import com.tokheim.client.utils.JSONUtils;
  8. import lombok.extern.slf4j.Slf4j;
  9. import org.springframework.util.LinkedMultiValueMap;
  10. import org.springframework.util.MultiValueMap;
  11. import java.io.IOException;
  12. import java.io.InputStream;
  13. import java.io.OutputStream;
  14. import java.net.*;
  15. import java.util.*;
  16. import java.util.concurrent.ExecutorService;
  17. import java.util.concurrent.Executors;
  18. /**
  19. * @author xgm
  20. * @version 1.0
  21. * @date: Created in 9:42 2021/9/26
  22. * <p>
  23. * 多台ITouch操作
  24. */
  25. @Slf4j
  26. public class ClientFactory {
  27. // 创建固定数量的线程池
  28. private static ExecutorService executorService = null;
  29. private static ExecutorService reExecutorService = null;
  30. private static ExecutorService nozzleExecutorService = null;
  31. private static ExecutorService headerExecutorService = null;
  32. private String iTouchHost;
  33. private String iTouchPort;
  34. private String msg;
  35. private static List<String> nozzles = new ArrayList<>();
  36. private static List<String> nozzles2 = new ArrayList<>();
  37. private static String header = "02 01 01 00 02 60 00 09 02"; //枪配置信息头
  38. //private static String heartHeaderPackage = "02 01 01 00 02 60 00 0B 01"; //心跳头
  39. //private static String realTimePackage = "02 01 01 00 00 60 00 16 01"; //实时加油数据头
  40. //private static String oilHeaderPackage = "02 01 01 00 00 60 00 31 04";//加油交易记录头
  41. //private static String speechHeaderPackage = "02 01 01 00 00 60 00 08 01";//语音数据头
  42. private static boolean flag = true;
  43. public static Set<String> iTouchIps = new HashSet<>();
  44. private static Map<String, Socket> socketMap = new HashMap<>();
  45. private static Map<String, Boolean> flagMap = new HashMap<>();
  46. //private static TwoKeyMap<String, String, Socket> socketTwoKeyMap = new TwoKeyMap<>();
  47. // private static MultiValueMap<String, String> nozzleMap = new LinkedMultiValueMap<>();
  48. static {
  49. executorService = Executors.newFixedThreadPool(10);
  50. reExecutorService = Executors.newFixedThreadPool(10);
  51. nozzleExecutorService = Executors.newFixedThreadPool(10);
  52. headerExecutorService = Executors.newFixedThreadPool(10);
  53. //模拟油枪信息
  54. //nozzles.add("02 01 01 00 02 60 00 09 02 21 11 05 01 01 D3 01 00");
  55. //nozzles.add("02 01 01 00 02 60 00 09 02 23 11 05 01 03 D3 01 00");
  56. //模拟错误信息
  57. //nozzles2.add("103139322E3136382E312E353A3939313202010100006000080121140104150101103139322E3136382E312E353A3939313202010100006000080124140106150101103139322E3136382E312E353A3939313202010100006000080121140106150101103139322E3136382E312E353A3939313202010100006000080124140108150101103139322E3136382E312E353A3939313202010100006000080121140108150101103139322E3136382E312E353A39393132020101000260000B0100FF0720200928174252103139322E3136382E312E353A39393132020101000060001601242205060000064023050600000080240404000800000000000000103139322E3136382E312E353A39393132020101000060001601212205060000064023050600000080240404000800000000000000103139322E3136382E312E353A39393132020101000060001601242205060000116823050600000146240404000800000000000000103139322E3136382E312E353A39393132020101000060001601212205060000116823050600000146240404000800000000000000103139322E3136382E312E353A39393132020101000060001601242205060000170423050600000213240404000800000000000000103139322E3136382E312E353A393931320201010000600016012122050600001704230506000002132404040008");
  58. //nozzles2.add("00000000000000103139322E3136382E312E353A39393132020101000260000B0100FF0720200928174255103139322E3136382E312E353A39393132020101000060001601242205060000223223050600000279240404000800000000000000103139322E3136382E312E353A39393132020101000060001601212205060000223223050600000279240404000800000000000000103139322E3136382E312E353A39393132020101000060001601242205060000281623050600000352240404000800000000000000103139322E3136382E312E353A39393132020101000060001601212205060000281623050600000352240404000800000000000000103139322E3136382E312E353A39393132020101000060001601242205060000334423050600000418240404000800000000000000103139322E3136382E312E353A39393132020101000060001601212205060000334423050600000418240404000800000000000000103139322E3136382E312E353A39393132020101000260000B0100FF0720200928174258103139322E3136382E312E353A39393132020101000060001601242205060000388023050600000485240404000800000000000000103139322E3136382E312E353A39393132020101000060001601212205060000388023050600000485240404000800000000000000103139322E3136382E");
  59. }
  60. /**
  61. * 将字符串去掉0开发
  62. *
  63. * @param stationIp 油机Ip地址
  64. * @param iTouchPort 多媒体屏app的ip端口号
  65. * @param msg 油机发送过来的16进制字符串
  66. */
  67. public void setData(String stationIp, String iTouchPort, String msg) {
  68. try {
  69. /* if (iTouchIps.isEmpty()) {
  70. getConfigure(stationIp);
  71. }*/
  72. iTouchIps.clear();
  73. getConfigure(stationIp);
  74. this.iTouchPort = iTouchPort;
  75. this.msg = msg;
  76. //获取ITouch多媒体屏ip
  77. recursionMsg(msg); //枪信息
  78. sendData(msg);
  79. } catch (Exception e) {
  80. log.error("配置文件获取失败--" + e.getMessage());
  81. e.printStackTrace();
  82. }
  83. }
  84. /**
  85. * 油枪信息截取
  86. *
  87. * @param msg 多条油枪组成16进制字符串
  88. */
  89. public void recursionMsg(String msg) {
  90. if (msg.contains(header)) {
  91. String msg_front = msg.substring(msg.indexOf(header));
  92. //截取第一条枪配置信息
  93. String msg_end = msg_front.substring(50);
  94. String nozzleInfo = msg_front.substring(0, 50);
  95. if (!nozzles.contains(nozzleInfo)) {
  96. nozzles.add(nozzleInfo);
  97. }
  98. if (msg_end.contains(header)) {
  99. recursionMsg(msg_end);
  100. }
  101. }
  102. }
  103. /**
  104. * 判断后发送数据到多媒体屏app
  105. *
  106. * @param msg 16进制字符串
  107. */
  108. public void sendData(String msg) {
  109. for (String iTouchIp : iTouchIps) {
  110. Socket socket = socketMap.get(iTouchIp);
  111. if (socket == null) {
  112. executorService.submit(new Runnable() {
  113. @Override
  114. public void run() {
  115. send(iTouchIp);
  116. }
  117. });
  118. /*new Thread(new Runnable() {
  119. @Override
  120. public void run() {
  121. send(iTouchIp);
  122. }
  123. }).start();*/
  124. } else { //正常传输数据
  125. send(iTouchIp);
  126. }
  127. }
  128. }
  129. /* public void sendDataToITouch(String iTouchIp) {
  130. try {
  131. //TODO 将发送数据根据油枪号进行过滤发送
  132. if (msg.contains(realTimePackage)){ //实时加油
  133. //System.err.println("加油实时数据:" + msg);
  134. String substring = msg.substring(msg.indexOf(realTimePackage));
  135. String[] arrData = substring.split(" ");
  136. String[] gunNoArr = Arrays.copyOfRange(arrData, 9, 10);//枪号(1)
  137. String gunNo = "";
  138. for (int i = 0; i < gunNoArr.length; i++) {
  139. gunNo = String.valueOf(ByteUtils.hexToDecimal(gunNoArr[i]) - ByteUtils.hexToDecimal("20"));;
  140. }
  141. if (nozzleMap.containsKey(iTouchIp)){
  142. List<String> stringList = nozzleMap.get(iTouchIp);
  143. for (String nozzleNo : stringList) {
  144. if (nozzleNo.equals(gunNo)){
  145. System.err.println(iTouchIp + "--加油实时数据:" + msg);
  146. send(iTouchIp);
  147. }
  148. }
  149. }
  150. }
  151. if (msg.contains(oilHeaderPackage)){
  152. String substring = msg.substring(msg.indexOf(oilHeaderPackage));
  153. String[] arrData = substring.split(" ");
  154. String[] gunNoArr = Arrays.copyOfRange(arrData, 9, 10);//枪号(1)
  155. String gunNo = "";
  156. for (int i = 0; i < gunNoArr.length; i++) {
  157. gunNo = String.valueOf(ByteUtils.hexToDecimal(gunNoArr[i]) - ByteUtils.hexToDecimal("20"));;
  158. }
  159. if (nozzleMap.containsKey(iTouchIp)){
  160. List<String> stringList = nozzleMap.get(iTouchIp);
  161. for (String nozzleNo : stringList) {
  162. if (nozzleNo.equals(gunNo)){
  163. System.err.println(iTouchIp + "--加油记录数据:" + msg);
  164. send(iTouchIp);
  165. }
  166. }
  167. }
  168. }
  169. if (msg.contains(speechHeaderPackage)){
  170. String substring = msg.substring(msg.indexOf(speechHeaderPackage));
  171. String[] arrData = substring.split(" ");
  172. String[] gunNoArr = Arrays.copyOfRange(arrData, 9, 10);//枪号(1)
  173. String gunNo = "";
  174. for (int i = 0; i < gunNoArr.length; i++) {
  175. gunNo = String.valueOf(ByteUtils.hexToDecimal(gunNoArr[i]) - ByteUtils.hexToDecimal("20"));;
  176. }
  177. if (nozzleMap.containsKey(iTouchIp)){
  178. List<String> stringList = nozzleMap.get(iTouchIp);
  179. for (String nozzleNo : stringList) {
  180. if (nozzleNo.equals(gunNo)){
  181. System.err.println(iTouchIp + "--语音数据:" + msg);
  182. send(iTouchIp);
  183. }
  184. }
  185. }
  186. }
  187. send(iTouchIp);
  188. } catch (Exception e) {
  189. e.printStackTrace();
  190. }
  191. }*/
  192. /**
  193. * 发送数据到多媒体屏app
  194. *
  195. * @param iTouchIp 多媒体app的Ip地址
  196. */
  197. public void send(String iTouchIp) {
  198. try {
  199. Socket socket = socketMap.get(iTouchIp);
  200. if (socket == null) {
  201. socketMap.remove(iTouchIp);
  202. socket = new Socket();
  203. socket.connect(new InetSocketAddress(iTouchIp, Integer.valueOf(iTouchPort)), 2000);//超时时间为2秒
  204. socketMap.put(iTouchIp, socket);
  205. flagMap.put(iTouchIp, true);
  206. }
  207. if (socket.isClosed()) {
  208. socketMap.remove(iTouchIp);
  209. socket = new Socket();
  210. socket.connect(new InetSocketAddress(iTouchIp, Integer.valueOf(iTouchPort)), 2000);//超时时间为2秒
  211. socketMap.put(iTouchIp, socket);
  212. flagMap.put(iTouchIp, true);
  213. System.out.println(iTouchIp + "--socket 关闭...");
  214. log.info(iTouchIp + "--socket 关闭...");
  215. }
  216. Socket socketNew = socketMap.get(iTouchIp);
  217. if (socket.isConnected()) {
  218. OutputStream out = socketNew.getOutputStream();
  219. if (flag) sendHeartedData(iTouchIp);
  220. reData(iTouchIp);
  221. sendNozzleInfo(iTouchIp);
  222. //sendNozzleInfo2(iTouchIp);
  223. //if (msg.contains("01 01 02 01 00 40 00 13 01"))
  224. //System.err.println(iTouchIp + "--发送数据:" + msg);
  225. byte[] bytes = ByteUtils.hexToByteArray(msg);
  226. out.write(bytes);
  227. out.flush();
  228. } else {
  229. System.out.println(iTouchIp + "--socket服务端未启动......");
  230. log.info(iTouchIp + "--socket服务端未启动......");
  231. restartSocket(iTouchIp);
  232. }
  233. } catch (IOException e) {
  234. e.printStackTrace();
  235. if (e instanceof SocketTimeoutException) {
  236. System.err.println(iTouchIp + "--连接超时,正在重连....");
  237. log.error(iTouchIp + "--连接超时,正在重连....");
  238. startSocket(iTouchIp);
  239. } else if (e instanceof NoRouteToHostException) {
  240. System.err.println(iTouchIp + "--该地址不存在,请检查......");
  241. log.error(iTouchIp + "--该地址不存在,请检查......");
  242. stopSocket(iTouchIp);
  243. } else if (e instanceof ConnectException) {
  244. System.err.println(iTouchIp + "--连接异常或被拒绝,请检查.....");
  245. log.error(iTouchIp + "--连接异常或被拒绝,请检查.....");
  246. stopSocket(iTouchIp);
  247. } else if (e instanceof SocketException) {
  248. System.out.println(iTouchIp + "--服务端关闭,客户端关闭后重启......");
  249. log.error(iTouchIp + "--服务端关闭,客户端关闭后重启......");
  250. //stopSocket();
  251. restartSocket(iTouchIp);
  252. }
  253. }
  254. }
  255. /**
  256. * 重连多媒体app
  257. *
  258. * @param iTouchIp 多媒体app的Ip地址
  259. */
  260. public void restartSocket(String iTouchIp) {
  261. try {
  262. Socket socket = socketMap.get(iTouchIp);
  263. flagMap.put(iTouchIp, false);
  264. //每隔间2s向服务器请求一次以此检查服务器是否已经起来
  265. Thread.sleep(2000);
  266. log.info(iTouchIp + "--重连(ITouch)socket.......");
  267. System.out.println(iTouchIp + "--重连(ITouch)socket.......");
  268. if (socket == null) {
  269. socket = new Socket();
  270. socket.connect(new InetSocketAddress(iTouchIp, Integer.valueOf(iTouchPort)), 2000);//超时时间为2秒
  271. socketMap.put(iTouchIp, socket);
  272. flagMap.put(iTouchIp, true);
  273. } else {
  274. socket.close();
  275. }
  276. } catch (Exception e) {
  277. e.printStackTrace();
  278. } finally {
  279. Socket socket = socketMap.get(iTouchIp);
  280. if (socket == null) {
  281. restartSocket(iTouchIp);
  282. }
  283. }
  284. }
  285. /**
  286. * 监听多媒体app初始化是是否已启动
  287. *
  288. * @param iTouchIp 多媒体app的Ip地址
  289. */
  290. public void startSocket(String iTouchIp) {
  291. try {
  292. Socket socket = socketMap.get(iTouchIp);
  293. Thread.sleep(2000); //每隔两秒重新连接一次
  294. log.info(iTouchIp + "--两秒后重新链接....");
  295. System.out.println(iTouchIp + "--两秒后重新链接....");
  296. //创建socket客户端
  297. socket = new Socket();
  298. socket.connect(new InetSocketAddress(iTouchIp, Integer.valueOf(iTouchPort)), 2000);//超时时间为2秒
  299. flagMap.put(iTouchIp, true);
  300. sendData(msg);
  301. } catch (Exception e) {
  302. e.printStackTrace();
  303. if (e instanceof SocketTimeoutException) {
  304. socketMap.remove(iTouchIp);
  305. startSocket(iTouchIp);
  306. }
  307. }
  308. }
  309. /**
  310. * 停止与多媒体app连接
  311. *
  312. * @param iTouchIp 多媒体app的Ip地址
  313. */
  314. public void stopSocket(String iTouchIp) {
  315. try {
  316. Socket socket = socketMap.get(iTouchIp);
  317. flagMap.put(iTouchIp, false);
  318. socket.close();
  319. } catch (Exception e) {
  320. e.printStackTrace();
  321. }
  322. }
  323. /**
  324. * 发送心跳到多媒体app
  325. *
  326. * @param iTouchIp 多媒体app的Ip地址
  327. */
  328. public void sendHeartedData(String iTouchIp) {
  329. /*new Thread(new Runnable() {
  330. @Override
  331. public void run() {
  332. try {
  333. Thread.sleep(10000);
  334. Socket socket = socketMap.get(iTouchIp);
  335. if (socket != null && !socket.isClosed()) {
  336. OutputStream out = socket.getOutputStream();
  337. out.write(0);
  338. out.flush();
  339. }
  340. } catch (Exception e) {
  341. socketMap.remove(iTouchIp);
  342. flag = false;
  343. restartSocket(iTouchIp);
  344. e.printStackTrace();
  345. } finally {
  346. if (flag) {
  347. sendHeartedData(iTouchIp);
  348. }
  349. }
  350. }
  351. }).start();*/
  352. headerExecutorService.submit(new Runnable() {
  353. @Override
  354. public void run() {
  355. try {
  356. Thread.sleep(10000);
  357. Socket socket = socketMap.get(iTouchIp);
  358. if (socket != null && !socket.isClosed()) {
  359. OutputStream out = socket.getOutputStream();
  360. out.write(0);
  361. out.flush();
  362. }
  363. } catch (Exception e) {
  364. socketMap.remove(iTouchIp);
  365. flag = false;
  366. restartSocket(iTouchIp);
  367. e.printStackTrace();
  368. } finally {
  369. if (flag) {
  370. sendHeartedData(iTouchIp);
  371. }
  372. }
  373. }
  374. });
  375. }
  376. /**
  377. *接收多媒体app发送信息
  378. *
  379. * @param iTouchIp 多媒体app的Ip地址
  380. */
  381. public void reData(String iTouchIp) {
  382. /* new Thread(new Runnable() {
  383. @Override
  384. public void run() {
  385. try {
  386. Socket socket = socketMap.get(iTouchIp);
  387. if (socket != null && !socket.isClosed()) {
  388. byte[] buf = new byte[1024];
  389. while (true) {
  390. InputStream in = socket.getInputStream();
  391. if (in.available() > 0) {
  392. int len = in.read(buf);
  393. byte[] real = new byte[len];
  394. //解析数据
  395. for (int i = 0; i < real.length; i++) {
  396. real[i] = buf[i];
  397. }
  398. String[] strings = ByteUtils.bytesToHexStrings(real);
  399. //log.info("接收油机数据--" + Arrays.toString(strings));
  400. String msg = Arrays.toString(strings).replaceAll(",", "");
  401. msg = msg.substring(1, msg.length() - 1);
  402. if (!msg.contains("02 01 01 00 02 60 00 0B 01 00 FF")) {
  403. //System.err.println(iTouchIp + "--ITouch信息---" + msg);
  404. //log.info(iTouchIp + "--ITouch信息---" + msg);
  405. AsyncFactory.out.write(ByteUtils.hexToByteArray(msg));
  406. } else {
  407. //System.err.println("ITouch心跳信息---" + msg);
  408. }
  409. }
  410. }
  411. }
  412. } catch (Exception e) {
  413. e.printStackTrace();
  414. }
  415. }
  416. }).start();*/
  417. reExecutorService.submit(new Runnable() {
  418. @Override
  419. public void run() {
  420. try {
  421. Socket socket = socketMap.get(iTouchIp);
  422. if (socket != null && !socket.isClosed()) {
  423. byte[] buf = new byte[1024];
  424. while (true) {
  425. InputStream in = socket.getInputStream();
  426. if (in.available() > 0) {
  427. int len = in.read(buf);
  428. byte[] real = new byte[len];
  429. //解析数据
  430. for (int i = 0; i < real.length; i++) {
  431. real[i] = buf[i];
  432. }
  433. String[] strings = ByteUtils.bytesToHexStrings(real);
  434. //log.info("接收油机数据--" + Arrays.toString(strings));
  435. String msg = Arrays.toString(strings).replaceAll(",", "");
  436. msg = msg.substring(1, msg.length() - 1);
  437. if (!msg.contains("02 01 01 00 02 60 00 0B 01 00 FF")) {
  438. //System.err.println(iTouchIp + "--ITouch信息---" + msg);
  439. //log.info(iTouchIp + "--ITouch信息---" + msg);
  440. AsyncFactory.out.write(ByteUtils.hexToByteArray(msg));
  441. } else {
  442. //System.err.println("ITouch心跳信息---" + msg);
  443. }
  444. }
  445. }
  446. }
  447. } catch (Exception e) {
  448. e.printStackTrace();
  449. }
  450. }
  451. });
  452. }
  453. /**
  454. *发送油枪信息到多媒体app
  455. *
  456. * @param iTouchIp 多媒体app的Ip地址
  457. */
  458. public void sendNozzleInfo(String iTouchIp) {
  459. /* new Thread(new Runnable() {
  460. @Override
  461. public void run() {
  462. try {
  463. if (flagMap.get(iTouchIp)) {
  464. Socket socket = socketMap.get(iTouchIp);
  465. OutputStream out = socket.getOutputStream();
  466. //先发送油枪信息
  467. String nozzleInfo = "";
  468. for (String nozzle : nozzles) {
  469. nozzleInfo += nozzle + " ";
  470. }
  471. System.err.println(iTouchIp + "--发送油枪信息--" + nozzleInfo);
  472. log.info(iTouchIp + "--发送油枪信息--" + nozzleInfo);
  473. byte[] byteInfo = ByteUtils.hexToByteArray(nozzleInfo);
  474. out.write(byteInfo);
  475. out.flush();
  476. flagMap.put(iTouchIp, false);
  477. }
  478. } catch (Exception e) {
  479. e.printStackTrace();
  480. }
  481. }
  482. }).start();*/
  483. nozzleExecutorService.submit(new Runnable() {
  484. @Override
  485. public void run() {
  486. try {
  487. if (flagMap.get(iTouchIp)) {
  488. Socket socket = socketMap.get(iTouchIp);
  489. OutputStream out = socket.getOutputStream();
  490. //先发送油枪信息
  491. String nozzleInfo = "";
  492. for (String nozzle : nozzles) {
  493. nozzleInfo += nozzle + " ";
  494. }
  495. System.err.println(iTouchIp + "--发送油枪信息--" + nozzleInfo);
  496. log.info(iTouchIp + "--发送油枪信息--" + nozzleInfo);
  497. byte[] byteInfo = ByteUtils.hexToByteArray(nozzleInfo);
  498. out.write(byteInfo);
  499. out.flush();
  500. flagMap.put(iTouchIp, false);
  501. }
  502. } catch (Exception e) {
  503. e.printStackTrace();
  504. }
  505. }
  506. });
  507. }
  508. /* public void sendNozzleInfo2(String iTouchIp) {
  509. executorService.submit(new Runnable() {
  510. @Override
  511. public void run() {
  512. try {
  513. if (flagMap.get(iTouchIp)) {
  514. Socket socket = socketMap.get(iTouchIp);
  515. OutputStream out = socket.getOutputStream();
  516. //先发送油枪信息
  517. String nozzleInfo = "";
  518. for (String nozzle : nozzles2) {
  519. System.err.println(iTouchIp + "--发送模拟信息--" + nozzle);
  520. //log.info(iTouchIp + "--发送模拟信息--" + nozzle);
  521. byte[] byteInfo = ByteUtils.hexToByteArray(nozzle);
  522. out.write(byteInfo);
  523. out.flush();
  524. }
  525. *//*System.err.println(iTouchIp + "--发送模拟信息--" + nozzleInfo);
  526. log.info(iTouchIp + "--发送模拟信息--" + nozzleInfo);
  527. byte[] byteInfo = ByteUtils.hexToByteArray(nozzleInfo);
  528. out.write(byteInfo);
  529. out.flush();*//*
  530. flagMap.put(iTouchIp, false);
  531. }
  532. } catch (Exception e) {
  533. e.printStackTrace();
  534. }
  535. }
  536. });
  537. *//*new Thread(new Runnable() {
  538. @Override
  539. public void run() {
  540. try {
  541. if (flagMap.get(iTouchIp)) {
  542. Socket socket = socketMap.get(iTouchIp);
  543. OutputStream out = socket.getOutputStream();
  544. //先发送油枪信息
  545. String nozzleInfo = "";
  546. for (String nozzle : nozzles2) {
  547. System.err.println(iTouchIp + "--发送模拟信息--" + nozzle);
  548. //log.info(iTouchIp + "--发送模拟信息--" + nozzle);
  549. byte[] byteInfo = ByteUtils.hexToByteArray(nozzle);
  550. out.write(byteInfo);
  551. out.flush();
  552. }
  553. *//**//*System.err.println(iTouchIp + "--发送模拟信息--" + nozzleInfo);
  554. log.info(iTouchIp + "--发送模拟信息--" + nozzleInfo);
  555. byte[] byteInfo = ByteUtils.hexToByteArray(nozzleInfo);
  556. out.write(byteInfo);
  557. out.flush();*//**//*
  558. flagMap.put(iTouchIp, false);
  559. }
  560. } catch (Exception e) {
  561. e.printStackTrace();
  562. }
  563. }
  564. }).start();*//*
  565. }*/
  566. /**
  567. * 获取配置文件汇总多媒体信息
  568. *
  569. * @param stationIp 油机Ip地址
  570. * @return
  571. */
  572. public boolean getConfigure(String stationIp) {
  573. try {
  574. String s = JSONUtils.readJSONFile(SocketFactory.FILEPATH);
  575. s = s.trim();
  576. JSONObject configure = JSONObject.parseObject(s);
  577. JSONArray params = configure.getJSONArray("param");
  578. String[] nozzles = null;
  579. String ip = "";
  580. for (Object param : params) {
  581. String paramStr = String.valueOf(param);
  582. JSONObject configureObject = JSONObject.parseObject(paramStr);
  583. ip = String.valueOf(configureObject.get("ip"));
  584. if (ip.equals(stationIp)) {
  585. String nozzle = String.valueOf(configureObject.getJSONObject("configure").get("nozzle"));
  586. nozzles = nozzle.split(",");
  587. }
  588. }
  589. if (nozzles != null) {
  590. for (String nozzleInfo : nozzles) {
  591. String[] split = nozzleInfo.split("\\+");
  592. //Nozzle nozzle = new Nozzle();
  593. //nozzle.setGunNo(split[0]); //枪号
  594. //nozzle.setOils(split[1]); //油品名称
  595. //nozzle.setOilGrade(split[2]); //油品等级
  596. //nozzle.setPayShop(split[3]); //支付方式
  597. //nozzle.setPayType(split[4]); //加油卡类型
  598. if (split.length >= 6) {
  599. //nozzle.setiTouchIp(split[5]); //ITouch ip 地址,显示将该条数据往哪个ITouch屏发送
  600. iTouchHost = split[5];
  601. iTouchIps.add(iTouchHost);
  602. //nozzleMap.add(split[5],split[0]);
  603. }
  604. }
  605. }
  606. return true;
  607. } catch (Exception e) {
  608. e.printStackTrace();
  609. }
  610. return false;
  611. }
  612. }