158 lines
14 KiB
Java
158 lines
14 KiB
Java
package com.muyu.vehicle;
|
||
|
||
import com.alibaba.fastjson2.JSONArray;
|
||
import com.muyu.domain.Vehicle;
|
||
import com.muyu.domain.model.PositionModel;
|
||
import com.muyu.utils.VehicleUtils;
|
||
import com.muyu.vehicle.core.LocalContainer;
|
||
import com.muyu.vehicle.model.VehicleData;
|
||
import com.muyu.vehicle.model.properties.MqttProperties;
|
||
import lombok.extern.log4j.Log4j2;
|
||
|
||
import java.math.BigDecimal;
|
||
import java.util.ArrayList;
|
||
import java.util.Date;
|
||
import java.util.List;
|
||
|
||
import static java.lang.Thread.sleep;
|
||
|
||
/**
|
||
* @author DongZl
|
||
* @description:
|
||
* @Date 2023-11-17 上午 09:02
|
||
*/
|
||
@Log4j2
|
||
public class Test {
|
||
|
||
private static String localStrJson = "[\"116.664053,39.531791\",\"116.66438,39.53199\",\"116.665067,39.532478\",\"116.66556,39.532879\",\"116.66607,39.533219\",\"116.666268,39.53343\",\"116.666789,39.533794\",\"116.668,39.5347\",\"116.669202,39.535577\",\"116.669964,39.536214\",\"116.670248,39.536293\",\"116.670656,39.536289\",\"116.67087,39.536541\",\"116.670799,39.536898\",\"116.670568,39.537064\",\"116.67038,39.537432\",\"116.670327,39.538086\",\"116.670235,39.538996\",\"116.670152,39.539968\",\"116.670152,39.539968\",\"116.670169,39.540365\",\"116.670093,39.541209\",\"116.670045,39.541697\",\"116.669949,39.542748\",\"116.669911,39.542963\",\"116.669884,39.543542\",\"116.669857,39.54377\",\"116.669841,39.544039\",\"116.669811,39.54439\",\"116.669789,39.544621\",\"116.669741,39.545126\",\"116.669714,39.545593\",\"116.669698,39.545804\",\"116.669656,39.546451\",\"116.66964,39.546662\",\"116.669527,39.547166\",\"116.669626,39.547133\",\"116.670103,39.547179\",\"116.670484,39.547216\",\"116.670994,39.547257\",\"116.671809,39.547315\",\"116.67263,39.547386\",\"116.673089,39.547415\",\"116.673373,39.547498\",\"116.674065,39.547547\",\"116.675176,39.547643\",\"116.675961,39.547703\",\"116.676583,39.547757\",\"116.677393,39.547828\",\"116.678005,39.547881\",\"116.67859,39.547914\",\"116.679089,39.547931\",\"116.679228,39.54791\",\"116.679829,39.547964\",\"116.680703,39.548039\",\"116.681186,39.54808\",\"116.681637,39.548113\",\"116.682216,39.548163\",\"116.682935,39.548221\",\"116.683402,39.548262\",\"116.683627,39.548324\",\"116.684132,39.548379\",\"116.685092,39.548454\",\"116.686444,39.548582\",\"116.686809,39.548611\",\"116.687739,39.548685\",\"116.688726,39.548785\",\"116.689536,39.548843\",\"116.689927,39.548863\",\"116.690206,39.548888\",\"116.690732,39.548934\",\"116.691455,39.549\",\"116.692249,39.54907\",\"116.692651,39.549091\",\"116.693086,39.549128\",\"116.693665,39.549194\",\"116.69389,39.549219\",\"116.694598,39.549273\",\"116.695784,39.549397\",\"116.696245,39.549376\",\"116.69698,39.549446\",\"116.697189,39.549459\",\"116.697619,39.549521\",\"116.697983,39.549525\",\"116.69874,39.549579\",\"116.698911,39.549653\",\"116.699426,39.54967\",\"116.699673,39.549711\",\"116.700462,39.549786\",\"116.700923,39.54981\",\"116.701277,39.549852\",\"116.701695,39.549889\",\"116.702157,39.549914\",\"116.702543,39.549963\",\"116.702881,39.549988\",\"116.703423,39.550021\",\"116.704013,39.550083\",\"116.704624,39.550112\",\"116.704603,39.549992\",\"116.704614,39.549798\",\"116.704651,39.549463\",\"116.704704,39.549051\",\"116.704768,39.548761\",\"116.704795,39.548298\",\"116.704913,39.547417\",\"116.704972,39.546953\",\"116.705095,39.545857\",\"116.705229,39.544898\",\"116.705235,39.544658\",\"116.70531,39.544062\",\"116.705422,39.543483\",\"116.70546,39.542966\",\"116.705503,39.542486\",\"116.705658,39.541373\",\"116.705707,39.540992\",\"116.70576,39.54057\",\"116.705793,39.540302\",\"116.705857,39.53983\",\"116.705905,39.539334\",\"116.705948,39.538978\",\"116.70598,39.538667\",\"116.70605,39.538183\",\"116.706098,39.537828\",\"116.706136,39.537546\",\"116.706195,39.537071\",\"116.706291,39.536272\",\"116.706383,39.535763\",\"116.706426,39.535308\",\"116.706458,39.53506\",\"116.706533,39.534506\",\"116.706565,39.53422\",\"116.706672,39.533355\",\"116.70671,39.533029\",\"116.706747,39.532664\",\"116.706817,39.532234\",\"116.706876,39.531696\",\"116.706958,39.531083\",\"116.707011,39.530512\",\"116.707049,39.530239\",\"116.707103,39.529871\",\"116.707156,39.529321\",\"116.707215,39.528957\",\"116.707247,39.528717\",\"116.70729,39.528427\",\"116.707344,39.528022\",\"116.707382,39.527604\",\"116.707419,39.527413\",\"116.70743,39.52724\",\"116.707451,39.527066\",\"116.707489,39.526784\",\"116.707542,39.52635\",\"116.707607,39.525804\",\"116.707628,39.525688\",\"116.707671,39.525245\",\"116.707666,39.525307\",\"116.707671,39.525278\",\"116.707741,39.524786\",\"116.707781,39.524421\",\"116.707797,39.524214\",\"116.70784,39.523887\",\"116.707867,39.523734\",\"116.707902,39.523415\",\"116.707961,39.52308\",\"116.707993,39.522645\",\"116.708047,39.522261\",\"116.708084,39.521954\",\"116.708138,39.521553\",\"116.708159,39.521387\",\"116.708202,39.521023\",\"116.708245,39.520725\",\"116.708288,39.520407\",\"116.708326,39.520022\",\"116.708422,39.5195\",\"116.708449,39.519045\",\"116.708508,39.518607\",\"116.708556,39.518259\",\"116.708615,39.517589\",\"116.708663,39.517328\",\"116.708706,39.517017\",\"116.708749,39.516682\",\"116.708819,39.516322\",\"116.708835,39.516086\",\"116.708905,39.515569\",\"116.708937,39.51547\",\"116.708567,39.515474\",\"116.708175,39.515482\",\"116.707703,39.515486\",\"116.707414,39.515482\",\"116.706797,39.515495\",\"116.706303,39.515482\",\"116.7053,39.515507\",\"116.704613,39.515515\",\"116.704369,39.515242\",\"116.704095,39.514969\",\"116.703849,39.514708\",\"116.703811,39.5147\",\"116.703559,39.514431\",\"116.703232,39.514083\",\"116.702904,39.513727\",\"116.702593,39.513425\",\"116.702298,39.513119\",\"116.70203,39.512834\",\"116.701628,39.512519\",\"116.70129,39.512349\",\"116.701102,39.512411\",\"116.700635,39.512457\",\"116.700201,39.512486\",\"116.699965,39.512511\",\"116.699428,39.512565\",\"116.699101,39.512602\",\"116.698709,39.512631\",\"116.698034,39.512709\",\"116.6968,39.512807\",\"116.695663,39.51294\",\"116.694193,39.513047\",\"116.693013,39.513188\",\"116.692734,39.513221\",\"116.691833,39.513263\",\"116.690739,39.513329\",\"116.690277,39.513279\",\"116.689773,39.513329\",\"116.688732,39.513296\",\"116.687828,39.51328\",\"116.687308,39.513255\",\"116.686991,39.513242\",\"116.686149,39.513205\",\"116.685554,39.51318\",\"116.685103,39.513193\",\"116.684626,39.51316\",\"116.684164,39.513156\",\"116.683306,39.513118\",\"116.682748,39.513081\",\"116.681793,39.513065\",\"116.6813,39.513048\",\"116.68049,39.513015\",\"116.679074,39.512957\",\"116.678478,39.512903\",\"116.67799,39.512878\",\"116.677352,39.512858\",\"116.676831,39.512816\",\"116.676204,39.512783\",\"116.67556,39.51275\",\"116.675088,39.512738\",\"116.674772,39.512696\",\"116.67446,39.512684\",\"116.674017,39.512672\",\"116.673818,39.512663\",\"116.67326,39.512618\",\"116.673013,39.512601\",\"116.672434,39.512585\",\"116.672032,39.512556\",\"116.671291,39.51251\",\"116.670685,39.512473\",\"116.67031,39.512473\",\"116.66994,39.512436\",\"116.669398,39.512432\",\"116.668877,39.512403\",\"116.66855,39.512353\",\"116.668207,39.51234\",\"116.667746,39.512316\",\"116.667086,39.512274\",\"116.666592,39.512225\",\"116.666378,39.512249\",\"116.666313,39.512502\",\"116.666286,39.512738\",\"116.666244,39.512982\",\"116.666227,39.513156\",\"116.666217,39.513379\",\"116.666125,39.513942\",\"116.666072,39.514381\",\"116.666034,39.514579\",\"116.666024,39.514815\",\"116.665965,39.5152\",\"116.665889,39.51573\",\"116.665841,39.51609\",\"116.665761,39.51664\",\"116.665739,39.516897\",\"116.665682,39.517227\",\"116.665671,39.517318\",\"116.66566,39.517463\",\"116.665607,39.517802\",\"116.665574,39.518063\",\"116.665526,39.51851\",\"116.665478,39.5188\",\"116.665435,39.519015\",\"116.665419,39.519201\",\"116.665378,39.519652\",\"116.665335,39.519917\",\"116.665314,39.520128\",\"116.66526,39.5205\",\"116.665223,39.520707\",\"116.665115,39.521585\",\"116.665083,39.521775\",\"116.665035,39.522081\",\"116.665013,39.522251\",\"116.664992,39.522458\",\"116.664951,39.52279\",\"116.664892,39.523175\",\"116.664844,39.52358\",\"116.664737,39.524362\",\"116.664673,39.524714\",\"116.664646,39.52502\",\"116.66464,39.525181\",\"116.664576,39.525508\",\"116.664538,39.525802\",\"116.664479,39.52622\",\"116.664463,39.52639\",\"116.664426,39.526688\",\"116.664378,39.527058\",\"116.664319,39.527455\",\"116.664319,39.527455\",\"116.664248,39.527948\",\"116.664189,39.528312\",\"116.664136,39.528788\",\"116.664114,39.529036\",\"116.664071,39.529276\",\"116.664023,39.529619\",\"116.66398,39.529934\",\"116.663913,39.530326\",\"116.663865,39.530674\",\"116.663817,39.531071\",\"116.663817,39.531071\",\"116.663994,39.531687\",\"116.664069,39.531778\",\"116.664069,39.531778\",\"116.664069,39.531778\",\"116.664069,39.531778\",\"116.664069,39.531778\",\"116.664069,39.531778\",\"116.664069,39.531778\",\"116.664069,39.531778\",\"116.664069,39.531778\",\"116.664069,39.531778\",\"116.664069,39.531778\",\"116.664069,39.531778\",\"116.664069,39.531778\",\"116.664069,39.531778\",\"116.664069,39.531778\",\"116.664069,39.531778\",\"116.664069,39.531778\",\"116.664069,39.531778\",\"116.664069,39.531778\",\"116.664069,39.531778\",\"116.664069,39.531778\",\"116.664069,39.531778\",\"116.664069,39.531778\",\"116.664069,39.531778\",\"116.664069,39.531778\",\"116.664069,39.531778\",\"116.664069,39.531778\",\"116.664069,39.531778\",\"116.664069,39.531778\",\"116.664069,39.531778\",\"116.664069,39.531778\",\"116.664069,39.531778\",\"116.664069,39.531778\",\"116.664069,39.531778\",\"116.664069,39.531778\",\"116.664069,39.531778\",\"116.664069,39.531778\",\"116.664069,39.531778\"]";
|
||
|
||
private static MqttProperties mqttProperties = MqttProperties.builder()
|
||
.broker("tcp://fluxmq.muyu.icu:1883")
|
||
.topic("mqttAA")
|
||
.username("123456")
|
||
.password("AJLJWIEJLASDJOWQES")
|
||
.build();
|
||
|
||
public static void main(String[] args) {
|
||
log.info("开始生成VIN");
|
||
long genVinStartTime = System.currentTimeMillis();
|
||
List<String> list = new ArrayList<>();
|
||
// list.add("VIN12345678912345");
|
||
for (int i = 0; i < 100; i++) {
|
||
list.add(VehicleUtils.genVin());
|
||
}
|
||
log.info("生成VIN结束:[{}MS]", System.currentTimeMillis()-genVinStartTime);
|
||
log.info("开始创建车辆");
|
||
long initVehicleStartTime = System.currentTimeMillis();
|
||
list.forEach(Test::init);
|
||
log.info("创建车辆结束:[{}MS]", System.currentTimeMillis()-initVehicleStartTime);
|
||
list.forEach(vin -> {
|
||
VehicleInstance vehicleIns = LocalContainer.getVehicleInstance(vin);
|
||
vehicleIns.setPositionCode("123");
|
||
vehicleIns.initVehicleThread();
|
||
vehicleIns.startSend();
|
||
});
|
||
|
||
list.forEach(vin -> {
|
||
VehicleInstance vehicleInstance = LocalContainer.getVehicleInstance(vin);
|
||
vehicleInstance.settingPosition(
|
||
JSONArray.parseArray(localStrJson, String.class)
|
||
.stream()
|
||
.map(PositionModel::strBuild)
|
||
.toList()
|
||
);
|
||
});
|
||
|
||
new Thread(() -> {
|
||
try {
|
||
Thread.sleep(5000);
|
||
} catch (InterruptedException e) {
|
||
throw new RuntimeException(e);
|
||
}
|
||
list.forEach(vin -> {
|
||
VehicleInstance vehicleIns = LocalContainer.getVehicleInstance(vin);
|
||
vehicleIns.setGear("D");
|
||
});
|
||
}).start();
|
||
// countDownLatch.await();
|
||
// ThreadPool.shutdown();
|
||
}
|
||
|
||
public static void init(String vin){
|
||
Vehicle vehicle = Vehicle.builder()
|
||
.vin(vin)
|
||
.createTime(new Date())
|
||
.remainingBattery(new BigDecimal("45000"))
|
||
.batteryLevel(new BigDecimal("50000"))
|
||
.totalMileage(new BigDecimal("12.5"))
|
||
.build();
|
||
log.info("构建车辆对象");
|
||
mqttProperties.setClientId(vin);
|
||
VehicleInstance vehicleInstance = new VehicleInstance(
|
||
mqttProperties
|
||
);
|
||
log.info("构建车辆实例");
|
||
vehicleInstance.setVehicle(vehicle);
|
||
vehicleInstance.setVehicleData(VehicleData.vehicleBuild(vehicle));
|
||
vehicleInstance.initClient();
|
||
log.info("构建车辆客户端");
|
||
LocalContainer.setVehicleInstance(vehicleInstance);
|
||
}
|
||
|
||
}
|
||
|
||
class TestThread implements Runnable{
|
||
|
||
private String vin ;
|
||
|
||
public TestThread(String vin) {
|
||
this.vin = vin;
|
||
}
|
||
|
||
/**
|
||
* When an object implementing interface {@code Runnable} is used
|
||
* to create a thread, starting the thread causes the object's
|
||
* {@code run} method to be called in that separately executing
|
||
* thread.
|
||
* <p>
|
||
* The general contract of the method {@code run} is that it may
|
||
* take any action whatsoever.
|
||
*
|
||
* @see Thread#run()
|
||
*/
|
||
@Override
|
||
public void run() {
|
||
VehicleInstance vehicleIns = LocalContainer.getVehicleInstance(vin);
|
||
vehicleIns.initVehicleThread();
|
||
// try {
|
||
// sleep(3000);
|
||
// } catch (InterruptedException e) {
|
||
// throw new RuntimeException(e);
|
||
// }
|
||
vehicleIns.startSend();
|
||
|
||
/*try {
|
||
sleep(3000);
|
||
} catch (InterruptedException e) {
|
||
throw new RuntimeException(e);
|
||
}
|
||
vehicleIns.pauseSend();
|
||
|
||
try {
|
||
sleep(3000);
|
||
} catch (InterruptedException e) {
|
||
throw new RuntimeException(e);
|
||
}
|
||
vehicleIns.startSend();*/
|
||
|
||
// try {
|
||
// sleep(10000);
|
||
// } catch (InterruptedException e) {
|
||
// throw new RuntimeException(e);
|
||
// }
|
||
// vehicleIns.stopSend();
|
||
//
|
||
// Test.countDownLatch.countDown();
|
||
}
|
||
}
|