TestClient2.java 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. package com.steerinfo.util;
  2. import com.steerinfo.framework.utils.collection.ListUtils;
  3. import com.steerinfo.meterwork.constants.DbConstants;
  4. import com.steerinfo.rtdb.*;
  5. import com.sun.org.apache.bcel.internal.generic.NEW;
  6. import java.math.BigDecimal;
  7. import java.util.ArrayList;
  8. import java.util.List;
  9. public class TestClient2 {
  10. public static Client getConnecting() {
  11. ClientConfig config = new ClientConfig();
  12. config.username = "guest";
  13. config.password = "";
  14. // int j = 0;
  15. // while (j < 2) {
  16. // SocketChannelProvider socketChannel = new SingleSocketChannelProviderImpl("172.16.100.139:2013");
  17. // Client client = new ClientImpl(socketChannel, config);
  18. // List<ArrayList> res1 = (List<ArrayList>) client.syncOps().call("db.space.Live:select",Collections.emptyList());
  19. // client.close();
  20. // List ll = res1.get(0);
  21. // for (int i = 0; i < ll.size(); i++) {
  22. // String s = ll.get(i).toString();
  23. // String head = s.substring(1, s.indexOf(","));
  24. // if (head.endsWith("56-202/8101/totalpower")) {
  25. // ////system.out.println(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()) + " : " + s);
  26. // }
  27. // if (head.endsWith("totalpower") && head.startsWith("device/iec102-42-159")) {
  28. // //system.out.println(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()) + " : " + s);
  29. // }
  30. // }
  31. // Thread.sleep(1000 * 10);
  32. // j++;
  33. // }
  34. SocketChannelProvider socketChannel = new SingleSocketChannelProviderImpl("172.22.42.3:2101");
  35. return new ClientImpl(socketChannel, config);
  36. }
  37. public static List connectSelect(String no) {
  38. try {
  39. List<ArrayList> res1 = (List<ArrayList>) DbConstants.client.syncOps().call("db.space.TrackWeight:select", no);
  40. List ll = res1.get(0);
  41. return ll;
  42. } catch (Exception e) {
  43. DbConstants.client.close();
  44. DbConstants.client = TestClient2.getConnecting();
  45. return null;
  46. }
  47. }
  48. public static void main(String[] args) {
  49. ClientConfig config = new ClientConfig();
  50. config.username = "guest";
  51. config.password = "";
  52. SocketChannelProvider socketChannel = new SingleSocketChannelProviderImpl("192.168.102.51:2101");
  53. Client client = new ClientImpl(socketChannel, config);
  54. List<ArrayList> res1 = (List<ArrayList>) client.syncOps().call("LiveData:readByPointId", "CAR01");
  55. if (ListUtils.isNotEmpty(res1)) {
  56. List listDate1 = res1.get(0);
  57. BigDecimal westTime = BigDecimal.valueOf(0),eastTime = BigDecimal.valueOf(0);
  58. String vlprWest = "", vlprEast = "";
  59. for (Object liveDate : listDate1) {
  60. String myLiveDate = liveDate.toString();
  61. String[] listDate = myLiveDate.split(",");
  62. if (listDate[0].equals("[HMI01VlprWest")) {
  63. westTime = new BigDecimal(listDate[2].trim());
  64. vlprWest = listDate[1].trim();
  65. //system.out.println("测试输出1:" + listDate[1].trim());
  66. }
  67. if (listDate[0].equals("[HMI01VlprEast")) {
  68. eastTime = new BigDecimal(listDate[2].trim());
  69. vlprEast = listDate[1].trim();
  70. //system.out.println("测试输出2:" + listDate[1].trim());
  71. }
  72. }
  73. if (westTime.compareTo(eastTime) > 0) {
  74. //system.out.println("测试输出3:" + vlprWest);
  75. } else {
  76. //system.out.println("测试输出4:" + vlprEast);
  77. }
  78. }
  79. client.close();
  80. List ll = res1.get(0);
  81. ArrayList arr = (ArrayList) ll.get(0);
  82. //system.out.println(arr.get(6));
  83. }
  84. }