feat:rabbit,实时数据,实时轨迹

master
hbr 2024-06-18 21:21:39 +08:00
parent 640b80bfb7
commit 48cf2749c4
7 changed files with 272 additions and 61 deletions

View File

@ -49,6 +49,12 @@ public class BusinessServiceImpl extends ServiceImpl<BusinessMapper, Business>
@Autowired
private RedisService redisService;
/**
* rabbitMq
*/
@Autowired
private RabbitTemplate rabbitTemplate;
/**
*
*
@ -101,7 +107,7 @@ public class BusinessServiceImpl extends ServiceImpl<BusinessMapper, Business>
.email(business.getBusinessEmail())
.phonenumber(business.getBusinessPhone())
.loginIp("111.229.102.61")
.roleId(Long.valueOf(101))
.roleId(101L)
.userType(String.valueOf(business.getId()))
.build();
Result add = remoteUserService.add(sysUser);
@ -137,12 +143,12 @@ public class BusinessServiceImpl extends ServiceImpl<BusinessMapper, Business>
}
if (business.getBusinessStates().equals("2")) {
SysUser sysUser = remoteUserService.userById(business.getId());
sysUser.setRoleId(Long.valueOf(2));
sysUser.setRoleId(2L);
remoteUserService.updateById(sysUser);
Entinfo build = Entinfo.builder()
.entCode("test_" + business.getId())
.ip("192.168.120.128")
.port(Integer.valueOf(3306 + Integer.valueOf(String.valueOf(business.getId())))).build();
.port(3306 + Integer.parseInt(String.valueOf(business.getId()))).build();
Entinfo entinfo =entinfoService.selectEntinfo(build);
if (entinfo==null){
extracted(business);
@ -150,12 +156,8 @@ public class BusinessServiceImpl extends ServiceImpl<BusinessMapper, Business>
}
}
@Autowired
private RabbitTemplate rabbitTemplate;
/**
* http URL
* http URL Mysql Docker
* @param business
*/
private void extracted(Business business) {
@ -190,16 +192,10 @@ public class BusinessServiceImpl extends ServiceImpl<BusinessMapper, Business>
new InputStreamReader(httpConn.getInputStream()));
String resultData = br.readLine();
System.out.println("从服务端返回结果: " + resultData);
// 7.关闭HttpURLConnection连接
httpConn.disconnect();
} catch (Exception e) {
throw new RuntimeException(e);
}
Entinfo build = Entinfo.builder()
.entCode("test_" + business.getId())
.ip("192.168.120.128")
.port(Integer.valueOf(3306 + Integer.valueOf(String.valueOf(business.getId())))).build();
.port(3306 + Integer.parseInt(String.valueOf(business.getId()))).build();
entinfoService.insertEntinfo(build);
rabbitTemplate.convertAndSend("zhiLian-vehicle-exchange",JSON.toJSONString(build),message ->{
message.getMessageProperties().setMessageId(UUID.randomUUID().toString());
@ -207,6 +203,13 @@ public class BusinessServiceImpl extends ServiceImpl<BusinessMapper, Business>
message.getMessageProperties().setDelay(5000);
return message;
} );
// 7.关闭HttpURLConnection连接
httpConn.disconnect();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
/**

View File

@ -30,7 +30,7 @@ import java.util.List;
public class IotDBSessionConfig {
private static Session session;
private static final String LOCAL_HOST = "192.168.120.128";
private static final String LOCAL_HOST = "10.3.44.51";
@Bean
public Session getSession() throws IoTDBConnectionException, StatementExecutionException {
if (session == null) {

View File

@ -0,0 +1,43 @@
package com.zhiLian.vehicle.controller;
import com.alibaba.fastjson2.JSON;
import com.zhiLian.common.core.domain.Result;
import com.zhiLian.common.core.web.controller.BaseController;
import com.zhiLian.common.core.web.page.TableDataInfo;
import com.zhiLian.common.log.annotation.Log;
import com.zhiLian.common.log.enums.BusinessType;
import com.zhiLian.common.redis.service.RedisService;
import com.zhiLian.vehicle.domain.Vehicle;
import com.zhiLian.vehicle.domain.VehicleInfo;
import com.zhiLian.vehicle.service.IVehicleService;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;
/**
* Controller
*
* @author BingRui.Hou
* @date 2024-05-27
*/
@Log4j2
@RestController
@RequestMapping("/vehicleInfo")
public class VehicleInfoController extends BaseController
{
@Autowired
private RedisTemplate<String,String> redisTemplate;
@GetMapping("/list/{vin}")
public Result vehicleInfoAllList(@PathVariable String vin){
String lastElement = redisTemplate.opsForList().index(vin, -1);
VehicleInfo vehicleInfo = JSON.parseObject(lastElement, VehicleInfo.class);
return Result.success(vehicleInfo);
}
}

View File

