From 48cf2749c4d50cd8544e569d965a9127470e7c9f Mon Sep 17 00:00:00 2001 From: hbr <1991483710@qq.com> Date: Tue, 18 Jun 2024 21:21:39 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9Arabbit=EF=BC=8C=E5=AE=9E=E6=97=B6?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=EF=BC=8C=E5=AE=9E=E6=97=B6=E8=BD=A8=E8=BF=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/BusinessServiceImpl.java | 41 ++-- .../iotdb/config/IotDBSessionConfig.java | 2 +- .../controller/VehicleInfoController.java | 43 ++++ .../vehicle/datasource/ManyDataSource.java | 37 ---- .../datasource/config/DataSourceAsp.java | 7 +- .../factory/DruidDataSourceFactory.java | 1 - .../zhiLian/vehicle/domain/VehicleInfo.java | 202 ++++++++++++++++++ 7 files changed, 272 insertions(+), 61 deletions(-) create mode 100644 zhiLian-vehicle/zhiLian-vehicle-service/src/main/java/com/zhiLian/vehicle/controller/VehicleInfoController.java create mode 100644 zhiLian-vehicle/zhiLian-vehicle-service/src/main/java/com/zhiLian/vehicle/domain/VehicleInfo.java diff --git a/zhiLian-business/zhiLian-data-service/src/main/java/com/zhiLian/business/service/impl/BusinessServiceImpl.java b/zhiLian-business/zhiLian-data-service/src/main/java/com/zhiLian/business/service/impl/BusinessServiceImpl.java index 04fc5aa..638e57c 100644 --- a/zhiLian-business/zhiLian-data-service/src/main/java/com/zhiLian/business/service/impl/BusinessServiceImpl.java +++ b/zhiLian-business/zhiLian-data-service/src/main/java/com/zhiLian/business/service/impl/BusinessServiceImpl.java @@ -49,6 +49,12 @@ public class BusinessServiceImpl extends ServiceImpl @Autowired private RedisService redisService; + /** + * rabbitMq 发送消息 + */ + @Autowired + private RabbitTemplate rabbitTemplate; + /** * 查询企业 * @@ -101,7 +107,7 @@ public class BusinessServiceImpl extends ServiceImpl .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 } 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 } } - @Autowired - private RabbitTemplate rabbitTemplate; - - /** - * http URL 链接 + * http URL 进行创建Mysql Docker * @param business */ private void extracted(Business business) { @@ -190,23 +192,24 @@ public class BusinessServiceImpl extends ServiceImpl new InputStreamReader(httpConn.getInputStream())); String resultData = br.readLine(); System.out.println("从服务端返回结果: " + resultData); + Entinfo build = Entinfo.builder() + .entCode("test_" + business.getId()) + .ip("192.168.120.128") + .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()); + //设置消息延迟时间为5秒 + message.getMessageProperties().setDelay(5000); + return message; + } ); // 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(); - entinfoService.insertEntinfo(build); - rabbitTemplate.convertAndSend("zhiLian-vehicle-exchange",JSON.toJSONString(build),message ->{ - message.getMessageProperties().setMessageId(UUID.randomUUID().toString()); - //设置消息延迟时间为5秒 - message.getMessageProperties().setDelay(5000); - return message; - } ); + } /** diff --git a/zhiLian-iotdb/src/main/java/com/zhiLian/iotdb/config/IotDBSessionConfig.java b/zhiLian-iotdb/src/main/java/com/zhiLian/iotdb/config/IotDBSessionConfig.java index b58e28a..faf5eec 100644 --- a/zhiLian-iotdb/src/main/java/com/zhiLian/iotdb/config/IotDBSessionConfig.java +++ b/zhiLian-iotdb/src/main/java/com/zhiLian/iotdb/config/IotDBSessionConfig.java @@ -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) { diff --git a/zhiLian-vehicle/zhiLian-vehicle-service/src/main/java/com/zhiLian/vehicle/controller/VehicleInfoController.java b/zhiLian-vehicle/zhiLian-vehicle-service/src/main/java/com/zhiLian/vehicle/controller/VehicleInfoController.java new file mode 100644 index 0000000..ab11f39 --- /dev/null +++ b/zhiLian-vehicle/zhiLian-vehicle-service/src/main/java/com/zhiLian/vehicle/controller/VehicleInfoController.java @@ -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 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); + } +} diff --git a/zhiLian-vehicle/zhiLian-vehicle-service/src/main/java/com/zhiLian/vehicle/datasource/ManyDataSource.java b/zhiLian-vehicle/zhiLian-vehicle-service/src/main/java/com/zhiLian/vehicle/datasource/ManyDataSource.java index 1a39ad6..e567c8c 100644 --- a/zhiLian-vehicle/zhiLian-vehicle-service/src/main/java/com/zhiLian/vehicle/datasource/ManyDataSource.java +++ b/zhiLian-vehicle/zhiLian-vehicle-service/src/main/java/com/zhiLian/vehicle/datasource/ManyDataSource.java @@ -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 list = remoteBusinessService.listAll(); databaseNameList.addAll(list); - -// List entinfo = redisTemplate.opsForList().range("entinfo", 0, -1); -// entinfo.forEach(string -> { -// Entinfo entInfo = JSON.parseObject(String.valueOf(string), Entinfo.class); -// databaseNameList.add(entInfo); -// }); - -// List 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 dataSourceMap = new HashMap<>(); dataSourceInfoList() @@ -157,6 +122,4 @@ public class ManyDataSource { dynamicDataSource.setDefineTargetDataSources(dataSourceMap); return dynamicDataSource; } - - } diff --git a/zhiLian-vehicle/zhiLian-vehicle-service/src/main/java/com/zhiLian/vehicle/datasource/config/DataSourceAsp.java b/zhiLian-vehicle/zhiLian-vehicle-service/src/main/java/com/zhiLian/vehicle/datasource/config/DataSourceAsp.java index b2408d9..3de90aa 100644 --- a/zhiLian-vehicle/zhiLian-vehicle-service/src/main/java/com/zhiLian/vehicle/datasource/config/DataSourceAsp.java +++ b/zhiLian-vehicle/zhiLian-vehicle-service/src/main/java/com/zhiLian/vehicle/datasource/config/DataSourceAsp.java @@ -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; + /** * 的每一個方法執行之前 執行的處理 */ diff --git a/zhiLian-vehicle/zhiLian-vehicle-service/src/main/java/com/zhiLian/vehicle/datasource/config/factory/DruidDataSourceFactory.java b/zhiLian-vehicle/zhiLian-vehicle-service/src/main/java/com/zhiLian/vehicle/datasource/config/factory/DruidDataSourceFactory.java index f4a0966..e62e0b0 100644 --- a/zhiLian-vehicle/zhiLian-vehicle-service/src/main/java/com/zhiLian/vehicle/datasource/config/factory/DruidDataSourceFactory.java +++ b/zhiLian-vehicle/zhiLian-vehicle-service/src/main/java/com/zhiLian/vehicle/datasource/config/factory/DruidDataSourceFactory.java @@ -20,7 +20,6 @@ import java.sql.SQLException; @Component public class DruidDataSourceFactory { - /** * @Description: 根据传递的数据源信息测试数据库连接 * @Author Dongzl diff --git a/zhiLian-vehicle/zhiLian-vehicle-service/src/main/java/com/zhiLian/vehicle/domain/VehicleInfo.java b/zhiLian-vehicle/zhiLian-vehicle-service/src/main/java/com/zhiLian/vehicle/domain/VehicleInfo.java new file mode 100644 index 0000000..8c8242f --- /dev/null +++ b/zhiLian-vehicle/zhiLian-vehicle-service/src/main/java/com/zhiLian/vehicle/domain/VehicleInfo.java @@ -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; +}