更新车辆上线代码逻辑
parent
5c2fbb91dd
commit
3ecc09bb50
1
pom.xml
1
pom.xml
|
@ -13,7 +13,6 @@
|
||||||
<maven.compiler.target>17</maven.compiler.target>
|
<maven.compiler.target>17</maven.compiler.target>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<mybatisplus.version>3.5.1</mybatisplus.version>
|
<mybatisplus.version>3.5.1</mybatisplus.version>
|
||||||
<freemaker.version>2.3.31</freemaker.version>
|
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<parent>
|
<parent>
|
||||||
|
|
|
@ -13,6 +13,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
@Log4j2
|
@Log4j2
|
||||||
@Controller
|
@Controller
|
||||||
public class IndexController {
|
public class IndexController {
|
||||||
|
|
||||||
@RequestMapping("/")
|
@RequestMapping("/")
|
||||||
public String hello(){
|
public String hello(){
|
||||||
log.debug("重定向到 - /static/index 页面");
|
log.debug("重定向到 - /static/index 页面");
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package com.muyu.controller;
|
package com.muyu.controller;
|
||||||
|
|
||||||
import com.muyu.common.Result;
|
import com.muyu.common.Result;
|
||||||
|
import com.muyu.domain.model.MqttServerModel;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
@ -14,12 +16,25 @@ import org.springframework.web.bind.annotation.RestController;
|
||||||
@RequestMapping("/verify")
|
@RequestMapping("/verify")
|
||||||
public class VerifyController {
|
public class VerifyController {
|
||||||
|
|
||||||
|
|
||||||
|
@Value("${mqtt.server.host}")
|
||||||
|
private String broker;
|
||||||
|
|
||||||
|
@Value("${mqtt.server.topic}")
|
||||||
|
private String topic;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 新增车辆默认上线主题
|
* 新增车辆默认上线主题
|
||||||
* @return 默认返回test
|
* @return 默认返回test
|
||||||
*/
|
*/
|
||||||
@PostMapping("/vehicleConnection")
|
@PostMapping("/vehicleConnection")
|
||||||
public Result<String> vehicleConnection(){
|
public Result<MqttServerModel> vehicleConnection(){
|
||||||
return Result.success("test");
|
return Result.success(
|
||||||
|
MqttServerModel.builder()
|
||||||
|
.broker(broker)
|
||||||
|
.topic(topic)
|
||||||
|
.build()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
package com.muyu.domain.model;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author DongZl
|
||||||
|
* @description: Mqtt服务器模型
|
||||||
|
* @Date 2024-3-26 上午 09:53
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class MqttServerModel {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MQTT服务节点
|
||||||
|
*/
|
||||||
|
private String broker;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MQTT订阅主题
|
||||||
|
*/
|
||||||
|
private String topic;
|
||||||
|
}
|
|
@ -1,18 +1,14 @@
|
||||||
package com.muyu.service.impl;
|
package com.muyu.service.impl;
|
||||||
|
|
||||||
import com.alibaba.fastjson2.JSONArray;
|
|
||||||
import com.muyu.common.PageList;
|
import com.muyu.common.PageList;
|
||||||
import com.muyu.common.Result;
|
import com.muyu.common.Result;
|
||||||
import com.muyu.common.pool.FixedThreadPool;
|
|
||||||
import com.muyu.domain.PositionRouteInfo;
|
|
||||||
import com.muyu.domain.Vehicle;
|
import com.muyu.domain.Vehicle;
|
||||||
|
import com.muyu.domain.model.MqttServerModel;
|
||||||
import com.muyu.domain.model.PositionModel;
|
import com.muyu.domain.model.PositionModel;
|
||||||
import com.muyu.domain.model.TaskModel;
|
|
||||||
import com.muyu.domain.req.CheckPositionReq;
|
import com.muyu.domain.req.CheckPositionReq;
|
||||||
import com.muyu.domain.req.GearReq;
|
import com.muyu.domain.req.GearReq;
|
||||||
import com.muyu.domain.req.MsgReq;
|
import com.muyu.domain.req.MsgReq;
|
||||||
import com.muyu.domain.req.VehicleInstanceListReq;
|
import com.muyu.domain.req.VehicleInstanceListReq;
|
||||||
import com.muyu.domain.resp.UnifiedTaskResp;
|
|
||||||
import com.muyu.domain.resp.VehicleInstanceResp;
|
import com.muyu.domain.resp.VehicleInstanceResp;
|
||||||
import com.muyu.service.PositionRouteService;
|
import com.muyu.service.PositionRouteService;
|
||||||
import com.muyu.service.VehicleInstanceService;
|
import com.muyu.service.VehicleInstanceService;
|
||||||
|
@ -27,15 +23,11 @@ import com.muyu.vehicle.model.properties.MqttProperties;
|
||||||
import lombok.extern.log4j.Log4j2;
|
import lombok.extern.log4j.Log4j2;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.CountDownLatch;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -54,9 +46,6 @@ public class VehicleInstanceServiceImpl implements VehicleInstanceService {
|
||||||
@Autowired
|
@Autowired
|
||||||
private ClientAdmin clientAdmin;
|
private ClientAdmin clientAdmin;
|
||||||
|
|
||||||
@Value("${mqtt.server.host}")
|
|
||||||
private String broker;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据车辆生成车辆实例
|
* 根据车辆生成车辆实例
|
||||||
*
|
*
|
||||||
|
@ -122,14 +111,15 @@ public class VehicleInstanceServiceImpl implements VehicleInstanceService {
|
||||||
.userName(MD5Util.encrypted(vin+timestamp))
|
.userName(MD5Util.encrypted(vin+timestamp))
|
||||||
.nonce(MD5Util.encrypted(UUID.randomUUID().toString().replace("-", "")))
|
.nonce(MD5Util.encrypted(UUID.randomUUID().toString().replace("-", "")))
|
||||||
.build();
|
.build();
|
||||||
Result<String> result = clientAdmin.vehicleConnection(connectionReq);
|
Result<MqttServerModel> result = clientAdmin.vehicleConnection(connectionReq);
|
||||||
if (result.getCode() != 200){
|
if (result.getCode() != 200){
|
||||||
log.error("车辆:[{}],申请上线异常:[{}]", vin, result.getMsg());
|
log.error("车辆:[{}],申请上线异常:[{}]", vin, result.getMsg());
|
||||||
throw new RuntimeException("远程服务器没有【"+vin+"】车辆");
|
throw new RuntimeException("远程服务器没有【"+vin+"】车辆");
|
||||||
}
|
}
|
||||||
|
MqttServerModel mqttServerModel = result.getData();
|
||||||
MqttProperties mqttProperties = MqttProperties.builder()
|
MqttProperties mqttProperties = MqttProperties.builder()
|
||||||
.broker(broker)
|
.broker(mqttServerModel.getBroker())
|
||||||
.topic(result.getData())
|
.topic(mqttServerModel.getTopic())
|
||||||
.clientId(vin)
|
.clientId(vin)
|
||||||
.username(connectionReq.getUserName())
|
.username(connectionReq.getUserName())
|
||||||
.password(vin + connectionReq.getTimestamp() + connectionReq.getNonce())
|
.password(vin + connectionReq.getTimestamp() + connectionReq.getNonce())
|
||||||
|
|
|
@ -55,9 +55,10 @@ public class VehicleUnifiedServiceImpl implements VehicleUnifiedService {
|
||||||
.stream()
|
.stream()
|
||||||
.map(VehicleInstance::getVin)
|
.map(VehicleInstance::getVin)
|
||||||
.toList();
|
.toList();
|
||||||
|
taskModel.submit("一键上线", vinList.size());
|
||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
int vinSize = 0, executionSize = 15;
|
int vinSize = 0, executionSize = 15;
|
||||||
do {
|
do {
|
||||||
int startIndex = vinSize++ * executionSize;
|
int startIndex = vinSize++ * executionSize;
|
||||||
// 进行分页开启车辆
|
// 进行分页开启车辆
|
||||||
List<String> executionVinList = vinList.stream()
|
List<String> executionVinList = vinList.stream()
|
||||||
|
@ -94,6 +95,7 @@ public class VehicleUnifiedServiceImpl implements VehicleUnifiedService {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}while (true);
|
}while (true);
|
||||||
|
taskModel.down();
|
||||||
}).start();
|
}).start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package com.muyu.utils;
|
package com.muyu.utils;
|
||||||
|
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
public class ConversionUtil {
|
public class ConversionUtil {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -17,4 +19,47 @@ public class ConversionUtil {
|
||||||
}
|
}
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void main (String[] args) {
|
||||||
|
// String str = "<?xml version=\"1.0\"?>\n" +
|
||||||
|
// "<monitorRoot type=\"param\"><synchronizeSyptom event=\"0\" initial=\"true\"><Action_ECG><Rhythm>Sinus</Rhythm><HR>80</HR><EMD>No Change</EMD><Conduct>0</Conduct></Action_ECG><Action_Osat value=\"94\" isRelativePercent=\"false\"/><Action_BP isRelativePercent=\"false\"><Shrink value=\"120\"/><Stretch value=\"80\"/></Action_BP><Action_Resp breathType=\"Normal\" value=\"14\" isRelativePercent=\"false\"/><Action_etCO2 value=\"34\" isRelativePercent=\"false\"/><Action_Temperature value=\"35.2\"/><Action_CVP value=\"6.0\"/><Action_PAPDia value=\"10\"/><Action_PAPSys value=\"25\"/><Action_WP value=\"9\"/></synchronizeSyptom></monitorRoot>";
|
||||||
|
// String strToSixteen = strToSixteen(str);
|
||||||
|
// System.out.println(str);
|
||||||
|
// System.out.println(str.length());
|
||||||
|
// System.out.println(strToSixteen);
|
||||||
|
// System.out.println(strToSixteen.replace(" ", "").length());
|
||||||
|
|
||||||
|
String hexStr = "3C3F786D6C2076657273696F6E3D22312E30223F3E0D0A3C6D6F6E69746F72526F6F7420747970653D22706172616D223E3C73796E6368726F6E697A65537970746F6D206576656E743D22302220696E697469616C3D2274727565223E3C416374696F6E5F4543473E3C52687974686D3E53696E75733C2F52687974686D3E3C48523E38303C2F48523E3C454D443E4E6F204368616E67653C2F454D443E3C436F6E647563743E303C2F436F6E647563743E3C2F416374696F6E5F4543473E3C416374696F6E5F4F7361742076616C75653D2239342220697352656C617469766550657263656E743D2266616C7365222F3E3C416374696F6E5F425020697352656C617469766550657263656E743D2266616C7365223E3C536872696E6B2076616C75653D22313230222F3E3C537472657463682076616C75653D223830222F3E3C2F416374696F6E5F42503E3C416374696F6E5F5265737020627265617468547970653D224E6F726D616C222076616C75653D2231342220697352656C617469766550657263656E743D2266616C7365222F3E3C416374696F6E5F6574434F322076616C75653D2233342220697352656C617469766550657263656E743D2266616C7365222F3E3C416374696F6E5F54656D70657261747572652076616C75653D2233352E32222F3E3C416374696F6E5F4356502076616C75653D22362E30222F3E3C416374696F6E5F5041504469612076616C75653D223130222F3E3C416374696F6E5F5041505379732076616C75653D223235222F3E3C416374696F6E5F57502076616C75653D2239222F3E3C2F73796E6368726F6E697A65537970746F6D3E3C2F6D6F6E69746F72526F6F743E0D0A";
|
||||||
|
String hexStringToString = hexStringToString(hexStr);
|
||||||
|
System.out.println(hexStr);
|
||||||
|
System.out.println(hexStr.length());
|
||||||
|
System.out.println(hexStringToString);
|
||||||
|
System.out.println(hexStringToString.length());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 16进制转换成为string类型字符串
|
||||||
|
* @param s
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String hexStringToString(String s) {
|
||||||
|
if (s == null || s.equals("")) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
s = s.replace(" ", "");
|
||||||
|
byte[] baKeyword = new byte[s.length() / 2];
|
||||||
|
for (int i = 0; i < baKeyword.length; i++) {
|
||||||
|
try {
|
||||||
|
baKeyword[i] = (byte) (0xff & Integer.parseInt(s.substring(i * 2, i * 2 + 2), 16));
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
s = new String(baKeyword, StandardCharsets.UTF_8);
|
||||||
|
} catch (Exception e1) {
|
||||||
|
e1.printStackTrace();
|
||||||
|
}
|
||||||
|
return s;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import com.dtflys.forest.annotation.BaseRequest;
|
||||||
import com.dtflys.forest.annotation.JSONBody;
|
import com.dtflys.forest.annotation.JSONBody;
|
||||||
import com.dtflys.forest.annotation.Post;
|
import com.dtflys.forest.annotation.Post;
|
||||||
import com.muyu.common.Result;
|
import com.muyu.common.Result;
|
||||||
|
import com.muyu.domain.model.MqttServerModel;
|
||||||
import com.muyu.vehicle.api.req.VehicleConnectionReq;
|
import com.muyu.vehicle.api.req.VehicleConnectionReq;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -17,5 +18,5 @@ import com.muyu.vehicle.api.req.VehicleConnectionReq;
|
||||||
public interface ClientAdmin {
|
public interface ClientAdmin {
|
||||||
|
|
||||||
@Post("${adminTopicUri}")
|
@Post("${adminTopicUri}")
|
||||||
public Result<String> vehicleConnection(@JSONBody VehicleConnectionReq vehicleConnectionReq);
|
public Result<MqttServerModel> vehicleConnection(@JSONBody VehicleConnectionReq vehicleConnectionReq);
|
||||||
}
|
}
|
||||||
|
|
|
@ -87,6 +87,7 @@ forest:
|
||||||
mqtt:
|
mqtt:
|
||||||
server:
|
server:
|
||||||
host: tcp://fluxmq.muyu.icu:1883
|
host: tcp://fluxmq.muyu.icu:1883
|
||||||
|
topic: test1
|
||||||
admin:
|
admin:
|
||||||
host: http://127.0.0.1:${server.port}
|
host: http://127.0.0.1:${server.port}
|
||||||
topic-uri: /verify/vehicleConnection
|
topic-uri: /verify/vehicleConnection
|
||||||
|
|
Loading…
Reference in New Issue