@ -45,20 +45,7 @@ public class ManyDataSource {
@Autowired
private RemoteBusinessService remoteBusinessService;
// @Autowired
// private EntInfoFeign entInfoFeign;
// @PostConstruct
// public void init() {
// new Thread(() -> {
// try {
// Thread.sleep(10000);
// } catch (InterruptedException e) {
// throw new RuntimeException(e);
// }
//
// }).start();
// }
//调用注解 添加队列名称
@RabbitListener(queuesToDeclare = {@Queue(name = "zhiLian-vehicle-exchange")})
@ -111,27 +98,6 @@ public class ManyDataSource {
}};
List<Entinfo> list = remoteBusinessService.listAll();
databaseNameList.addAll(list);
// List<String> entinfo = redisTemplate.opsForList().range("entinfo", 0, -1);
// entinfo.forEach(string -> {
// Entinfo entInfo = JSON.parseObject(String.valueOf(string), Entinfo.class);
// databaseNameList.add(entInfo);
// });
// List<Entinfo> entinfos = entInfoFeign.listAll();
// databaseNameList.addAll(entinfos);
// if(SecurityUtils.getLoginUser() == null){
// return databaseNameList;
// }else{
// Long storeId = SecurityUtils.getLoginUser().getUserid();
// SysUser sysUser = remoteUserService.selectByUserId(storeId);
// String s = redisService.getCacheObject(String.valueOf(sysUser.getUserType()));
// EntInfo entInfo = JSON.parseObject(s, EntInfo.class);
// databaseNameList.add(entInfo);
// return databaseNameList;
// }
return databaseNameList;
}
@ -140,7 +106,6 @@ public class ManyDataSource {
@Bean
@Primary
public DynamicDataSource dynamicDataSource(DruidDataSourceFactory druidDataSourceFactory) {
//查企业
Map<Object, Object> dataSourceMap = new HashMap<>();
dataSourceInfoList()
@ -157,6 +122,4 @@ public class ManyDataSource {
dynamicDataSource.setDefineTargetDataSources(dataSourceMap);
return dynamicDataSource;
}
}

View File

@ -21,14 +21,15 @@ import org.springframework.stereotype.Component;
@Aspect
@Component
public class DataSourceAsp {
@Lazy
@Autowired
private RemoteUserService remoteUserService;
@Pointcut("execution(public * com.zhiLian.vehicle.controller.*Controller.*(..))")
public void pointcut () {
}
@Lazy
@Autowired
private RemoteUserService remoteUserService;
/**
*
*/

View File

@ -20,7 +20,6 @@ import java.sql.SQLException;
@Component
public class DruidDataSourceFactory {
/**
* @Description:
* @Author Dongzl

View File

@ -0,0 +1,202 @@
package com.zhiLian.vehicle.domain;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
/**
*
* @author YunFei.Du
* @date 9:03 2024/6/4
*/
@Data
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
public class VehicleInfo {
/**
* VIN
*/
private String vin;
private Long startTime;
/**
*
*/
private String longitude;
/**
*
*/
private String latitude;
/**
*
*/
private String speed;
/**
*
*/
private String mileage;
/**
*
*/
private String voltage;
/**
*
*/
private String current;
/**
*
*/
private String resistance;
private String gear;
/**
*
*/
private String accelerationPedal;
/**
*
*/
private String brakePedal;
/**
*
*/
private String fuelConsumptionRate;
/**
*
*/
private String motorControllerTemperature;
/**
*
*/
private String motorSpeed;
/**
*
*/
private String motorTorque;
/**
*
*/
private String motorTemperature;
/**
*
*/
private String motorVoltage;
/**
*
*/
private String motorCurrent;
/**
*
*/
private String remainingBattery;
/**
*
*/
private String maximumFeedbackPower;
/**
*
*/
private String maximumDischargePower;
/**
* BMS
*/
private String selfCheckCounter;
/**
*
*/
private String totalBatteryCurrent;
/**
* V3
*/
private String totalBatteryVoltage;
/**
*
*/
private String singleBatteryMaxVoltage;
/**
*
*/
private String singleBatteryMinVoltage;
/**
*
*/
private String singleBatteryMaxTemperature;
/**
*
*/
private String singleBatteryMinTemperature;
/**
*
*/
private String availableBatteryCapacity;
/**
*
*/
private String vehicleStatus;
/**
*
*/
private String chargingStatus;
/**
*
*/
private String operatingStatus;
/**
* SOC
*/
private String socStatus;
/**
*
*/
private String chargingEnergyStorageStatus;
/**
*
*/
private String driveMotorStatus;
/**
*
*/
private String positionStatus;
/**
* EAS()
*/
private String easStatus;
/**
* PTC()
*/
private String ptcStatus;
/**
* EPS()
*/
private String epsStatus;
/**
* ABS()
*/
private String absStatus;
/**
* MCU(/)
*/
private String mcuStatus;
/**
*
*/
private String heatingStatus;
/**
*
*/
private String batteryStatus;
/**
*
*/
private String batteryInsulationStatus;
/**
* DCDC()
*/
private String dcdcStatus;
/**
* CHG()
*/
private String chgStatus;
}