车辆数据模拟
parent
8fd9aea58a
commit
8413e2e627
|
@ -38,4 +38,6 @@ public class VehicleController {
|
||||||
vehicleService.generate(sum);
|
vehicleService.generate(sum);
|
||||||
return Result.success();
|
return Result.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
package com.muyu.controller;
|
package com.muyu.controller;
|
||||||
|
|
||||||
import com.muyu.common.Result;
|
import com.muyu.common.Result;
|
||||||
|
import com.muyu.domain.req.CheckPositionReq;
|
||||||
|
import com.muyu.domain.req.GearReq;
|
||||||
|
import com.muyu.domain.req.MsgReq;
|
||||||
import com.muyu.domain.req.VehicleInstanceListReq;
|
import com.muyu.domain.req.VehicleInstanceListReq;
|
||||||
import com.muyu.domain.resp.VehicleInstanceResp;
|
import com.muyu.domain.resp.VehicleInstanceResp;
|
||||||
import com.muyu.service.VehicleInstanceService;
|
import com.muyu.service.VehicleInstanceService;
|
||||||
|
@ -55,4 +58,35 @@ public class VehicleInstanceController {
|
||||||
this.vehicleInstanceService.vehicleClientClose(vin);
|
this.vehicleInstanceService.vehicleClientClose(vin);
|
||||||
return Result.success();
|
return Result.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 选择车辆轨迹
|
||||||
|
* @param checkPositionReq 轨迹选择
|
||||||
|
* @return 操作提示
|
||||||
|
*/
|
||||||
|
@PostMapping("/position/check")
|
||||||
|
public Result<String> checkPosition(@RequestBody CheckPositionReq checkPositionReq){
|
||||||
|
this.vehicleInstanceService.checkPosition(checkPositionReq);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 车辆报文操作
|
||||||
|
* @return 操作提示
|
||||||
|
*/
|
||||||
|
@PostMapping("/msg")
|
||||||
|
public Result<String> msg(@RequestBody MsgReq msgReq){
|
||||||
|
this.vehicleInstanceService.msg(msgReq);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 车辆档位操作
|
||||||
|
* @return 操作提示
|
||||||
|
*/
|
||||||
|
@PostMapping("/gear")
|
||||||
|
public Result<String> gear(@RequestBody GearReq gearReq){
|
||||||
|
this.vehicleInstanceService.gear(gearReq);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
package com.muyu.controller;
|
||||||
|
|
||||||
|
import com.muyu.common.Result;
|
||||||
|
import com.muyu.domain.PositionRouteInfo;
|
||||||
|
import com.muyu.service.PositionRouteService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author DongZl
|
||||||
|
* @description: 车辆路径控制层
|
||||||
|
* @Date 2023-11-27 上午 10:50
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/position")
|
||||||
|
public class VehiclePositionController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private PositionRouteService positionRouteService;
|
||||||
|
|
||||||
|
@GetMapping("/list")
|
||||||
|
public Result<List<String>> listAll(){
|
||||||
|
List<PositionRouteInfo> positionRouteInfos = positionRouteService.list();
|
||||||
|
List<String> list = positionRouteInfos.stream().map(PositionRouteInfo::getName)
|
||||||
|
.toList();
|
||||||
|
return Result.success(list);
|
||||||
|
}
|
||||||
|
}
|
|
@ -20,7 +20,7 @@ import java.util.Date;
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@TableName("route_info")
|
@TableName("route_info")
|
||||||
public class RouteInfo {
|
public class PositionRouteInfo {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 主键
|
* 主键
|
|
@ -0,0 +1,28 @@
|
||||||
|
package com.muyu.domain.req;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author DongZl
|
||||||
|
* @description: 车辆选择轨迹
|
||||||
|
* @Date 2023-11-27 上午 11:04
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class CheckPositionReq {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* VIN
|
||||||
|
*/
|
||||||
|
private String vin;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 轨迹标签
|
||||||
|
*/
|
||||||
|
private String positionCode;
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
package com.muyu.domain.req;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author DongZl
|
||||||
|
* @description:
|
||||||
|
* @Date 2023-11-27 下午 02:37
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class GearReq {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* VIN
|
||||||
|
*/
|
||||||
|
private String vin;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 档位
|
||||||
|
*/
|
||||||
|
private String gear;
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
package com.muyu.domain.req;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author DongZl
|
||||||
|
* @description: msg请求实体类
|
||||||
|
* @Date 2023-11-27 下午 02:15
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class MsgReq {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 车辆VIN
|
||||||
|
*/
|
||||||
|
private String vin;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 消息编码
|
||||||
|
*/
|
||||||
|
private String msgCode;
|
||||||
|
}
|
|
@ -6,6 +6,8 @@ import lombok.Builder;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author DongZl
|
* @author DongZl
|
||||||
* @description: 车辆实例控制层响应结果
|
* @description: 车辆实例控制层响应结果
|
||||||
|
@ -25,12 +27,43 @@ public class VehicleInstanceResp {
|
||||||
/**
|
/**
|
||||||
* 是否在线
|
* 是否在线
|
||||||
*/
|
*/
|
||||||
public boolean isOnline;
|
private boolean isOnline;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 路线轨迹编码
|
||||||
|
*/
|
||||||
|
private String positionCode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 路线剩余定位点
|
||||||
|
*/
|
||||||
|
private Integer positionLength = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 消息状态
|
||||||
|
*/
|
||||||
|
private String msgCode;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 档位
|
||||||
|
*/
|
||||||
|
private String gear = "P";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 里程
|
||||||
|
*/
|
||||||
|
private BigDecimal mileage;
|
||||||
|
|
||||||
public static VehicleInstanceResp instanceBuild (VehicleInstance vehicleInstance) {
|
public static VehicleInstanceResp instanceBuild (VehicleInstance vehicleInstance) {
|
||||||
return VehicleInstanceResp.builder()
|
return VehicleInstanceResp.builder()
|
||||||
.vin(vehicleInstance.getVin())
|
.vin(vehicleInstance.getVin())
|
||||||
.isOnline(vehicleInstance.isOnline())
|
.isOnline(vehicleInstance.isOnline())
|
||||||
|
.positionCode(vehicleInstance.getPositionCode())
|
||||||
|
.positionLength(vehicleInstance.getPositionQueue().size())
|
||||||
|
.gear(vehicleInstance.getVehicleData().getGear())
|
||||||
|
.msgCode(vehicleInstance.getMsgCode())
|
||||||
|
.mileage(vehicleInstance.getVehicleData().getMileage())
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
package com.muyu.mapper;
|
package com.muyu.mapper;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
import com.muyu.domain.RouteInfo;
|
import com.muyu.domain.PositionRouteInfo;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author DongZl
|
* @author DongZl
|
||||||
* @description: 轨迹路径 mapper
|
* @description: 轨迹路径 mapper
|
||||||
* @Date 2023-11-20 上午 09:32
|
* @Date 2023-11-20 上午 09:32
|
||||||
*/
|
*/
|
||||||
public interface RouteMapper extends BaseMapper<RouteInfo> {
|
public interface PositionRouteMapper extends BaseMapper<PositionRouteInfo> {
|
||||||
}
|
}
|
|
@ -1,7 +1,7 @@
|
||||||
package com.muyu.service;
|
package com.muyu.service;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
import com.muyu.domain.RouteInfo;
|
import com.muyu.domain.PositionRouteInfo;
|
||||||
import com.muyu.domain.model.PositionModel;
|
import com.muyu.domain.model.PositionModel;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -11,7 +11,7 @@ import java.util.List;
|
||||||
* @description: 路径轨迹业务层
|
* @description: 路径轨迹业务层
|
||||||
* @Date 2023-11-20 上午 09:33
|
* @Date 2023-11-20 上午 09:33
|
||||||
*/
|
*/
|
||||||
public interface RouteService extends IService<RouteInfo> {
|
public interface PositionRouteService extends IService<PositionRouteInfo> {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -20,4 +20,11 @@ public interface RouteService extends IService<RouteInfo> {
|
||||||
* @return 轨迹ID
|
* @return 轨迹ID
|
||||||
*/
|
*/
|
||||||
public List<PositionModel> getPositionModelByRouteId(Long routeId);
|
public List<PositionModel> getPositionModelByRouteId(Long routeId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据轨迹 编号查询 估计详情
|
||||||
|
* @param positionCode 轨迹编号
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
List<PositionModel> getPositionModelByRouteName (String positionCode);
|
||||||
}
|
}
|
|
@ -1,6 +1,9 @@
|
||||||
package com.muyu.service;
|
package com.muyu.service;
|
||||||
|
|
||||||
import com.muyu.domain.Vehicle;
|
import com.muyu.domain.Vehicle;
|
||||||
|
import com.muyu.domain.req.CheckPositionReq;
|
||||||
|
import com.muyu.domain.req.GearReq;
|
||||||
|
import com.muyu.domain.req.MsgReq;
|
||||||
import com.muyu.domain.req.VehicleInstanceListReq;
|
import com.muyu.domain.req.VehicleInstanceListReq;
|
||||||
import com.muyu.domain.resp.VehicleInstanceResp;
|
import com.muyu.domain.resp.VehicleInstanceResp;
|
||||||
|
|
||||||
|
@ -44,4 +47,22 @@ public interface VehicleInstanceService {
|
||||||
* @param vin vin
|
* @param vin vin
|
||||||
*/
|
*/
|
||||||
void vehicleClientClose (String vin);
|
void vehicleClientClose (String vin);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 选择车辆轨迹
|
||||||
|
* @param checkPositionReq 切换轨迹
|
||||||
|
*/
|
||||||
|
void checkPosition (CheckPositionReq checkPositionReq);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 车辆消息操作
|
||||||
|
* @param msgReq
|
||||||
|
*/
|
||||||
|
void msg (MsgReq msgReq);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置档位
|
||||||
|
* @param gearReq
|
||||||
|
*/
|
||||||
|
void gear (GearReq gearReq);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,54 @@
|
||||||
|
package com.muyu.service.impl;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson2.JSONArray;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.muyu.domain.PositionRouteInfo;
|
||||||
|
import com.muyu.domain.model.PositionModel;
|
||||||
|
import com.muyu.mapper.PositionRouteMapper;
|
||||||
|
import com.muyu.service.PositionRouteService;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author DongZl
|
||||||
|
* @description: 路径轨迹业务实现层
|
||||||
|
* @Date 2023-11-20 上午 09:34
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class PositionRouteServiceImpl extends ServiceImpl<PositionRouteMapper, PositionRouteInfo> implements PositionRouteService {
|
||||||
|
/**
|
||||||
|
* 根据轨迹ID获取轨迹详情
|
||||||
|
*
|
||||||
|
* @param routeId 轨迹ID
|
||||||
|
*
|
||||||
|
* @return 轨迹ID
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<PositionModel> getPositionModelByRouteId (Long routeId) {
|
||||||
|
PositionRouteInfo positionRouteInfo = this.getById(routeId);
|
||||||
|
return JSONArray.parseArray(positionRouteInfo.getRouteData(), String.class)
|
||||||
|
.stream()
|
||||||
|
.map(PositionModel::strBuild)
|
||||||
|
.toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据轨迹 编号查询 估计详情
|
||||||
|
*
|
||||||
|
* @param positionCode 轨迹编号
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<PositionModel> getPositionModelByRouteName (String positionCode) {
|
||||||
|
LambdaQueryWrapper<PositionRouteInfo> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
queryWrapper.eq(PositionRouteInfo::getName, positionCode);
|
||||||
|
PositionRouteInfo positionRouteInfo = getOne(queryWrapper);
|
||||||
|
return JSONArray.parseArray(positionRouteInfo.getRouteData(), String.class)
|
||||||
|
.stream()
|
||||||
|
.map(PositionModel::strBuild)
|
||||||
|
.toList();
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,35 +0,0 @@
|
||||||
package com.muyu.service.impl;
|
|
||||||
|
|
||||||
import com.alibaba.fastjson2.JSONArray;
|
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
||||||
import com.muyu.domain.RouteInfo;
|
|
||||||
import com.muyu.domain.model.PositionModel;
|
|
||||||
import com.muyu.mapper.RouteMapper;
|
|
||||||
import com.muyu.service.RouteService;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author DongZl
|
|
||||||
* @description: 路径轨迹业务实现层
|
|
||||||
* @Date 2023-11-20 上午 09:34
|
|
||||||
*/
|
|
||||||
@Service
|
|
||||||
public class RouteServiceImpl extends ServiceImpl<RouteMapper, RouteInfo> implements RouteService {
|
|
||||||
/**
|
|
||||||
* 根据轨迹ID获取轨迹详情
|
|
||||||
*
|
|
||||||
* @param routeId 轨迹ID
|
|
||||||
*
|
|
||||||
* @return 轨迹ID
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public List<PositionModel> getPositionModelByRouteId (Long routeId) {
|
|
||||||
RouteInfo routeInfo = this.getById(routeId);
|
|
||||||
return JSONArray.parseArray(routeInfo.getRouteData(), String.class)
|
|
||||||
.stream()
|
|
||||||
.map(PositionModel::strBuild)
|
|
||||||
.toList();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,15 +1,24 @@
|
||||||
package com.muyu.service.impl;
|
package com.muyu.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.muyu.domain.PositionRouteInfo;
|
||||||
import com.muyu.domain.Vehicle;
|
import com.muyu.domain.Vehicle;
|
||||||
|
import com.muyu.domain.model.PositionModel;
|
||||||
|
import com.muyu.domain.req.CheckPositionReq;
|
||||||
|
import com.muyu.domain.req.GearReq;
|
||||||
|
import com.muyu.domain.req.MsgReq;
|
||||||
import com.muyu.domain.req.VehicleInstanceListReq;
|
import com.muyu.domain.req.VehicleInstanceListReq;
|
||||||
import com.muyu.domain.resp.VehicleInstanceResp;
|
import com.muyu.domain.resp.VehicleInstanceResp;
|
||||||
|
import com.muyu.service.PositionRouteService;
|
||||||
import com.muyu.service.VehicleInstanceService;
|
import com.muyu.service.VehicleInstanceService;
|
||||||
import com.muyu.vehicle.VehicleInstance;
|
import com.muyu.vehicle.VehicleInstance;
|
||||||
import com.muyu.vehicle.core.LocalContainer;
|
import com.muyu.vehicle.core.LocalContainer;
|
||||||
import com.muyu.vehicle.model.VehicleData;
|
import com.muyu.vehicle.model.VehicleData;
|
||||||
import com.muyu.vehicle.model.properties.MqttProperties;
|
import com.muyu.vehicle.model.properties.MqttProperties;
|
||||||
import lombok.extern.log4j.Log4j2;
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -22,6 +31,10 @@ import java.util.List;
|
||||||
@Log4j2
|
@Log4j2
|
||||||
@Service
|
@Service
|
||||||
public class VehicleInstanceServiceImpl implements VehicleInstanceService {
|
public class VehicleInstanceServiceImpl implements VehicleInstanceService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private PositionRouteService positionRouteService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据车辆生成车辆实例
|
* 根据车辆生成车辆实例
|
||||||
*
|
*
|
||||||
|
@ -100,4 +113,48 @@ public class VehicleInstanceServiceImpl implements VehicleInstanceService {
|
||||||
vehicleInstance.closeClient();
|
vehicleInstance.closeClient();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 选择车辆轨迹
|
||||||
|
*
|
||||||
|
* @param checkPositionReq 切换轨迹
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void checkPosition (CheckPositionReq checkPositionReq) {
|
||||||
|
VehicleInstance vehicleInstance = LocalContainer.getVehicleInstance(checkPositionReq.getVin());
|
||||||
|
List<PositionModel> positionModelList =
|
||||||
|
this.positionRouteService.getPositionModelByRouteName(checkPositionReq.getPositionCode());
|
||||||
|
vehicleInstance.settingPosition(positionModelList);
|
||||||
|
vehicleInstance.setPositionCode(checkPositionReq.getPositionCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 车辆消息操作
|
||||||
|
*
|
||||||
|
* @param msgReq
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void msg (MsgReq msgReq) {
|
||||||
|
VehicleInstance vehicleInstance = LocalContainer.getVehicleInstance(msgReq.getVin());
|
||||||
|
switch (msgReq.getMsgCode()){
|
||||||
|
case "上报" -> {
|
||||||
|
vehicleInstance.initVehicleThread();
|
||||||
|
vehicleInstance.startSend();
|
||||||
|
}
|
||||||
|
case "暂停" -> vehicleInstance.pauseSend();
|
||||||
|
case "停止" -> vehicleInstance.stopSend();
|
||||||
|
default -> throw new RuntimeException("车辆消息事件错误");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置档位
|
||||||
|
*
|
||||||
|
* @param gearReq
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void gear (GearReq gearReq) {
|
||||||
|
VehicleInstance vehicleInstance = LocalContainer.getVehicleInstance(gearReq.getVin());
|
||||||
|
vehicleInstance.setGear(gearReq.getGear());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,10 +43,15 @@ import static com.muyu.common.SystemConstant.*;
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class VehicleInstance {
|
public class VehicleInstance {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 路线轨迹编码
|
||||||
|
*/
|
||||||
|
private String positionCode;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 路径队列
|
* 路径队列
|
||||||
*/
|
*/
|
||||||
private final LinkedBlockingQueue<PositionModel> positionQueue = new LinkedBlockingQueue<>();
|
private LinkedBlockingQueue<PositionModel> positionQueue = new LinkedBlockingQueue<>();
|
||||||
/**
|
/**
|
||||||
* 车辆
|
* 车辆
|
||||||
*/
|
*/
|
||||||
|
@ -63,7 +68,10 @@ public class VehicleInstance {
|
||||||
* 车辆工作线程
|
* 车辆工作线程
|
||||||
*/
|
*/
|
||||||
private VehicleThread vehicleThread;
|
private VehicleThread vehicleThread;
|
||||||
|
/**
|
||||||
|
* 消息状态
|
||||||
|
*/
|
||||||
|
private String msgCode;
|
||||||
/**
|
/**
|
||||||
* 线程提交回调
|
* 线程提交回调
|
||||||
*/
|
*/
|
||||||
|
@ -170,6 +178,7 @@ public class VehicleInstance {
|
||||||
* @param positionModelList 路线集合
|
* @param positionModelList 路线集合
|
||||||
*/
|
*/
|
||||||
public void settingPosition(List<PositionModel> positionModelList){
|
public void settingPosition(List<PositionModel> positionModelList){
|
||||||
|
positionQueue.clear();
|
||||||
positionModelList.forEach(positionQueue::offer);
|
positionModelList.forEach(positionQueue::offer);
|
||||||
log.info("车辆:{} 设置路径成功", this.getVin());
|
log.info("车辆:{} 设置路径成功", this.getVin());
|
||||||
}
|
}
|
||||||
|
@ -178,10 +187,12 @@ public class VehicleInstance {
|
||||||
* 初始化线程
|
* 初始化线程
|
||||||
*/
|
*/
|
||||||
public void initVehicleThread() {
|
public void initVehicleThread() {
|
||||||
|
if (this.positionCode == null){
|
||||||
|
throw new RuntimeException("车辆["+getVin()+"]为选中路径");
|
||||||
|
}
|
||||||
VehicleThread vehicleThread = new VehicleThread();
|
VehicleThread vehicleThread = new VehicleThread();
|
||||||
vehicleThread.setVehicleInstance(this);
|
vehicleThread.setVehicleInstance(this);
|
||||||
this.setVehicleThread(vehicleThread);
|
this.setVehicleThread(vehicleThread);
|
||||||
this.vehicleThread.pause();
|
|
||||||
ScheduledFuture<?> scheduledFuture = ThreadPool.submit(vehicleThread);
|
ScheduledFuture<?> scheduledFuture = ThreadPool.submit(vehicleThread);
|
||||||
this.setScheduledFuture(scheduledFuture);
|
this.setScheduledFuture(scheduledFuture);
|
||||||
log.info("初始化车辆上报模拟线程开始:[{}]", this.getVin());
|
log.info("初始化车辆上报模拟线程开始:[{}]", this.getVin());
|
||||||
|
@ -191,21 +202,27 @@ public class VehicleInstance {
|
||||||
* 开始上报线程
|
* 开始上报线程
|
||||||
*/
|
*/
|
||||||
public void startSend() {
|
public void startSend() {
|
||||||
|
this.msgCode = "上报";
|
||||||
this.vehicleThread.resume();
|
this.vehicleThread.resume();
|
||||||
|
log.info("车辆[{}],开始上报", this.getVin());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 暂停上报线程
|
* 暂停上报线程
|
||||||
*/
|
*/
|
||||||
public void pauseSend() {
|
public void pauseSend() {
|
||||||
|
this.msgCode = "暂停";
|
||||||
this.vehicleThread.pause();
|
this.vehicleThread.pause();
|
||||||
|
log.info("车辆[{}],暂停上报", this.getVin());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 结束发送
|
* 结束发送
|
||||||
*/
|
*/
|
||||||
public void stopSend() {
|
public void stopSend() {
|
||||||
|
this.msgCode = "停止";
|
||||||
this.vehicleThread.stop();
|
this.vehicleThread.stop();
|
||||||
|
log.info("车辆[{}],停止上报", this.getVin());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -392,9 +392,27 @@ public class VehicleData {
|
||||||
public static VehicleData vehicleBuild (Vehicle vehicle) {
|
public static VehicleData vehicleBuild (Vehicle vehicle) {
|
||||||
return VehicleData.builder()
|
return VehicleData.builder()
|
||||||
.vin(vehicle.getVin())
|
.vin(vehicle.getVin())
|
||||||
|
.gear("P")
|
||||||
.remainingBattery(vehicle.getRemainingBattery())
|
.remainingBattery(vehicle.getRemainingBattery())
|
||||||
.batteryLevel(vehicle.getBatteryLevel())
|
.batteryLevel(vehicle.getBatteryLevel())
|
||||||
.mileage(vehicle.getTotalMileage())
|
.mileage(vehicle.getTotalMileage())
|
||||||
|
.vehicleStatus(1)
|
||||||
|
.chargingStatus(1)
|
||||||
|
.operatingStatus(1)
|
||||||
|
.socStatus(1)
|
||||||
|
.chargingEnergyStorageStatus(1)
|
||||||
|
.driveMotorStatus(1)
|
||||||
|
.positionStatus(1)
|
||||||
|
.easStatus(1)
|
||||||
|
.ptcStatus(1)
|
||||||
|
.epsStatus(1)
|
||||||
|
.absStatus(1)
|
||||||
|
.mcuStatus(1)
|
||||||
|
.heatingStatus(1)
|
||||||
|
.batteryStatus(1)
|
||||||
|
.batteryInsulationStatus(1)
|
||||||
|
.dcdcStatus(1)
|
||||||
|
.chgStatus(1)
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
insert into vehicle(vin, remaining_battery, total_mileage, battery_level, create_time)
|
insert into vehicle(vin, remaining_battery, total_mileage, battery_level, create_time)
|
||||||
values
|
values
|
||||||
('VIN1234567891234',45000,12.483, 45000, CURRENT_TIMESTAMP()),
|
('VIN12345678912345',45000,12.483, 45000, CURRENT_TIMESTAMP()),
|
||||||
('VIN123456789DIJE',45000,23.696, 45000, CURRENT_TIMESTAMP());
|
('VIN123456789DIJE4',45000,23.696, 45000, CURRENT_TIMESTAMP());
|
||||||
|
|
||||||
insert into route_info (id, name, data, create_time)
|
insert into route_info (id, name, data, create_time)
|
||||||
values
|
values
|
||||||
|
|
|
@ -8,7 +8,7 @@ create table if not exists vehicle (
|
||||||
|
|
||||||
create table if not exists route_info (
|
create table if not exists route_info (
|
||||||
`id` int primary key not null ,
|
`id` int primary key not null ,
|
||||||
`name` char (50) not null,
|
`name` char (3) not null,
|
||||||
`data` CLOB not null,
|
`data` CLOB not null,
|
||||||
`create_time` datetime not null
|
`create_time` datetime not null
|
||||||
) ;
|
) ;
|
||||||
|
|
Loading…
Reference in New Issue