From 6c3d48bd33f3a3cc8f5d826d14582a71c0f81f8c Mon Sep 17 00:00:00 2001 From: gukaixuan <1> Date: Fri, 15 Sep 2023 20:43:33 +0800 Subject: [PATCH] car-collect --- .gitignore | 46 +++++ Dockerfile | 22 ++ pom.xml | 26 +++ ruoyi-collect-common/.gitignore | 38 ++++ ruoyi-collect-common/pom.xml | 97 +++++++++ .../java/com/ruoyi/collect/domain/Car.java | 86 ++++++++ .../com/ruoyi/collect/domain/CarBsRecord.java | 37 ++++ .../com/ruoyi/collect/domain/CarFence.java | 123 ++++++++++++ .../com/ruoyi/collect/domain/CarRecord.java | 47 +++++ .../java/com/ruoyi/collect/domain/Emp.java | 44 ++++ .../ruoyi/collect/domain/EmpMiddleCar.java | 52 +++++ .../java/com/ruoyi/collect/domain/Fence.java | 73 +++++++ .../com/ruoyi/collect/domain/FenceRecord.java | 37 ++++ .../java/com/ruoyi/collect/domain/Firm.java | 56 ++++++ .../ruoyi/collect/domain/Identification.java | 35 ++++ .../java/com/ruoyi/collect/domain/Type.java | 11 + .../ruoyi/collect/domain/VehicleMessage.java | 114 +++++++++++ .../domain/cache/fence/FenceIdTypeCache.java | 29 +++ .../cache/fence/FenceInfoTypeCache.java | 29 +++ ruoyi-collect-remote/.gitignore | 38 ++++ ruoyi-collect-remote/pom.xml | 29 +++ ruoyi-collect-server/.gitignore | 38 ++++ ruoyi-collect-server/pom.xml | 91 +++++++++ .../collect/RuoYiCollectApplication.java | 34 ++++ .../com/ruoyi/collect/cache/CacheItem.java | 41 ++++ .../collect/cache/service/CacheService.java | 40 ++++ .../cache/service/impl/CacheServiceImpl.java | 91 +++++++++ .../com/ruoyi/collect/config/ConsumeTest.java | 103 ++++++++++ .../com/ruoyi/collect/config/KafkaTopic.java | 36 ++++ .../com/ruoyi/collect/config/ProductTest.java | 78 +++++++ .../config/RabbitmqConsumeMessage.java | 57 ++++++ .../config/RabbitmqConsumeSendEmail.java | 76 +++++++ .../collect/config/RabbitmqConsumeStart.java | 87 ++++++++ .../collect/config/RedisFinalVariable.java | 13 ++ .../controller/BusinessController.java | 81 ++++++++ .../collect/controller/CarController.java | 190 ++++++++++++++++++ .../collect/controller/EmpController.java | 67 ++++++ .../controller/IdentificationController.java | 48 +++++ .../collect/controller/SendController.java | 105 ++++++++++ .../ruoyi/collect/mapper/BusinessMapper.java | 30 +++ .../com/ruoyi/collect/mapper/CarMapper.java | 51 +++++ .../com/ruoyi/collect/mapper/EmpMapper.java | 23 +++ .../collect/mapper/IdentificationMapper.java | 23 +++ .../collect/service/BusinessService.java | 25 +++ .../com/ruoyi/collect/service/CarService.java | 37 ++++ .../com/ruoyi/collect/service/EmpService.java | 21 ++ .../collect/service/IElectronicFence.java | 19 ++ .../service/IdentificationService.java | 21 ++ .../service/impl/BusinessServiceImpl.java | 79 ++++++++ .../collect/service/impl/CarServiceImpl.java | 169 ++++++++++++++++ .../service/impl/ElectronicdFenceimpl.java | 186 +++++++++++++++++ .../collect/service/impl/EmpServiceImpl.java | 50 +++++ .../impl/IdentificationServiceImpl.java | 67 ++++++ .../com/ruoyi/collect/utils/FenceUtils.java | 77 +++++++ .../collect/utils/Latitudelongitude.java | 9 + .../java/com/ruoyi/collect/utils/Text.java | 58 ++++++ .../src/main/resources/banner.txt | 10 + .../src/main/resources/bootstrap.yml | 47 +++++ .../src/main/resources/logback.xml | 74 +++++++ .../mapper/collect/BusinessMapper.xml | 55 +++++ .../resources/mapper/collect/CarMapper.xml | 149 ++++++++++++++ .../resources/mapper/collect/EmpMapper.xml | 22 ++ .../mapper/collect/IdentificationMapper.xml | 18 ++ ruoyi-vehicle-cache/pom.xml | 25 +++ .../ruoyi-business-cache/.gitignore | 38 ++++ .../ruoyi-business-cache/pom.xml | 28 +++ .../ruoyi/vehicle/cache/fence/FenceCache.java | 31 +++ .../cache/fence/VehicleFenceCache.java | 31 +++ .../cache/fence/VehicleFenceCacheService.java | 29 +++ ...ot.autoconfigure.AutoConfiguration.imports | 1 + 70 files changed, 3848 insertions(+) create mode 100644 .gitignore create mode 100644 Dockerfile create mode 100644 pom.xml create mode 100644 ruoyi-collect-common/.gitignore create mode 100644 ruoyi-collect-common/pom.xml create mode 100644 ruoyi-collect-common/src/main/java/com/ruoyi/collect/domain/Car.java create mode 100644 ruoyi-collect-common/src/main/java/com/ruoyi/collect/domain/CarBsRecord.java create mode 100644 ruoyi-collect-common/src/main/java/com/ruoyi/collect/domain/CarFence.java create mode 100644 ruoyi-collect-common/src/main/java/com/ruoyi/collect/domain/CarRecord.java create mode 100644 ruoyi-collect-common/src/main/java/com/ruoyi/collect/domain/Emp.java create mode 100644 ruoyi-collect-common/src/main/java/com/ruoyi/collect/domain/EmpMiddleCar.java create mode 100644 ruoyi-collect-common/src/main/java/com/ruoyi/collect/domain/Fence.java create mode 100644 ruoyi-collect-common/src/main/java/com/ruoyi/collect/domain/FenceRecord.java create mode 100644 ruoyi-collect-common/src/main/java/com/ruoyi/collect/domain/Firm.java create mode 100644 ruoyi-collect-common/src/main/java/com/ruoyi/collect/domain/Identification.java create mode 100644 ruoyi-collect-common/src/main/java/com/ruoyi/collect/domain/Type.java create mode 100644 ruoyi-collect-common/src/main/java/com/ruoyi/collect/domain/VehicleMessage.java create mode 100644 ruoyi-collect-common/src/main/java/com/ruoyi/collect/domain/cache/fence/FenceIdTypeCache.java create mode 100644 ruoyi-collect-common/src/main/java/com/ruoyi/collect/domain/cache/fence/FenceInfoTypeCache.java create mode 100644 ruoyi-collect-remote/.gitignore create mode 100644 ruoyi-collect-remote/pom.xml create mode 100644 ruoyi-collect-server/.gitignore create mode 100644 ruoyi-collect-server/pom.xml create mode 100644 ruoyi-collect-server/src/main/java/com/ruoyi/collect/RuoYiCollectApplication.java create mode 100644 ruoyi-collect-server/src/main/java/com/ruoyi/collect/cache/CacheItem.java create mode 100644 ruoyi-collect-server/src/main/java/com/ruoyi/collect/cache/service/CacheService.java create mode 100644 ruoyi-collect-server/src/main/java/com/ruoyi/collect/cache/service/impl/CacheServiceImpl.java create mode 100644 ruoyi-collect-server/src/main/java/com/ruoyi/collect/config/ConsumeTest.java create mode 100644 ruoyi-collect-server/src/main/java/com/ruoyi/collect/config/KafkaTopic.java create mode 100644 ruoyi-collect-server/src/main/java/com/ruoyi/collect/config/ProductTest.java create mode 100644 ruoyi-collect-server/src/main/java/com/ruoyi/collect/config/RabbitmqConsumeMessage.java create mode 100644 ruoyi-collect-server/src/main/java/com/ruoyi/collect/config/RabbitmqConsumeSendEmail.java create mode 100644 ruoyi-collect-server/src/main/java/com/ruoyi/collect/config/RabbitmqConsumeStart.java create mode 100644 ruoyi-collect-server/src/main/java/com/ruoyi/collect/config/RedisFinalVariable.java create mode 100644 ruoyi-collect-server/src/main/java/com/ruoyi/collect/controller/BusinessController.java create mode 100644 ruoyi-collect-server/src/main/java/com/ruoyi/collect/controller/CarController.java create mode 100644 ruoyi-collect-server/src/main/java/com/ruoyi/collect/controller/EmpController.java create mode 100644 ruoyi-collect-server/src/main/java/com/ruoyi/collect/controller/IdentificationController.java create mode 100644 ruoyi-collect-server/src/main/java/com/ruoyi/collect/controller/SendController.java create mode 100644 ruoyi-collect-server/src/main/java/com/ruoyi/collect/mapper/BusinessMapper.java create mode 100644 ruoyi-collect-server/src/main/java/com/ruoyi/collect/mapper/CarMapper.java create mode 100644 ruoyi-collect-server/src/main/java/com/ruoyi/collect/mapper/EmpMapper.java create mode 100644 ruoyi-collect-server/src/main/java/com/ruoyi/collect/mapper/IdentificationMapper.java create mode 100644 ruoyi-collect-server/src/main/java/com/ruoyi/collect/service/BusinessService.java create mode 100644 ruoyi-collect-server/src/main/java/com/ruoyi/collect/service/CarService.java create mode 100644 ruoyi-collect-server/src/main/java/com/ruoyi/collect/service/EmpService.java create mode 100644 ruoyi-collect-server/src/main/java/com/ruoyi/collect/service/IElectronicFence.java create mode 100644 ruoyi-collect-server/src/main/java/com/ruoyi/collect/service/IdentificationService.java create mode 100644 ruoyi-collect-server/src/main/java/com/ruoyi/collect/service/impl/BusinessServiceImpl.java create mode 100644 ruoyi-collect-server/src/main/java/com/ruoyi/collect/service/impl/CarServiceImpl.java create mode 100644 ruoyi-collect-server/src/main/java/com/ruoyi/collect/service/impl/ElectronicdFenceimpl.java create mode 100644 ruoyi-collect-server/src/main/java/com/ruoyi/collect/service/impl/EmpServiceImpl.java create mode 100644 ruoyi-collect-server/src/main/java/com/ruoyi/collect/service/impl/IdentificationServiceImpl.java create mode 100644 ruoyi-collect-server/src/main/java/com/ruoyi/collect/utils/FenceUtils.java create mode 100644 ruoyi-collect-server/src/main/java/com/ruoyi/collect/utils/Latitudelongitude.java create mode 100644 ruoyi-collect-server/src/main/java/com/ruoyi/collect/utils/Text.java create mode 100644 ruoyi-collect-server/src/main/resources/banner.txt create mode 100644 ruoyi-collect-server/src/main/resources/bootstrap.yml create mode 100644 ruoyi-collect-server/src/main/resources/logback.xml create mode 100644 ruoyi-collect-server/src/main/resources/mapper/collect/BusinessMapper.xml create mode 100644 ruoyi-collect-server/src/main/resources/mapper/collect/CarMapper.xml create mode 100644 ruoyi-collect-server/src/main/resources/mapper/collect/EmpMapper.xml create mode 100644 ruoyi-collect-server/src/main/resources/mapper/collect/IdentificationMapper.xml create mode 100644 ruoyi-vehicle-cache/pom.xml create mode 100644 ruoyi-vehicle-cache/ruoyi-business-cache/.gitignore create mode 100644 ruoyi-vehicle-cache/ruoyi-business-cache/pom.xml create mode 100644 ruoyi-vehicle-cache/ruoyi-business-cache/src/main/java/com/ruoyi/vehicle/cache/fence/FenceCache.java create mode 100644 ruoyi-vehicle-cache/ruoyi-business-cache/src/main/java/com/ruoyi/vehicle/cache/fence/VehicleFenceCache.java create mode 100644 ruoyi-vehicle-cache/ruoyi-business-cache/src/main/java/com/ruoyi/vehicle/cache/fence/VehicleFenceCacheService.java create mode 100644 ruoyi-vehicle-cache/ruoyi-business-cache/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..09bdfea --- /dev/null +++ b/.gitignore @@ -0,0 +1,46 @@ +###################################################################### +# Build Tools + +.gradle +/build/ +!gradle/wrapper/gradle-wrapper.jar + +target/ +!.mvn/wrapper/maven-wrapper.jar + +###################################################################### +# IDE + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### JRebel ### +rebel.xml +### NetBeans ### +nbproject/private/ +build/* +nbbuild/ +dist/ +nbdist/ +.nb-gradle/ + +###################################################################### +# Others +*.log +*.xml.versionsBackup +*.swp + +!*/build/*.java +!*/build/*.html +!*/build/*.xml \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..3c13ca0 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,22 @@ +FROM openjdk:17-ea-slim +LABEL authors="Car-two <3079188394@qq.com>" + +RUN mkdir /car + +# 暴露端口 +EXPOSE 9455 + +# 创建着陆点 +WORKDIR "/car" + +# 复制新的运行程序 +COPY ./ruoyi-collect-server/target/ruoyi-collect-server.jar /car/app.jar + +# 挂载持续的目录 +VOLUME /car/logs/ruoyi-collect-server + + +# 运行你的jar包 +CMD ["java","-jar","/car/app.jar"] + + diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..8792858 --- /dev/null +++ b/pom.xml @@ -0,0 +1,26 @@ + + + + com.ruoyi + ruoyi + 3.6.3 + + pom + + ruoyi-collect-common + ruoyi-collect-remote + ruoyi-collect-server + ruoyi-vehicle-cache + + 3.6.3 + 4.0.0 + ruoyi-modules-collect + + + + ruoyi-modules-collect系统模块 + + + diff --git a/ruoyi-collect-common/.gitignore b/ruoyi-collect-common/.gitignore new file mode 100644 index 0000000..5ff6309 --- /dev/null +++ b/ruoyi-collect-common/.gitignore @@ -0,0 +1,38 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/ruoyi-collect-common/pom.xml b/ruoyi-collect-common/pom.xml new file mode 100644 index 0000000..cf5fc3c --- /dev/null +++ b/ruoyi-collect-common/pom.xml @@ -0,0 +1,97 @@ + + + 4.0.0 + + com.ruoyi + ruoyi-modules-collect + 3.6.3 + + + com.ruoyi + ruoyi-collect-common + + 8 + 8 + UTF-8 + + + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-discovery + + + + net.logstash.logback + logstash-logback-encoder + 6.6 + + + + org.springframework.kafka + spring-kafka + 3.0.9 + + + org.projectlombok + lombok + + + org.apache.kafka + kafka-clients + 3.0.0 + + + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-config + + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-sentinel + + + + + org.springframework.boot + spring-boot-starter-actuator + + + + + io.springfox + springfox-swagger-ui + ${swagger.fox.version} + + + + + com.mysql + mysql-connector-j + + + + com.ruoyi + ruoyi-common-core + + + + + org.springframework.boot + spring-boot-starter-mail + + + org.springframework.boot + spring-boot-starter-amqp + + + + + diff --git a/ruoyi-collect-common/src/main/java/com/ruoyi/collect/domain/Car.java b/ruoyi-collect-common/src/main/java/com/ruoyi/collect/domain/Car.java new file mode 100644 index 0000000..9daf063 --- /dev/null +++ b/ruoyi-collect-common/src/main/java/com/ruoyi/collect/domain/Car.java @@ -0,0 +1,86 @@ +package com.ruoyi.collect.domain; + +import lombok.*; + +@Data +@AllArgsConstructor +@NoArgsConstructor +@Setter +@Getter +public class Car { + + /** + * 车辆ID + */ + private Integer carId; + /** + * 车辆名称 + */ + private String carName; + /** + * 车辆VIN编码 + */ + private String carVin; + /** + * 车辆类型 + */ + private Integer typeId; + /** + * 车辆类型名称 + */ + private String typeName; + /** + * 制造厂商名称 + */ + private String manufacturerName; + /** + * 电池名称 + */ + private String batteryName; + /** + * 制造编号 + */ + private String manufacturerDesc; + /** + * 电池编号 + */ + private String batteryDesc; + /** + * 汽车状态 1在线1 已离线 + */ + private Integer carStatus; + /** + * 关联企业 + */ + private Integer firmId; + /** + * 企业名称 + */ + private String firmName; + + /** + * 逻辑删除 1显示 2删除 + */ + private Integer deletion; + + /** + * 標識選擇數組 + */ + private String identifications; + + /** + * 強轉 + */ + private Integer[] identificationIds; + + + /** + * 標識字符串 + */ + private String identificationName; + + + + + +} diff --git a/ruoyi-collect-common/src/main/java/com/ruoyi/collect/domain/CarBsRecord.java b/ruoyi-collect-common/src/main/java/com/ruoyi/collect/domain/CarBsRecord.java new file mode 100644 index 0000000..d756111 --- /dev/null +++ b/ruoyi-collect-common/src/main/java/com/ruoyi/collect/domain/CarBsRecord.java @@ -0,0 +1,37 @@ +package com.ruoyi.collect.domain; + +import lombok.Data; + +/** + * @author Lff + * @Date: 2023/9/11 20:44 + * @Description: + */ +@Data +public class CarBsRecord { + /** + * 車輛標識主鍵 + */ + private Integer carBsId; + + /** + * 標識主鍵 + */ + private Integer identificationId; + + /** + * 車輛主鍵 + */ + private Integer carId; + + /** + * 標識主鍵 + */ + private Integer carBsStatus; + + /** + * 標識選擇數組 + */ + private Integer[] identifications; + +} diff --git a/ruoyi-collect-common/src/main/java/com/ruoyi/collect/domain/CarFence.java b/ruoyi-collect-common/src/main/java/com/ruoyi/collect/domain/CarFence.java new file mode 100644 index 0000000..9af1e39 --- /dev/null +++ b/ruoyi-collect-common/src/main/java/com/ruoyi/collect/domain/CarFence.java @@ -0,0 +1,123 @@ +package com.ruoyi.collect.domain; + +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.*; +import org.springframework.format.annotation.DateTimeFormat; + +import java.util.Date; + +/** + * 车辆电子围栏中间表 + * @author Lff + * @Date: 2023/8/22 22:27 + * @Description: + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +@Setter +@Getter +public class CarFence { + /** + * 车辆-电子围栏中间表唯一标识:主键 + */ + private Integer fenceMiddleId; + /** + * 关联围栏 + */ + private Integer fenceId; + /** + * 车辆标识-状态:驶入驶出 + */ + private Integer carFenceStatus; + + /** + * 车辆ID + */ + private Integer carId; + /** + * 车辆名称 + */ + private String carName; + /** + * 车辆VIN编码 + */ + private String carVin; + /** + * 车辆类型 + */ + private Integer typeId; + /** + * 车辆类型名称 + */ + private String typeName; + /** + * 制造厂商名称 + */ + private String manufacturerName; + /** + * 电池名称 + */ + private String batteryName; + /** + * 制造编号 + */ + private String manufacturerDesc; + /** + * 电池编号 + */ + private String batteryDesc; + /** + * 汽车状态 1已离线 2在线 + */ + private Integer carStatus; + + /** + * 电子围栏中间表 + */ + private CarFence carFences; + + /** + * 电子围栏设置:围栏名称 + */ + private String fenceName; + /** + * 电子围栏设置:围栏地址 + */ + private String address; + /** + * 电子围栏设置:电子围栏经度/纬度 + */ + private String logLat; + /** + * 电子围栏设置:电子围栏创建时间 + */ + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private Date createTime; + /** + * 创建人 + */ + private String createName; + /** + * 电子围栏设置:电子围栏修改时间 + */ + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private Date updateTime; + /** + * 修改人 + */ + private String updateName; + /** + * 电子围栏设置:电子围栏结束时间 + */ + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private Date endTime; + /** + * 电子围栏设置:电子围栏状态 1激活 2未激活 + */ + private Integer fenceStatus; + +} diff --git a/ruoyi-collect-common/src/main/java/com/ruoyi/collect/domain/CarRecord.java b/ruoyi-collect-common/src/main/java/com/ruoyi/collect/domain/CarRecord.java new file mode 100644 index 0000000..eb5d044 --- /dev/null +++ b/ruoyi-collect-common/src/main/java/com/ruoyi/collect/domain/CarRecord.java @@ -0,0 +1,47 @@ +package com.ruoyi.collect.domain; + +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Data; +import org.springframework.format.annotation.DateTimeFormat; + +import java.util.Date; + +/** + * @author Lff + * @Date: 2023/9/2 9:23 + * @Description: + */ +@Data +public class CarRecord { + /** + * 车辆记录表主键 + */ + private Integer recordId; + /** + * 车辆标识 + */ + private String carVin; + /** + * 开始时间 + */ + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private Date createDate; + /** + * 结束时间 + */ + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private Date endDate; + + + /** + * 开始时间戳 + */ + private String startKey; + /** + * 结束时间戳 + */ + private String endKey; + +} diff --git a/ruoyi-collect-common/src/main/java/com/ruoyi/collect/domain/Emp.java b/ruoyi-collect-common/src/main/java/com/ruoyi/collect/domain/Emp.java new file mode 100644 index 0000000..768cd36 --- /dev/null +++ b/ruoyi-collect-common/src/main/java/com/ruoyi/collect/domain/Emp.java @@ -0,0 +1,44 @@ +package com.ruoyi.collect.domain; + +import lombok.Data; + +/** + * @author Lff + * @Date: 2023/8/30 18:49 + * @Description: + */ +@Data +public class Emp { + /** + * 员工唯一标识:主键 + */ + private Integer empId; + /** + * 员工姓名 + */ + private String empName; + /** + * 员工性别 + */ + private String empSex; + /** + * 员工手机号 + */ + private String empPhone; + /** + * 员工邮箱 + */ + private String email; + /** + * 绑定企业 + */ + private Integer firmId; + /** + * 员工状态 0在职 1停用 + */ + private Integer empStatus; + /** + * 企业名称 + */ + private String firmName; +} diff --git a/ruoyi-collect-common/src/main/java/com/ruoyi/collect/domain/EmpMiddleCar.java b/ruoyi-collect-common/src/main/java/com/ruoyi/collect/domain/EmpMiddleCar.java new file mode 100644 index 0000000..a3e71bc --- /dev/null +++ b/ruoyi-collect-common/src/main/java/com/ruoyi/collect/domain/EmpMiddleCar.java @@ -0,0 +1,52 @@ +package com.ruoyi.collect.domain; + +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Data; +import org.springframework.format.annotation.DateTimeFormat; + +import java.util.Date; + +/** + * @author Lff + * @Date: 2023/8/30 18:52 + * @Description: + */ +@Data +public class EmpMiddleCar { + /** + * 员工汽车中间表唯一标识:主键 + */ + private Integer middleId; + /** + * 绑定员工 + */ + private Integer empId; + /** + * 绑定汽车 + */ + private Integer carId; + /** + * 创建人名称 + */ + private String createName; + /** + * 创建时间 + */ + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private Date createTime; + /** + * 修改人名称 + */ + private String updateName; + /** + * 修改时间 + */ + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private Date updateTime; + /** + * 逻辑删除 0正常 1删除 + */ + private Integer deletion; +} diff --git a/ruoyi-collect-common/src/main/java/com/ruoyi/collect/domain/Fence.java b/ruoyi-collect-common/src/main/java/com/ruoyi/collect/domain/Fence.java new file mode 100644 index 0000000..6dda070 --- /dev/null +++ b/ruoyi-collect-common/src/main/java/com/ruoyi/collect/domain/Fence.java @@ -0,0 +1,73 @@ +package com.ruoyi.collect.domain; + +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Data; +import org.springframework.format.annotation.DateTimeFormat; + +import java.util.Date; + +/** + * 电子围栏实体类 + * @author Lff + * @Date: 2023/8/22 16:52 + * @Description: + */ +@Data +public class Fence { + /** + * 电子围栏设置:主键ID + */ + private Integer fenceId; + /** + * 关联企业 + */ + private Integer firmId; + /** + * 电子围栏设置:围栏名称 + */ + private String fenceName; + /** + * 电子围栏设置:围栏地址 + */ + private String address; + /** + * 电子围栏设置:电子围栏经度/纬度 + */ + private String logLat; + /** + * 电子围栏设置:电子围栏创建时间 + */ + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private Date createTime; + /** + * 创建人 + */ + private String createName; + /** + * 电子围栏设置:电子围栏修改时间 + */ + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private Date updateTime; + /** + * 修改人 + */ + private String updateName; + /** + * 电子围栏设置:电子围栏结束时间 + */ + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private Date endTime; + /** + * 电子围栏设置:电子围栏状态 1激活 2未激活 + */ + private Integer fenceStatus; + /** + * 逻辑删除 + */ + private Integer deletion; + + private String firmName; +} diff --git a/ruoyi-collect-common/src/main/java/com/ruoyi/collect/domain/FenceRecord.java b/ruoyi-collect-common/src/main/java/com/ruoyi/collect/domain/FenceRecord.java new file mode 100644 index 0000000..8ac0284 --- /dev/null +++ b/ruoyi-collect-common/src/main/java/com/ruoyi/collect/domain/FenceRecord.java @@ -0,0 +1,37 @@ +package com.ruoyi.collect.domain; + +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Data; +import org.springframework.format.annotation.DateTimeFormat; + +import java.util.Date; + +/** + * @author Lff + * @Date: 2023/9/12 9:32 + * @Description: + */ +@Data +public class FenceRecord { + private Integer recordId; + private Integer identificationId; + private Integer fenceId; + private Integer recordStatus; + private Integer firmId; + private String fenceName; + private String address; + private String logLat; + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private Date createTime; + private String createName; + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private Date updateTime; + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private Date endTime; + private String updateName; + private Integer fenceStatus; + +} diff --git a/ruoyi-collect-common/src/main/java/com/ruoyi/collect/domain/Firm.java b/ruoyi-collect-common/src/main/java/com/ruoyi/collect/domain/Firm.java new file mode 100644 index 0000000..962e18d --- /dev/null +++ b/ruoyi-collect-common/src/main/java/com/ruoyi/collect/domain/Firm.java @@ -0,0 +1,56 @@ +package com.ruoyi.collect.domain; + +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Data; +import org.springframework.format.annotation.DateTimeFormat; + +@Data +public class Firm { + + /** + * 企业唯一标识 + */ + private Integer firmId; + /** + * 企业名称 + */ + private String firmName; + /** + * 负责人 + */ + private String userId; + /** + * 地址 + */ + private String address; + /** + * 电话 + */ + private String firmPhone; + /** + * 逻辑删除 + */ + private String deletion; + /** + * 状态 + */ + private String firmState; + /** + * 创建时间 + */ + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private String createTime; + /** + * 修改人 + */ + private String updateName; + /** + * 修改时间 + */ + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private String updateTime; + + +} diff --git a/ruoyi-collect-common/src/main/java/com/ruoyi/collect/domain/Identification.java b/ruoyi-collect-common/src/main/java/com/ruoyi/collect/domain/Identification.java new file mode 100644 index 0000000..489d6ca --- /dev/null +++ b/ruoyi-collect-common/src/main/java/com/ruoyi/collect/domain/Identification.java @@ -0,0 +1,35 @@ +package com.ruoyi.collect.domain; + +import lombok.Data; + +/** + * @author Lff + * @Date: 2023/9/11 20:47 + * @Description: + */ +@Data +public class Identification { + /** + * 標識主鍵 + */ + private Integer identificationId; + + /** + * 標識名稱 + */ + private String identificationName; + + /** + * 標識狀態 + */ + private Integer identificationStatus; + + /** + * 電子圍欄多選框 + */ + private Integer[] fences; + + + + +} diff --git a/ruoyi-collect-common/src/main/java/com/ruoyi/collect/domain/Type.java b/ruoyi-collect-common/src/main/java/com/ruoyi/collect/domain/Type.java new file mode 100644 index 0000000..94b2f20 --- /dev/null +++ b/ruoyi-collect-common/src/main/java/com/ruoyi/collect/domain/Type.java @@ -0,0 +1,11 @@ +package com.ruoyi.collect.domain; + +import lombok.Data; + +@Data +public class Type { + + private Integer typeId; + private String typeName; + +} diff --git a/ruoyi-collect-common/src/main/java/com/ruoyi/collect/domain/VehicleMessage.java b/ruoyi-collect-common/src/main/java/com/ruoyi/collect/domain/VehicleMessage.java new file mode 100644 index 0000000..a9f6541 --- /dev/null +++ b/ruoyi-collect-common/src/main/java/com/ruoyi/collect/domain/VehicleMessage.java @@ -0,0 +1,114 @@ +package com.ruoyi.collect.domain; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + + + +/** + * 报文实体类 + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +public class VehicleMessage { + //消息标识 + private String identification; + //VIN码 + private String vinCode; + //经度 + private String longitude; + //纬度 + private String latitude; + //车速 + private String speedOfVehicle; + //总里程 + private String TotalMileage; + //总电压 + private String TotalVoltage; + //总电流 + private String combinedCurrent; + //绝缘电阻 + private String InsulationResistance; + //档位 + private String gearPosition; + //加速踏板行程值 + private String acceleratorPedalTravelValue; + //制动踏板行程值 + private String brakePedalTravelValue; + //燃料消耗率 + private String specificFuelConsumption; + //电机控制器温度 + private String motorControllerTemperature; + //电机转速 + private String motorSpeed; + //电机转矩 + private String motorTorque; + //电机温度 + private String motorTemperature; + //电机电压 + private String motorVoltage; + //电机电流 + private String motorCurrent; + //动力电池剩余电量SOC + private String electricalSoc; + //当前状态允许的最大反馈功率 + private String maximumFeedbackPower; + //当前状态允许最大放电功率 + private String maximumDischargePower; + //BMS自检计数器 + private String bms; + //动力电池充放电电流 + private String batteryCurrent; + //动力电池负载端总电压V3 + private String v3; + //单次最大电压 + private String singleMaximumVoltage; + //单体电池最低电压 + private String minimumVoltageOfBattery; + //单体电池最高温度 + private String maximumBatteryTemperature; + //单体电池最低温度 + private String minimumBatteryTemperature; + //动力电池可用容量 + private String powerBatteryAvailableCapacity; + //车辆状态 + private Integer carStatus; + //充电状态 + private Integer chargingState; + //运行状态 + private Integer runningState; + //SOC + private String soc; + //可充电储能装置工作状态 + private String workingCondition; + //驱动电机状态 + private String driveMotorCondition; + //定位是否有效 + private String whetherTheLocationValid; + //EAS + private String eas; + //PTC + private String ptc; + //EPS + private String eps; + //ABS + private String abs; + //MCU + private String mcu; + //动力电池加热状态 + private String powerBatteryHeatingState; + //动力电池当前状态 + private String powerBattery; + //动力电池保温状态 + private String powerBatteryInsulationState; + //DCDC + private String dcdc; + //CHG + private String chg; + + //时间 + private Long time; +} + diff --git a/ruoyi-collect-common/src/main/java/com/ruoyi/collect/domain/cache/fence/FenceIdTypeCache.java b/ruoyi-collect-common/src/main/java/com/ruoyi/collect/domain/cache/fence/FenceIdTypeCache.java new file mode 100644 index 0000000..49c2a30 --- /dev/null +++ b/ruoyi-collect-common/src/main/java/com/ruoyi/collect/domain/cache/fence/FenceIdTypeCache.java @@ -0,0 +1,29 @@ +package com.ruoyi.collect.domain.cache.fence; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * 车辆存储围栏类型缓存 + */ + +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class FenceIdTypeCache { + + /** + * 围栏ID + */ + private String fenceId; + + /** + * 围栏类型 + */ + private String fenceType; + +} + diff --git a/ruoyi-collect-common/src/main/java/com/ruoyi/collect/domain/cache/fence/FenceInfoTypeCache.java b/ruoyi-collect-common/src/main/java/com/ruoyi/collect/domain/cache/fence/FenceInfoTypeCache.java new file mode 100644 index 0000000..11b6b13 --- /dev/null +++ b/ruoyi-collect-common/src/main/java/com/ruoyi/collect/domain/cache/fence/FenceInfoTypeCache.java @@ -0,0 +1,29 @@ +package com.ruoyi.collect.domain.cache.fence; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * 电子围栏坐标和类型 + */ + +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class FenceInfoTypeCache { + + /** + * 围栏类型 + */ + private String fenceType; + + /** + * 经纬度信息 + */ + private double[][] coordinate; + + +} diff --git a/ruoyi-collect-remote/.gitignore b/ruoyi-collect-remote/.gitignore new file mode 100644 index 0000000..5ff6309 --- /dev/null +++ b/ruoyi-collect-remote/.gitignore @@ -0,0 +1,38 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/ruoyi-collect-remote/pom.xml b/ruoyi-collect-remote/pom.xml new file mode 100644 index 0000000..0f16ffe --- /dev/null +++ b/ruoyi-collect-remote/pom.xml @@ -0,0 +1,29 @@ + + + 4.0.0 + + com.ruoyi + ruoyi-modules-collect + 3.6.3 + + + com.ruoyi + ruoyi-collect-remote + + + 8 + 8 + UTF-8 + + + + + com.ruoyi + ruoyi-collect-common + 3.6.3 + + + + diff --git a/ruoyi-collect-server/.gitignore b/ruoyi-collect-server/.gitignore new file mode 100644 index 0000000..5ff6309 --- /dev/null +++ b/ruoyi-collect-server/.gitignore @@ -0,0 +1,38 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/ruoyi-collect-server/pom.xml b/ruoyi-collect-server/pom.xml new file mode 100644 index 0000000..606c513 --- /dev/null +++ b/ruoyi-collect-server/pom.xml @@ -0,0 +1,91 @@ + + + 4.0.0 + + com.ruoyi + ruoyi-modules-collect + 3.6.3 + + + com.ruoyi + ruoyi-collect-server + + 8 + 8 + UTF-8 + + + + + com.ruoyi + ruoyi-collect-common + 3.6.3 + + + + + com.ruoyi + ruoyi-common-datasource + + + + + com.ruoyi + ruoyi-common-datascope + + + + + com.ruoyi + ruoyi-common-log + + + + com.ruoyi + ruoyi-common-swagger + + + + com.ruoyi + ruoyi-file-remote + + + + com.ruoyi + ruoyi-analysis-remote + 3.6.3 + + + com.ruoyi + ruoyi-common-redis + + + + + + ${project.artifactId} + + + org.springframework.boot + spring-boot-maven-plugin + + + + repackage + + + + + + org.apache.maven.plugins + maven-deploy-plugin + + true + + + + + + diff --git a/ruoyi-collect-server/src/main/java/com/ruoyi/collect/RuoYiCollectApplication.java b/ruoyi-collect-server/src/main/java/com/ruoyi/collect/RuoYiCollectApplication.java new file mode 100644 index 0000000..fa74d3b --- /dev/null +++ b/ruoyi-collect-server/src/main/java/com/ruoyi/collect/RuoYiCollectApplication.java @@ -0,0 +1,34 @@ +package com.ruoyi.collect; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import com.ruoyi.common.security.annotation.EnableCustomConfig; +import com.ruoyi.common.security.annotation.EnableRyFeignClients; +import com.ruoyi.common.swagger.annotation.EnableCustomSwagger2; + +/** + * 系统模块 + * + * @author ruoyi + */ +@EnableCustomConfig +@EnableCustomSwagger2 +@EnableRyFeignClients +@SpringBootApplication +public class RuoYiCollectApplication +{ + public static void main(String[] args) + { + SpringApplication.run(RuoYiCollectApplication.class, args); + System.out.println("(♥◠‿◠)ノ゙ 系统模块启动成功 ლ(´ڡ`ლ)゙ \n" + + " .-------. ____ __ \n" + + " | _ _ \\ \\ \\ / / \n" + + " | ( ' ) | \\ _. / ' \n" + + " |(_ o _) / _( )_ .' \n" + + " | (_,_).' __ ___(_ o _)' \n" + + " | |\\ \\ | || |(_,_)' \n" + + " | | \\ `' /| `-' / \n" + + " | | \\ / \\ / \n" + + " ''-' `'-' `-..-' "); + } +} diff --git a/ruoyi-collect-server/src/main/java/com/ruoyi/collect/cache/CacheItem.java b/ruoyi-collect-server/src/main/java/com/ruoyi/collect/cache/CacheItem.java new file mode 100644 index 0000000..82e462a --- /dev/null +++ b/ruoyi-collect-server/src/main/java/com/ruoyi/collect/cache/CacheItem.java @@ -0,0 +1,41 @@ +package com.ruoyi.collect.cache; + +import lombok.Data; + +/** + * @program: Electronic-fence + * @description: 本地缓存 + * @author: lff + * @create: 2023-08-22 21:14 + **/ +@Data +public class CacheItem { + /** + * value的值 + */ + private Object value; + /** + * 过期时间 + */ + private long expireTime; + /** + * 访问时间 + */ + private long accessTime; + + + + + + public Object getValue() { + return value; + } + + public boolean isExpired() { + return System.currentTimeMillis() - accessTime > expireTime; + } + + public void updateAccessTime() { + accessTime = System.currentTimeMillis(); + } +} diff --git a/ruoyi-collect-server/src/main/java/com/ruoyi/collect/cache/service/CacheService.java b/ruoyi-collect-server/src/main/java/com/ruoyi/collect/cache/service/CacheService.java new file mode 100644 index 0000000..ab7f751 --- /dev/null +++ b/ruoyi-collect-server/src/main/java/com/ruoyi/collect/cache/service/CacheService.java @@ -0,0 +1,40 @@ +package com.ruoyi.collect.cache.service; + +/** + * @program: Electronic-fence + * @description: 缓存的接口 + * @author: lff + * @create: 2023-08-22 20:49 + **/ +public interface CacheService { + /** + * 添加缓存的方法 + * @param key + * @param value + * @param expire + */ + public void put(Object key,Object value,long expire); + + public void put(Object key,Object value); + + + /** + * 获取缓存 + * @param key + * @return + */ + public Object get(Object key); + + /** + * 获取最少使用的缓存 + * @return + */ + public Object getKickedKey(); + + + /** + * 删除缓存 + * @param key + */ + public void delekeyValue(Object key); +} diff --git a/ruoyi-collect-server/src/main/java/com/ruoyi/collect/cache/service/impl/CacheServiceImpl.java b/ruoyi-collect-server/src/main/java/com/ruoyi/collect/cache/service/impl/CacheServiceImpl.java new file mode 100644 index 0000000..ecbf22e --- /dev/null +++ b/ruoyi-collect-server/src/main/java/com/ruoyi/collect/cache/service/impl/CacheServiceImpl.java @@ -0,0 +1,91 @@ +package com.ruoyi.collect.cache.service.impl; + + + + +import com.ruoyi.collect.cache.CacheItem; +import com.ruoyi.collect.cache.service.CacheService; +import org.springframework.stereotype.Service; + +import java.util.Date; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +/** + * @program: Electronic-fence + * @description: 缓存接口的实现 + * @author: lff + * @create: 2023-08-22 20:52 + **/ +@Service +public class CacheServiceImpl implements CacheService { + + private Map cache; + + public CacheServiceImpl() { + this.cache = new ConcurrentHashMap<>(); + } + + /** + * 添加缓存项 + * @param key + * @param value + * @param expire + */ + @Override + public void put(Object key, Object value, long expire) { + CacheItem item = new CacheItem(); + CacheItem cacheItem = new CacheItem(); + cacheItem.setValue(value); + cacheItem.setExpireTime(expire); + cache.put(key, item); + } + + @Override + public void put(Object key, Object value) { + CacheItem item = new CacheItem(); + item.setValue(value); + cache.put(key, item); + } + + /** + * 通过key获取缓存项 + * @param key + * @return + */ + @Override + public Object get(Object key) { + CacheItem item = cache.get(key); + if (item != null && !item.isExpired()) { + item.updateAccessTime(); + return item.getValue(); + } + return item; + } + + + /** + * 清除已过期的缓存项 + * @return + */ + @Override + public Object getKickedKey() { + for (Map.Entry entry : cache.entrySet()) { + if (entry.getValue().isExpired()) { + return entry.getKey(); + } + } + return null; + } + + /** + * 删除Key以及对应的值 + * @param key + */ + @Override + public void delekeyValue(Object key) { + cache.remove(key); + } + + +} diff --git a/ruoyi-collect-server/src/main/java/com/ruoyi/collect/config/ConsumeTest.java b/ruoyi-collect-server/src/main/java/com/ruoyi/collect/config/ConsumeTest.java new file mode 100644 index 0000000..9645544 --- /dev/null +++ b/ruoyi-collect-server/src/main/java/com/ruoyi/collect/config/ConsumeTest.java @@ -0,0 +1,103 @@ +package com.ruoyi.collect.config; + +import org.apache.kafka.clients.admin.AdminClientConfig; +import org.apache.kafka.clients.consumer.ConsumerConfig; +import org.apache.kafka.clients.consumer.ConsumerRecord; +import org.apache.kafka.clients.consumer.ConsumerRecords; +import org.apache.kafka.clients.consumer.KafkaConsumer; +import org.apache.kafka.clients.producer.ProducerConfig; +import org.apache.kafka.common.TopicPartition; +import org.apache.kafka.common.serialization.StringDeserializer; +import org.springframework.beans.factory.BeanFactory; +import org.springframework.beans.factory.FactoryBean; + + +import java.time.Duration; +import java.util.Arrays; +import java.util.Collections; +import java.util.Properties; + +/** + * @author Lff + * @Date: 2023/8/19 11:32 + * @Description: + */ + +public class ConsumeTest { + + public void startKafkaProduct() { + Properties properties = new Properties(); + + properties.put(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, "43.142.96.146:9092"); + + properties.put("group-id","topic-test"); + + + properties.put("enable.auto.commit","true"); + + properties.put("auto.commit.interval.ms","1000"); + + properties.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class.getName()); + properties.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class.getName()); + + KafkaConsumer consumer = new KafkaConsumer<>(properties); + + consumer.subscribe(Arrays.asList("topic-test")); + + while (true){ + ConsumerRecords poll = consumer.poll(Duration.ofSeconds(5)); + + for (ConsumerRecord stringStringConsumerRecord : poll) { + String topic = stringStringConsumerRecord.topic(); + long offset = stringStringConsumerRecord.offset(); + String key = stringStringConsumerRecord.key(); + + String value = stringStringConsumerRecord.value(); + + System.out.println("消费者消费的信息是:"+value+",key是:"+key+",偏移量是:"+offset+",分区是:"+topic); + } + } + + + } + + public static void main(String[] args) { + Properties properties = new Properties(); + + properties.put("bootstrap.servers", "43.142.96.146:9092"); + + properties.put("group.id","test"); + + properties.put("auto.commit.interval.ms","1000"); + + //序列化(建议使用Json,这种序列化方式可以无需额外配置传输实体类) + properties.put("key.deserializer", StringDeserializer.class.getName()); + + properties.put("value.deserializer", StringDeserializer.class.getName()); + + KafkaConsumer consumer = new KafkaConsumer<>(properties); + + TopicPartition test = new TopicPartition("test", 1); + consumer.assign(Collections.singleton(test)); + while (true){ + ConsumerRecords poll = consumer.poll(Duration.ofSeconds(5)); + for (ConsumerRecord stringStringConsumerRecord : poll) { + + String topic = stringStringConsumerRecord.topic(); + + long offset = stringStringConsumerRecord.offset(); + + String key = stringStringConsumerRecord.key(); + + String value = stringStringConsumerRecord.value(); + + System.out.println("消费者消费的信息是:"+value+",key是:"+key+",偏移量是:"+offset+",分区是:"+topic); + try { + Thread.sleep(1000L); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + } + } + } +} diff --git a/ruoyi-collect-server/src/main/java/com/ruoyi/collect/config/KafkaTopic.java b/ruoyi-collect-server/src/main/java/com/ruoyi/collect/config/KafkaTopic.java new file mode 100644 index 0000000..021ff7e --- /dev/null +++ b/ruoyi-collect-server/src/main/java/com/ruoyi/collect/config/KafkaTopic.java @@ -0,0 +1,36 @@ +package com.ruoyi.collect.config; + +import org.apache.kafka.clients.admin.AdminClientConfig; +import org.apache.kafka.clients.admin.NewTopic; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.kafka.core.KafkaAdmin; + + +import java.util.HashMap; +import java.util.Map; + +/** + * @author Lff + * @Date: 2023/8/18 15:35 + * @Description: + */ +@Configuration +public class KafkaTopic { + @Bean + public KafkaAdmin kafkaAdmin() { + Map configs = new HashMap<>(); + configs.put(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, "43.142.96.146:9092"); + return new KafkaAdmin(configs); + } + + @Bean + public NewTopic topic1() { + return new NewTopic("qaq", 50, (short) 1); + } + +// @Bean +// public NewTopic topic2() { +// return new NewTopic("test", 100, (short) 1); +// } +} diff --git a/ruoyi-collect-server/src/main/java/com/ruoyi/collect/config/ProductTest.java b/ruoyi-collect-server/src/main/java/com/ruoyi/collect/config/ProductTest.java new file mode 100644 index 0000000..d6cf99d --- /dev/null +++ b/ruoyi-collect-server/src/main/java/com/ruoyi/collect/config/ProductTest.java @@ -0,0 +1,78 @@ +package com.ruoyi.collect.config; + +import com.alibaba.fastjson.JSON; +import org.apache.kafka.clients.admin.AdminClientConfig; +import org.apache.kafka.clients.producer.*; +import org.apache.kafka.common.header.internals.RecordHeader; +import org.apache.kafka.common.serialization.StringSerializer; + +import java.util.Properties; + +/** + * @author Lff + * @Date: 2023/8/19 11:17 + * @Description: + */ + +public class ProductTest { + public void startKafka(){ + Properties properties = new Properties(); + + + properties.put("bootstrap.servers", "43.142.96.146:9092"); + + properties.put("acks","all"); + + + properties.put("auto.create.topics.enable", "true"); + + properties.put("key.serializer", StringSerializer.class.getName()); + properties.put("value.serializer", StringSerializer.class.getName()); + + + KafkaProducer kafkaProducer = new KafkaProducer<>(properties); + for (int i = 1; i <= 100; i++) { + ProducerRecord producerRecord = new ProducerRecord("topic-test","topic:"+i); + //发送消息成功 + kafkaProducer.send(producerRecord); + } + } + + public static void main(String[] args) { + Properties properties = new Properties(); + + properties.put("bootstrap.servers", "43.142.96.146:9092"); + + properties.put("topic","test"); + properties.put("acks","all"); + + properties.put("auto.create.topics.enable",true); + + properties.put("key.serializer", StringSerializer.class.getName()); + properties.put("value.serializer", StringSerializer.class.getName()); + + KafkaProducer kafkaProducer = new KafkaProducer<>(properties); + + for (int i = 1; i <= 10; i++) { + System.out.println("正在发送第"+i+"条消息------"); + + ProducerRecord producerRecord = new ProducerRecord("test", 2,"","topic:"+i); + producerRecord.headers().add(new RecordHeader("topicId", "1K3MIzCoT7u2cUDOu_nKpA".getBytes())); + //发送消息成功 + kafkaProducer.send(producerRecord, new Callback() { + @Override + public void onCompletion(RecordMetadata recordMetadata, Exception e) { + if(e!=null){ + System.out.println("程序异常"); + }else{ + String topic = recordMetadata.topic(); + long offset = recordMetadata.offset(); + int partition = recordMetadata.partition(); + System.out.println("生产者,主题是:"+topic+",分区是:"+partition+",偏移量是:"+offset+"---"); + } + } + }); + } + kafkaProducer.close(); + } +} diff --git a/ruoyi-collect-server/src/main/java/com/ruoyi/collect/config/RabbitmqConsumeMessage.java b/ruoyi-collect-server/src/main/java/com/ruoyi/collect/config/RabbitmqConsumeMessage.java new file mode 100644 index 0000000..2d11170 --- /dev/null +++ b/ruoyi-collect-server/src/main/java/com/ruoyi/collect/config/RabbitmqConsumeMessage.java @@ -0,0 +1,57 @@ +package com.ruoyi.collect.config; + +import com.alibaba.fastjson.JSON; +import com.rabbitmq.client.Channel; +import com.ruoyi.collect.domain.VehicleMessage; +import com.ruoyi.collect.service.IElectronicFence; +import com.ruoyi.collect.service.impl.ElectronicdFenceimpl; +import lombok.extern.log4j.Log4j2; +import org.springframework.amqp.core.Message; +import org.springframework.amqp.rabbit.annotation.Queue; +import org.springframework.amqp.rabbit.annotation.RabbitListener; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.stereotype.Component; + +import java.io.IOException; +import java.util.concurrent.CountDownLatch; + +/** + * @author Lff + * @Date: 2023/8/28 9:02 + * @Description: + */ +@Component +@Log4j2 +public class RabbitmqConsumeMessage { + @Autowired + private IElectronicFence iElectronicFence; + @Autowired + private RedisTemplate redisTemplate; + @RabbitListener(queuesToDeclare = {@Queue("fence_handler_queue")}) + public void fenceHandlerQueue(String msg, Message message, Channel channel){ + log.info("消费者开始消费:信息是:{},队列是:{}",msg,"fence_handler_queue"); + String messageId = message.getMessageProperties().getMessageId(); + Long fenceHandlerQueue = redisTemplate.opsForSet().add("fence_handler_queue", messageId); + try { + if (fenceHandlerQueue == 1) { + VehicleMessage vehicleMessage = JSON.parseObject(msg, VehicleMessage.class); + iElectronicFence.electronicFence(vehicleMessage); + channel.basicAck(message.getMessageProperties().getDeliveryTag(),false); + log.info("消费者消费成功:信息是:{},队列是:{}", msg, "fence_handler_queue"); + } else { + log.info("消息重复消费********"); + } + } catch(IOException e){ + log.info("消费者消费失败:信息是:{},队列是:{}", msg, "fence_handler_queue"); + try { + //回退消息 + log.info("消费者消费失败,进行回退:信息是:{},队列是:{}", msg, "fence_handler_queue"); + channel.basicReject(message.getMessageProperties().getDeliveryTag(), true); + } catch (IOException ex) { + log.info("消费者回退失败:信息是:{},队列是:{}", msg, "fence_handler_queue"); + throw new RuntimeException(ex); + } + } + } +} diff --git a/ruoyi-collect-server/src/main/java/com/ruoyi/collect/config/RabbitmqConsumeSendEmail.java b/ruoyi-collect-server/src/main/java/com/ruoyi/collect/config/RabbitmqConsumeSendEmail.java new file mode 100644 index 0000000..5d6d57c --- /dev/null +++ b/ruoyi-collect-server/src/main/java/com/ruoyi/collect/config/RabbitmqConsumeSendEmail.java @@ -0,0 +1,76 @@ +package com.ruoyi.collect.config; + +import com.alibaba.fastjson.JSON; +import com.rabbitmq.client.Channel; +import com.ruoyi.collect.domain.VehicleMessage; +import lombok.Data; +import lombok.extern.log4j.Log4j2; +import org.springframework.amqp.core.Message; +import org.springframework.amqp.rabbit.annotation.Queue; +import org.springframework.amqp.rabbit.annotation.RabbitListener; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.mail.javamail.JavaMailSender; +import org.springframework.mail.javamail.MimeMessageHelper; +import org.springframework.stereotype.Component; + +import javax.mail.MessagingException; +import javax.mail.internet.MimeMessage; +import java.io.IOException; +import java.util.concurrent.TimeUnit; + +/** + * @author Lff + * @Date: 2023/8/30 18:29 + * @Description: + */ +@Component +@Log4j2 +public class RabbitmqConsumeSendEmail { + @Autowired + private RedisTemplate redisTemplate; + @Autowired + private JavaMailSender javaMailSender; + @RabbitListener(queuesToDeclare = {@Queue("sendFactorError")}) + public void sendEmail(String msg, Message message, Channel channel){ + log.info("消费者开始消费,发送邮件,队列是:{},消息是:{}","sendFactorError",msg); + VehicleMessage vehicleMessage = JSON.parseObject(msg, VehicleMessage.class); + String messageId = message.getMessageProperties().getMessageId(); + Long sendFactorError = redisTemplate.opsForSet().add("sendFactorError", messageId); + try { + if(sendFactorError==1){ + if(redisTemplate.hasKey("car_"+vehicleMessage.getVinCode())){ + log.info("邮件已经提示!请稍后。。。"); + }else{ + //将第一次报警信息存入缓存当中,如果第一次报警过后 + System.out.println("发送邮件----------"); + MimeMessage mimeMessage = javaMailSender.createMimeMessage(); + MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true); + helper.setSubject("通知"); + helper.setTo("3079188394@qq.com"); + helper.setText("您的汽车超出了围栏范围***"); + helper.setFrom("3079188394@qq.com"); + javaMailSender.send(mimeMessage); + log.info("消费者发送邮件成功,队列是:{},信息是:{}","sendFactorError",msg); + //消息手动确认 + + redisTemplate.opsForValue().set("car_"+vehicleMessage.getVinCode(),"",3, TimeUnit.MINUTES); + } + channel.basicAck(message.getMessageProperties().getDeliveryTag(),false); + + }else{ + log.info("消费者重复消费*****队列是:{}","sendFactorError"); + }//最大异常 + } catch (Exception e) { + log.info("消息消费失败,消息回退,队列是:{},消息是:{}","sendFactorError",msg); + try { + channel.basicReject(message.getMessageProperties().getDeliveryTag(),true); + } catch (IOException ex) { + log.info("消息回退失败,回退异常!!"); + throw new RuntimeException(ex); + } + throw new RuntimeException(e); + } + } + +} diff --git a/ruoyi-collect-server/src/main/java/com/ruoyi/collect/config/RabbitmqConsumeStart.java b/ruoyi-collect-server/src/main/java/com/ruoyi/collect/config/RabbitmqConsumeStart.java new file mode 100644 index 0000000..f6862bb --- /dev/null +++ b/ruoyi-collect-server/src/main/java/com/ruoyi/collect/config/RabbitmqConsumeStart.java @@ -0,0 +1,87 @@ +package com.ruoyi.collect.config; + +import com.alibaba.fastjson.JSON; +import com.rabbitmq.client.Channel; + + +import com.ruoyi.analysis.constants.VehicleConstants; +import com.ruoyi.analysis.constants.VehicleStatusEntity; +import com.ruoyi.collect.domain.CarRecord; +import com.ruoyi.collect.service.CarService; +import com.ruoyi.common.redis.service.RedisService; +import lombok.extern.log4j.Log4j2; +import org.springframework.amqp.core.Message; +import org.springframework.amqp.rabbit.annotation.Queue; +import org.springframework.amqp.rabbit.annotation.RabbitListener; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.BoundSetOperations; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.stereotype.Component; + +import java.io.IOException; +import java.util.*; + +/** + * @author Lff + * @Date: 2023/9/2 9:28 + * @Description: + */ +@Component +@Log4j2 +public class RabbitmqConsumeStart { + @Autowired + private CarService carService; + @Autowired + private RedisTemplate redisTemplate; + @RabbitListener(queuesToDeclare = {@Queue(VehicleConstants.VEHICLE_STATUS_UPDATE_QUEUE)}) + public void getStartCar(String msg, Message message, Channel channel){ + log.info("消费者开始消费,队列是:{},消息是:{}",VehicleConstants.VEHICLE_STATUS_UPDATE_QUEUE,msg); + String messageId = message.getMessageProperties().getMessageId(); + + Long add = redisTemplate.opsForSet().add(VehicleConstants.VEHICLE_STATUS_UPDATE_QUEUE, messageId); + + try { + if(add==1){ + //消费对象 + VehicleStatusEntity vehicleStatusEntity = JSON.parseObject(msg, VehicleStatusEntity.class); + if(vehicleStatusEntity.getStatus()==1){ + log.info("车辆进行上线操作"); + carService.startIsCar(vehicleStatusEntity.getVin()); + + carService.addRecord(vehicleStatusEntity.getVin(),vehicleStatusEntity.getTimestamp()); + log.info("消费者消费成功,车辆启动,队列是:{},消息是:{}",VehicleConstants.VEHICLE_STATUS_UPDATE_QUEUE,msg); + channel.basicAck(message.getMessageProperties().getDeliveryTag(),false); + }else{ + carService.endIsCar(vehicleStatusEntity.getVin()); + Date date = new Date(vehicleStatusEntity.getTimestamp()); + if(redisTemplate.hasKey(RedisFinalVariable.RECORD_ID+vehicleStatusEntity.getVin())){ + String s = redisTemplate.opsForValue().get(RedisFinalVariable.RECORD_ID + vehicleStatusEntity.getVin()); + CarRecord carRecord = JSON.parseObject(s, CarRecord.class); + carRecord.setEndDate(date); + carRecord.setEndKey(String.valueOf(vehicleStatusEntity.getTimestamp())); + carService.endCarRecord(carRecord); + log.info("消费者消费成功,车辆关闭,队列是:{},消息是:{}",VehicleConstants.VEHICLE_STATUS_UPDATE_QUEUE,msg); + channel.basicAck(message.getMessageProperties().getDeliveryTag(),false); + } + } + + } + else{ + log.info("消费者消费失败,消息重复消费,队列是:{},消息是:{}",VehicleConstants.VEHICLE_STATUS_UPDATE_QUEUE,msg); + } + } catch (IOException e) { + + log.info("消费者消费失败,队列是:{},消息是:{}",VehicleConstants.VEHICLE_STATUS_UPDATE_QUEUE,msg); + //消息回退 + try { + channel.basicReject(message.getMessageProperties().getDeliveryTag(),true); + } catch (IOException ex) { + log.info("消费者回退失败,队列是:{},消息是:{}",VehicleConstants.VEHICLE_STATUS_UPDATE_QUEUE,msg); + throw new RuntimeException(ex); + } + + throw new RuntimeException(e); + } + } + +} diff --git a/ruoyi-collect-server/src/main/java/com/ruoyi/collect/config/RedisFinalVariable.java b/ruoyi-collect-server/src/main/java/com/ruoyi/collect/config/RedisFinalVariable.java new file mode 100644 index 0000000..954f02e --- /dev/null +++ b/ruoyi-collect-server/src/main/java/com/ruoyi/collect/config/RedisFinalVariable.java @@ -0,0 +1,13 @@ +package com.ruoyi.collect.config; + +/** + * @author Lff + * @Date: 2023/9/2 15:42 + * @Description: + */ +public class RedisFinalVariable { + /** + * 记录表id常量 + */ + public static final String RECORD_ID="RECORD_ID"; +} diff --git a/ruoyi-collect-server/src/main/java/com/ruoyi/collect/controller/BusinessController.java b/ruoyi-collect-server/src/main/java/com/ruoyi/collect/controller/BusinessController.java new file mode 100644 index 0000000..639c55b --- /dev/null +++ b/ruoyi-collect-server/src/main/java/com/ruoyi/collect/controller/BusinessController.java @@ -0,0 +1,81 @@ +package com.ruoyi.collect.controller; + +import com.ruoyi.collect.domain.Fence; +import com.ruoyi.collect.service.BusinessService; +import com.ruoyi.common.core.domain.R; +import lombok.extern.log4j.Log4j2; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +/** + * 电子围栏区域 + * @author Lff + * @Date: 2023/8/22 17:00 + * @Description: + */ +@RestController +@Log4j2 +public class BusinessController { + @Autowired + private BusinessService businessService; + + + /** + * @return 查询电子围栏列表 + */ + @GetMapping("/AllFence") + public R> AllFence(){ + return businessService.AllFence(); + } + + + /** + * @param fenceId + * @return 查看电子围栏/回显 + */ + @GetMapping("/echoFence/{fenceId}") + public R echoFence(@PathVariable Integer fenceId){ + return businessService.echoFence(fenceId); + } + + /** + * @param fence + * @return 修改电子围栏 + */ + @PostMapping("/updateFence") + public R updateFence(@RequestBody Fence fence){ + return businessService.updateFence(fence); + } + + /** + * @param fenceId + * @return 删除电子围栏 + */ + @GetMapping("/deleteFence/{fenceId}") + public R deleteFence(@PathVariable Integer fenceId){ + return businessService.deleteFence(fenceId); + } + + /** + * @param fenceId + * @param fenceStatus + * @return 开启/关闭电子围栏 + */ + @GetMapping("/openIsClose") + public R openIsClose(@RequestParam Integer fenceId,@RequestParam Integer fenceStatus){ + return businessService.openIsClose(fenceId,fenceStatus); + } + + @PostMapping("/addFence") + public R addFence(@RequestBody Fence fence){ + return businessService.addFence(fence); + } + + + + + + +} diff --git a/ruoyi-collect-server/src/main/java/com/ruoyi/collect/controller/CarController.java b/ruoyi-collect-server/src/main/java/com/ruoyi/collect/controller/CarController.java new file mode 100644 index 0000000..78d3ea5 --- /dev/null +++ b/ruoyi-collect-server/src/main/java/com/ruoyi/collect/controller/CarController.java @@ -0,0 +1,190 @@ +package com.ruoyi.collect.controller; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; + + +import com.ruoyi.analysis.feign.AnalysisRemote; +import com.ruoyi.collect.domain.*; +import com.ruoyi.collect.service.CarService; +import com.ruoyi.collect.service.IElectronicFence; +import com.ruoyi.common.core.domain.R; +import com.ruoyi.common.core.web.domain.AjaxResult; +import com.ruoyi.common.redis.service.RedisService; +import lombok.extern.log4j.Log4j2; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletRequest; +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.text.ParseException; +import java.util.ArrayList; +import java.util.List; + +/** + * 汽车增删改查 + */ + +@RequestMapping("/car") +@RestController +@Log4j2 +public class CarController { + + @Autowired + private CarService carService; + @Autowired + private HttpServletRequest request; + @Autowired + private IElectronicFence iElectronicFence; + @Autowired + private AnalysisRemote analysisRemote; + @Autowired + private RedisService redisService; + + /** + * 汽车列表展示 + * @return + */ + @PostMapping("/carList") + public R> carList(@RequestBody Car car){ + log.info("功能名称,汽车列表展示,请求URI:{},请求方式:{}",request.getRequestURI(),request.getMethod()); + R> listR = carService.carList(car); + log.info("功能名称,汽车列表展示,请求URI:{},请求方式:{},响应结果:{}",request.getRequestURI(),request.getMethod(),JSONObject.toJSONString(listR.getData())); + return listR; + } + + /** + * @param carVin 车联唯一标识 + * @return + */ + @GetMapping("/startIsCar") + public R startIsCar(@RequestParam String carVin){ + R r = carService.startIsCar(carVin); + return r; + } + + + /**` + * 查询汽车类型下拉框 + * @return + */ + @GetMapping("/findByType") + public R> findByType(){ + log.info("功能名称,查询汽车类型下拉框,请求URI:{},请求方式:{}",request.getRequestURI(),request.getMethod()); + R> byType = carService.findByType(); + log.info("功能名称,查询汽车类型下拉框,请求URI:{},请求方式:{},响应结果:{}",request.getRequestURI(),request.getMethod(),JSONObject.toJSONString(byType.getData())); + return byType; + } + + /** + * 选择企业 + * @return + */ + @GetMapping("/findByFirm") + public R> findByFirm(){ + log.info("功能名称,选择企业,请求URI:{},请求方式:{}",request.getRequestURI(),request.getMethod()); + R> byFirm = carService.findByFirm(); + log.info("功能名称,选择企业,请求URI:{},请求方式:{},响应结果:{}",request.getRequestURI(),request.getMethod(),JSONObject.toJSONString(byFirm.getData())); + return byFirm; + } + + /** + * 添加车辆 + * @param car + * @return + */ + @PostMapping("/addCar") + public R addCar(@RequestBody Car car){ + log.info("功能名称,添加车辆,请求URI:{},请求方式:{},请求参数:{}",request.getRequestURI(),request.getMethod(),JSONObject.toJSONString(car)); + R r = carService.addCar(car); + log.info("功能名称,添加车辆,请求URI:{},请求方式:{},请求参数:{}",request.getRequestURI(),request.getMethod(),JSONObject.toJSONString(r.getData())); + return r; + } + + /** + * 删除汽车 + * @param carId + * @return + */ + @GetMapping("/deleteCar/{carId}") + public R deleteCar(@PathVariable Integer carId){ + log.info("功能名称,删除汽车,请求URI:{},请求方式:{},请求参数:{}",request.getRequestURI(),request.getMethod(),carId); + R r = carService.deleteCar(carId); + log.info("功能名称,删除汽车,请求URI:{},请求方式:{},响应结果:{}",request.getRequestURI(),request.getMethod(),JSONObject.toJSONString(r.getData())); + return r; + } + + /** + * 编辑车辆信息回显 + * @param carId + * @return + */ + @GetMapping("/findByCar/{carId}") + public R findByCar(@PathVariable Integer carId){ + log.info("功能名称,编辑车辆信息回显,请求URI:{},请求方式:{},请求参数:{}",request.getRequestURI(),request.getMethod(),carId); + R byCar = carService.findByCar(carId); + log.info("功能名称,编辑车辆信息回显,请求URI:{},请求方式:{},响应结果:{}",request.getRequestURI(),request.getMethod(),JSONObject.toJSONString(byCar.getData())); + return byCar; + } + + /** + * 修改车辆 + * @param car + * @return + */ + @PostMapping("/updateCar") + public R updateCar(@RequestBody Car car){ + log.info("功能名称,修改车辆,请求URI:{},请求方式:{},请求参数:{}",request.getRequestURI(),request.getMethod(),JSONObject.toJSONString(car)); + R r = carService.updateCar(car); + log.info("功能名称,修改车辆,请求URI:{},请求方式:{},响应结果:{}",request.getRequestURI(),request.getMethod(),JSONObject.toJSONString(r.getData())); + return r; + } + + @GetMapping("/testCarVin/{carVin}") + public R testCarVin(@PathVariable String carVin){ + VehicleMessage vehicleMessage = new VehicleMessage(); + vehicleMessage.setVinCode(carVin); +// 121.424722,31.244579;121.427309,31.218271;121.482644,31.228524;121.476895,31.250754 + vehicleMessage.setLatitude("31.607563"); + vehicleMessage.setLongitude("120.521853"); + + iElectronicFence.electronicFence(vehicleMessage); + return R.ok("成功"); + } + + @GetMapping("/showCarRecord") + public R> showCarRecord(){ + return carService.showCarRecord(); + } + + @GetMapping("/showCarRecordById/{recordId}") + public R showCarRecordById(@PathVariable Integer recordId){ + return carService.showCarRecordById(recordId); + } + + @GetMapping("/queryHistory/{recordId}") + public AjaxResult queryHistory(@PathVariable Integer recordId) throws IOException, ParseException, NoSuchFieldException, InvocationTargetException, IllegalAccessException { + R carRecordR = carService.showCarRecordById(recordId); + AjaxResult ajaxResult = analysisRemote.queryHistory(carRecordR.getData()); + return ajaxResult; + } + + @GetMapping("/GetRedis/{carVin}") + public R> GetRedis(@PathVariable String carVin){ + List cacheList = redisService.getCacheList(carVin); + + ArrayList carFences = new ArrayList<>(); + + for (Object o : cacheList) { + carFences.add((CarFence) o); + } + return R.ok(carFences); + } + + @GetMapping("/addSet") + public void addSet(){ + + } + +} diff --git a/ruoyi-collect-server/src/main/java/com/ruoyi/collect/controller/EmpController.java b/ruoyi-collect-server/src/main/java/com/ruoyi/collect/controller/EmpController.java new file mode 100644 index 0000000..93fc012 --- /dev/null +++ b/ruoyi-collect-server/src/main/java/com/ruoyi/collect/controller/EmpController.java @@ -0,0 +1,67 @@ +package com.ruoyi.collect.controller; + +import com.alibaba.fastjson.JSON; +import com.ruoyi.collect.domain.Emp; +import com.ruoyi.collect.service.EmpService; +import com.ruoyi.common.core.domain.R; +import lombok.extern.log4j.Log4j2; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletRequest; +import java.util.List; + +/** + * @author Lff + * @Date: 2023/8/30 18:56 + * @Description: + */ +@RestController +@RequestMapping("/emp") +@Log4j2 +public class EmpController { + @Autowired + private EmpService empService; + @Autowired + private HttpServletRequest request; + @GetMapping("/EmpAll") + public R> EmpAll(){ + log.info("功能名称:查询员工列表,请求URL:{},请求方法:{}",request.getServletPath(),request.getMethod()); + + List emps = empService.EmpAll(); + + log.info("功能名称:查询员工列表,请求URL:{},请求方法:{},返回结果是:{}",request.getServletPath(),request.getMethod(), JSON.toJSONString(emps)); + + return R.ok(emps); + + } + + @PostMapping("/addEmp") + public R addEmp(@RequestBody Emp emp){ + log.info("功能名称:添加员工绑定公司信息,请求URL:{},请求方法:{},请求参数:{}",request.getServletPath(),request.getMethod(),emp); + + int i = empService.addEmp(emp); + + if(i>0){ + return R.ok("添加成功"); + }else{ + return R.ok("添加失败"); + } + } + + @GetMapping("/showEmpById/{empId}") + public R> showEmpById(@PathVariable Integer empId){ + List emps = empService.showEmpById(empId); + return R.ok(emps); + } + + @PostMapping("/updateEmp") + public R updateEmp(@RequestBody Emp emp){ + return empService.updateEmp(emp); + } + + + + + +} diff --git a/ruoyi-collect-server/src/main/java/com/ruoyi/collect/controller/IdentificationController.java b/ruoyi-collect-server/src/main/java/com/ruoyi/collect/controller/IdentificationController.java new file mode 100644 index 0000000..43e0078 --- /dev/null +++ b/ruoyi-collect-server/src/main/java/com/ruoyi/collect/controller/IdentificationController.java @@ -0,0 +1,48 @@ +package com.ruoyi.collect.controller; + +import com.ruoyi.collect.domain.Identification; +import com.ruoyi.collect.service.IdentificationService; +import com.ruoyi.common.core.domain.R; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +/** + * @author Lff + * @Date: 2023/9/11 20:50 + * @Description: + */ +@RestController +@RequestMapping("/Identification") +public class IdentificationController { + @Autowired + private IdentificationService identificationService; + //查詢所有標識 + @GetMapping("/showIdentification") + public R> showIdentification(){ + return identificationService.showIdentification(); + } + //添加標識圍欄 + @PostMapping("/addIdentification") + public R addIdentification(@RequestBody Identification identification){ + return identificationService.addIdentification(identification); + } + //修改標識圍欄 + @PostMapping("/updateIdentification") + public R updateIdentification(@RequestBody Identification identification){ + return identificationService.updateIdentification(identification); + } + //刪除標識 + @GetMapping("/deleteIdentification/{identificationId}") + public R deleteIdentification(@PathVariable Integer identificationId){ + return identificationService.deleteIdentification(identificationId); + } + + + + + + + +} diff --git a/ruoyi-collect-server/src/main/java/com/ruoyi/collect/controller/SendController.java b/ruoyi-collect-server/src/main/java/com/ruoyi/collect/controller/SendController.java new file mode 100644 index 0000000..6772df0 --- /dev/null +++ b/ruoyi-collect-server/src/main/java/com/ruoyi/collect/controller/SendController.java @@ -0,0 +1,105 @@ +package com.ruoyi.collect.controller; + + +import com.ruoyi.collect.config.ConsumeTest; +import com.ruoyi.collect.config.ProductTest; +import org.springframework.beans.factory.annotation.Autowired; + + +import org.springframework.context.annotation.Bean; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + + + +/** + * @author Lff + * @Date: 2023/8/17 21:58 + * @Description: + */ +@RestController +public class SendController { + + + +// @Transactional +// @GetMapping("/aaa") +// public void aaa() { +//// Properties properties = new Properties(); +//// properties.put(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG,"10.100.27.5:9092"); +//// +//// AdminClient adminClient = AdminClient.create(properties); +//// // props.put(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9092"); +//// +//// NewTopic send = new NewTopic("send", 1, (short) 1); +//// +//// adminClient.createTopics(Collections.singleton(send)); +// +// kafkaTemplate.send("dsadasd", "word", "消息1"); +// +// //NewTopic newTopic = new NewTopic("my_topic", 1, (short) 1); +// System.out.println("发送成功"); +// } + + + @Transactional + @GetMapping("/bbb") + public void bbb() { +// Properties properties = new Properties(); +// properties.put(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG,"10.100.27.5:9092"); +// +// AdminClient adminClient = AdminClient.create(properties); +// // props.put(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9092"); +// +// NewTopic send = new NewTopic("send", 1, (short) 1); +// +// adminClient.createTopics(Collections.singleton(send)); + //开启消费者 + + + ProductTest productTest = new ProductTest(); + + productTest.startKafka(); + + + } + + @Transactional + @GetMapping("/ccc") + public void ccc() { +// Properties properties = new Properties(); +// properties.put(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG,"10.100.27.5:9092"); +// +// AdminClient adminClient = AdminClient.create(properties); +// // props.put(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9092"); +// +// NewTopic send = new NewTopic("send", 1, (short) 1); +// +// adminClient.createTopics(Collections.singleton(send)); + //开启消费者 + + ConsumeTest consumeTest = new ConsumeTest(); + consumeTest.startKafkaProduct(); + + } + + + + + + + + + +} + + + + + + + + + diff --git a/ruoyi-collect-server/src/main/java/com/ruoyi/collect/mapper/BusinessMapper.java b/ruoyi-collect-server/src/main/java/com/ruoyi/collect/mapper/BusinessMapper.java new file mode 100644 index 0000000..f8861e0 --- /dev/null +++ b/ruoyi-collect-server/src/main/java/com/ruoyi/collect/mapper/BusinessMapper.java @@ -0,0 +1,30 @@ +package com.ruoyi.collect.mapper; + +import com.ruoyi.collect.domain.Fence; +import com.ruoyi.common.core.domain.R; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; +import org.springframework.stereotype.Repository; + +import java.util.List; + +/** + * @author Lff + * @Date: 2023/8/22 17:00 + * @Description: + */ +@Repository +public interface BusinessMapper { + + List AllFence(); + + Fence echoFence(@Param("fenceId") Integer fenceId); + + int updateFence(Fence fence); + + int deleteFence(@Param("fenceId") Integer fenceId); + + int openIsClose(@Param("fenceId") Integer fenceId, @Param("fenceStatus") Integer fenceStatus); + + int addFence(Fence fence); +} diff --git a/ruoyi-collect-server/src/main/java/com/ruoyi/collect/mapper/CarMapper.java b/ruoyi-collect-server/src/main/java/com/ruoyi/collect/mapper/CarMapper.java new file mode 100644 index 0000000..3139546 --- /dev/null +++ b/ruoyi-collect-server/src/main/java/com/ruoyi/collect/mapper/CarMapper.java @@ -0,0 +1,51 @@ +package com.ruoyi.collect.mapper; + + +import com.ruoyi.collect.domain.*; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.Date; +import java.util.List; + +@Mapper +public interface CarMapper { + + + List carList(Car car); + + List findByType(); + + + List findByFirm(); + + int addCar(Car car); + + int deleteCar(@Param("carId") Integer carId); + + Car findByCar(@Param("carVin") String carVin); + + int updateCar(Car car); + + void startIsCar(@Param("carVin") String carVin); + + List showCarRecord(); + + void endCar(@Param("carVin") String vin); + + int addRecord(CarRecord carRecord); + + void endCarRecord(CarRecord carRecord); + + Car fendByCarId(@Param("carId") Integer carId); + + CarRecord showCarRecordById(@Param("recordId") Integer recordId); + + int addIdentificationRecord(@Param("carId") Integer carId, @Param("identificationId") Integer identificationId); + + int deleteCarIdentification(@Param("carId") Integer carId); + + List showCarBsRecord(@Param("carId") Integer carId); + + List showFence(@Param("identificationId") Integer identificationId); +} diff --git a/ruoyi-collect-server/src/main/java/com/ruoyi/collect/mapper/EmpMapper.java b/ruoyi-collect-server/src/main/java/com/ruoyi/collect/mapper/EmpMapper.java new file mode 100644 index 0000000..70dd243 --- /dev/null +++ b/ruoyi-collect-server/src/main/java/com/ruoyi/collect/mapper/EmpMapper.java @@ -0,0 +1,23 @@ +package com.ruoyi.collect.mapper; + +import com.ruoyi.collect.domain.Emp; +import org.apache.ibatis.annotations.Param; +import org.springframework.stereotype.Repository; + +import java.util.List; + +/** + * @author Lff + * @Date: 2023/8/30 18:56 + * @Description: + */ +@Repository +public interface EmpMapper { + List EmpAll(); + + int addEmp(Emp emp); + + List showEmpById(@Param("empId") Integer empId); + + int updateEmp(Emp emp); +} diff --git a/ruoyi-collect-server/src/main/java/com/ruoyi/collect/mapper/IdentificationMapper.java b/ruoyi-collect-server/src/main/java/com/ruoyi/collect/mapper/IdentificationMapper.java new file mode 100644 index 0000000..80aea52 --- /dev/null +++ b/ruoyi-collect-server/src/main/java/com/ruoyi/collect/mapper/IdentificationMapper.java @@ -0,0 +1,23 @@ +package com.ruoyi.collect.mapper; + +import com.ruoyi.collect.domain.Identification; +import org.apache.ibatis.annotations.Param; +import org.springframework.stereotype.Repository; + +import java.util.List; + +/** + * @author Lff + * @Date: 2023/9/11 20:50 + * @Description: + */ +@Repository +public interface IdentificationMapper { + List showIdentification(); + + int addIdentification(Identification identification); + + int addFenceRecord(@Param("identificationId") Integer identificationId, @Param("fence") Integer fence); + + int deleteIdentification(@Param("identificationId") Integer identificationId); +} diff --git a/ruoyi-collect-server/src/main/java/com/ruoyi/collect/service/BusinessService.java b/ruoyi-collect-server/src/main/java/com/ruoyi/collect/service/BusinessService.java new file mode 100644 index 0000000..ea1cac5 --- /dev/null +++ b/ruoyi-collect-server/src/main/java/com/ruoyi/collect/service/BusinessService.java @@ -0,0 +1,25 @@ +package com.ruoyi.collect.service; + +import com.ruoyi.collect.domain.Fence; +import com.ruoyi.common.core.domain.R; + +import java.util.List; + +/** + * @author Lff + * @Date: 2023/8/22 17:00 + * @Description: + */ +public interface BusinessService { + R> AllFence(); + + R echoFence(Integer fenceId); + + R updateFence(Fence fence); + + R deleteFence(Integer fenceId); + + R openIsClose(Integer fenceId, Integer fenceStatus); + + R addFence(Fence fence); +} diff --git a/ruoyi-collect-server/src/main/java/com/ruoyi/collect/service/CarService.java b/ruoyi-collect-server/src/main/java/com/ruoyi/collect/service/CarService.java new file mode 100644 index 0000000..84ed89b --- /dev/null +++ b/ruoyi-collect-server/src/main/java/com/ruoyi/collect/service/CarService.java @@ -0,0 +1,37 @@ +package com.ruoyi.collect.service; + + +import com.ruoyi.collect.domain.*; +import com.ruoyi.common.core.domain.R; + +import java.util.Date; +import java.util.List; + +public interface CarService { + R> carList(Car car); + + R> findByType(); + + R> findByFirm(); + + R addCar(Car car); + + R deleteCar(Integer carId); + + R findByCar(Integer carId); + + R updateCar(Car car); + + R startIsCar(String carVin); + + + R> showCarRecord(); + + void addRecord(String vin, Long datetime); + + void endIsCar(String vin); + + void endCarRecord(CarRecord carRecord); + + R showCarRecordById(Integer recordId); +} diff --git a/ruoyi-collect-server/src/main/java/com/ruoyi/collect/service/EmpService.java b/ruoyi-collect-server/src/main/java/com/ruoyi/collect/service/EmpService.java new file mode 100644 index 0000000..513cf85 --- /dev/null +++ b/ruoyi-collect-server/src/main/java/com/ruoyi/collect/service/EmpService.java @@ -0,0 +1,21 @@ +package com.ruoyi.collect.service; + +import com.ruoyi.collect.domain.Emp; +import com.ruoyi.common.core.domain.R; + +import java.util.List; + +/** + * @author Lff + * @Date: 2023/8/30 18:55 + * @Description: + */ +public interface EmpService { + List EmpAll(); + + int addEmp(Emp emp); + + List showEmpById(Integer empId); + + R updateEmp(Emp emp); +} diff --git a/ruoyi-collect-server/src/main/java/com/ruoyi/collect/service/IElectronicFence.java b/ruoyi-collect-server/src/main/java/com/ruoyi/collect/service/IElectronicFence.java new file mode 100644 index 0000000..e428ae5 --- /dev/null +++ b/ruoyi-collect-server/src/main/java/com/ruoyi/collect/service/IElectronicFence.java @@ -0,0 +1,19 @@ +package com.ruoyi.collect.service; + + +import com.ruoyi.collect.domain.VehicleMessage; + +/** + * @program: lemon-fence + * @description: 电子围栏判断接口 + * @author: Mr.Gong + * @create: 2023-08-23 14:06 + **/ +public interface IElectronicFence { + /** + * 调用此接口 判断围栏内外 传入汽车报文的对象 + * @param messages + * @return + */ + public void electronicFence(VehicleMessage messages); +} diff --git a/ruoyi-collect-server/src/main/java/com/ruoyi/collect/service/IdentificationService.java b/ruoyi-collect-server/src/main/java/com/ruoyi/collect/service/IdentificationService.java new file mode 100644 index 0000000..415a469 --- /dev/null +++ b/ruoyi-collect-server/src/main/java/com/ruoyi/collect/service/IdentificationService.java @@ -0,0 +1,21 @@ +package com.ruoyi.collect.service; + +import com.ruoyi.collect.domain.Identification; +import com.ruoyi.common.core.domain.R; + +import java.util.List; + +/** + * @author Lff + * @Date: 2023/9/11 20:50 + * @Description: + */ +public interface IdentificationService { + R> showIdentification(); + + R addIdentification(Identification identification); + + R updateIdentification(Identification identification); + + R deleteIdentification(Integer identificationId); +} diff --git a/ruoyi-collect-server/src/main/java/com/ruoyi/collect/service/impl/BusinessServiceImpl.java b/ruoyi-collect-server/src/main/java/com/ruoyi/collect/service/impl/BusinessServiceImpl.java new file mode 100644 index 0000000..d5bb49b --- /dev/null +++ b/ruoyi-collect-server/src/main/java/com/ruoyi/collect/service/impl/BusinessServiceImpl.java @@ -0,0 +1,79 @@ +package com.ruoyi.collect.service.impl; + +import com.ruoyi.collect.domain.Fence; +import com.ruoyi.collect.mapper.BusinessMapper; +import com.ruoyi.collect.service.BusinessService; +import com.ruoyi.common.core.domain.R; +import com.ruoyi.common.redis.service.RedisService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.Date; +import java.util.List; + +/** + * @author Lff + * @Date: 2023/8/22 17:00 + * @Description: + */ +@Service +public class BusinessServiceImpl implements BusinessService { + @Autowired + private BusinessMapper businessMapper; + @Autowired + private RedisService redisService; + + @Override + public R> AllFence() { + List fences = businessMapper.AllFence(); + return R.ok(fences); + } + + @Override + public R echoFence(Integer fenceId) { + //查询电子围栏,根据主键唯一标识去查询 + Fence fence = businessMapper.echoFence(fenceId); + return R.ok(fence); + } + + @Override + public R updateFence(Fence fence) { + //修改电子围栏 + fence.setUpdateTime(new Date()); + int i = businessMapper.updateFence(fence); + if(i>0){ + return R.ok("修改成功"); + } + return R.ok("修改失败"); + } + + @Override + public R deleteFence(Integer fenceId) { + int i = businessMapper.deleteFence(fenceId); + if(i>0){ + return R.ok("删除成功"); + } + return R.ok("删除失败"); + } + + @Override + public R openIsClose(Integer fenceId, Integer fenceStatus) { + int i = businessMapper.openIsClose(fenceId, fenceStatus); + + if(i>0){ + return R.ok("修改成功"); + } + return R.ok("修改失败"); + } + + @Override + public R addFence(Fence fence) { + fence.setCreateTime(new Date()); + int i = businessMapper.addFence(fence); + if(i>0){ + return R.ok("添加成功"); + } + return R.ok("添加失败"); + } +} + diff --git a/ruoyi-collect-server/src/main/java/com/ruoyi/collect/service/impl/CarServiceImpl.java b/ruoyi-collect-server/src/main/java/com/ruoyi/collect/service/impl/CarServiceImpl.java new file mode 100644 index 0000000..7da4a09 --- /dev/null +++ b/ruoyi-collect-server/src/main/java/com/ruoyi/collect/service/impl/CarServiceImpl.java @@ -0,0 +1,169 @@ +package com.ruoyi.collect.service.impl; + + +import com.alibaba.fastjson.JSON; +import com.ruoyi.collect.cache.service.CacheService; +import com.ruoyi.collect.config.RedisFinalVariable; +import com.ruoyi.collect.domain.*; +import com.ruoyi.collect.mapper.CarMapper; +import com.ruoyi.collect.service.CarService; +import com.ruoyi.common.core.domain.R; +import com.ruoyi.common.redis.service.RedisService; +import lombok.extern.log4j.Log4j2; +import org.apache.commons.beanutils.ConvertUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Date; +import java.util.List; + +@Service +@Log4j2 +public class CarServiceImpl implements CarService { + + @Autowired + private CarMapper carMapper; + @Autowired + private CacheService cacheService; + @Autowired + private RedisTemplate redisTemplate; + @Autowired + private RedisService redisService; + + @Override + public R> carList(Car car) { + List cars = carMapper.carList(car); + return R.ok(cars); + } + + @Override + public R> findByType() { + List byType = carMapper.findByType(); + return R.ok(byType); + } + + @Override + public R> findByFirm() { + List byFirm = carMapper.findByFirm(); + return R.ok(byFirm); + } + + @Override + public R addCar(Car car) { + int i = carMapper.addCar(car); + if(i>0){ + //添加標識中间表 + int aa=0; + for (Integer identificationId : car.getIdentificationIds()) { + aa = carMapper.addIdentificationRecord(car.getCarId(),identificationId); + } + if(aa>0){ + return R.ok("添加成功"); + } + } + return R.ok("添加失败"); + } + + @Override + public R deleteCar(Integer carId) { + Car byCar = carMapper.fendByCarId(carId); + int i = carMapper.deleteCar(carId); + if(i>0){ + carMapper.deleteCarIdentification(byCar.getCarId());//删除该车辆的电子围栏 + return R.ok("删除成功"); + } + return R.ok("删除失败"); + } + + @Override + public R findByCar(Integer carId) { + Car byCar = carMapper.fendByCarId(carId); + String[] split = byCar.getIdentifications().split(","); + Integer[] convert = (Integer[]) ConvertUtils.convert(split, Integer.class); + byCar.setIdentificationIds(convert); + return R.ok(byCar); + } + + @Override + public R updateCar(Car car) { + int i = carMapper.updateCar(car); + if(i>0){ + //修改该车辆的电子围栏 + //先根据vin删除之前的电子围栏 + int i1 = carMapper.deleteCarIdentification(car.getCarId()); + for (Integer identificationId : car.getIdentificationIds()) { + carMapper.addIdentificationRecord(car.getCarId(),identificationId); + } + return R.ok("修改成功"); + } + return R.ok("修改失败"); + } + + @Override + public R startIsCar(String carVin) { + //查询车辆信息 + Car byCar = carMapper.findByCar(carVin); + //车辆上线 + carMapper.startIsCar(carVin); + //查询车辆标识 + List identifications = carMapper.showCarBsRecord(byCar.getCarId()); + + ArrayList fenceRecords = new ArrayList<>(); + + for (Identification identification : identifications) { + List fenceRecords1 = carMapper.showFence(identification.getIdentificationId()); + fenceRecords.addAll(fenceRecords1); + } + //将车辆标识存入缓存当中 + cacheService.put(byCar.getCarVin(),fenceRecords); + if(redisService.hasKey(byCar.getCarVin())){ + redisService.deleteObject(byCar.getCarVin()); + redisService.setCacheList(byCar.getCarVin(),fenceRecords); + }else{ + redisService.setCacheList(byCar.getCarVin(),fenceRecords); + } + return R.ok("启动成功"); + } + + + + @Override + public R> showCarRecord() { + List carRecords = carMapper.showCarRecord(); + return R.ok(carRecords); + } + + @Override + public void addRecord(String vin, Long datetime) { + CarRecord carRecord = new CarRecord(); + carRecord.setCarVin(vin); + carRecord.setCreateDate(new Date(datetime)); + carRecord.setStartKey(String.valueOf(datetime)); + int i = carMapper.addRecord(carRecord); + if(i>0){ +// redisTemplate.opsForValue().set(RedisFinalVariable.RECORD_ID+vin,JSON.toJSONString(carRecord)); + redisService.setCacheObject(RedisFinalVariable.RECORD_ID+vin,JSON.toJSONString(carRecord)); + } + } + + @Override + public void endIsCar(String vin) { + carMapper.endCar(vin); + } + + @Override + public void endCarRecord(CarRecord carRecord) { + carMapper.endCarRecord(carRecord); + } + + @Override + public R showCarRecordById(Integer recordId) { + CarRecord carRecord = carMapper.showCarRecordById(recordId); + return R.ok(carRecord); + } + + +} diff --git a/ruoyi-collect-server/src/main/java/com/ruoyi/collect/service/impl/ElectronicdFenceimpl.java b/ruoyi-collect-server/src/main/java/com/ruoyi/collect/service/impl/ElectronicdFenceimpl.java new file mode 100644 index 0000000..3d5e1de --- /dev/null +++ b/ruoyi-collect-server/src/main/java/com/ruoyi/collect/service/impl/ElectronicdFenceimpl.java @@ -0,0 +1,186 @@ +package com.ruoyi.collect.service.impl; + + +import com.alibaba.fastjson.JSON; +import com.ruoyi.collect.cache.CacheItem; +import com.ruoyi.collect.cache.service.CacheService; +import com.ruoyi.collect.domain.CarFence; +import com.ruoyi.collect.domain.FenceRecord; +import com.ruoyi.collect.domain.VehicleMessage; +import com.ruoyi.collect.service.CarService; +import com.ruoyi.collect.service.IElectronicFence; +import com.ruoyi.collect.utils.FenceUtils; +import com.ruoyi.collect.utils.Latitudelongitude; +import com.ruoyi.common.redis.service.RedisService; +import org.springframework.amqp.rabbit.core.RabbitTemplate; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.mail.javamail.JavaMailSender; +import org.springframework.mail.javamail.MimeMessageHelper; +import org.springframework.stereotype.Service; + + +import javax.mail.MessagingException; +import javax.mail.internet.MimeMessage; +import java.awt.geom.GeneralPath; +import java.awt.geom.Point2D; +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +/** + * @program: lemon-fence + * @description: 实现电子围栏判断接口 + * @author: lff + * @create: 2023-08-23 14:36 + **/ +@Service +public class ElectronicdFenceimpl implements IElectronicFence { + @Autowired + private CacheService cacheService; + @Autowired + private JavaMailSender javaMailSender; + @Autowired + private CarService carService; + @Autowired + private RabbitTemplate rabbitTemplate; + @Autowired + private RedisService redisService; + @Autowired + private RedisTemplate redisTemplate; + @Override + public void electronicFence(VehicleMessage messages) { + //获取纬度坐标 + double latitude = Double.parseDouble(messages.getLatitude()); + //获取经度坐标 + double longitude = Double.parseDouble(messages.getLongitude()); + + ArrayList carFences = new ArrayList<>(); + //从本地缓存中获取该车辆的所有电子围栏信息 + CacheItem o = (CacheItem) cacheService.get(messages.getVinCode()); + + if(o!=null){ + List value = (List) o.getValue(); + //一级缓存中如果有车辆围栏信息,直接从一级缓存中将数据取出,没有的话才会去二级缓存 + carFences.addAll(value); + }else{ + //二级缓存 +// List range = redisTemplate.opsForList().range(messages.getVinCode(), 0, -1); + List cacheList = redisService.getCacheList(messages.getVinCode()); + for (Object s : cacheList) { + carFences.add((FenceRecord) s); + } + } + + + //循环集合 + + carFences.stream().forEach(item -> { + //判断电子围栏的类型 + //驶入则判断是否在电子围栏内 + if(item.getRecordStatus()==1){ + //调用方法判断 + //获取到车辆的经度和纬度 + Latitudelongitude latitudelongitude = new Latitudelongitude(); + latitudelongitude.setLatitude(latitude); + latitudelongitude.setLongitude(longitude); + + String logLat = item.getLogLat(); + //调用方法实现切割经度纬度 + ArrayList latitudelongitudes = getList(logLat); + + Boolean isfence = FenceUtils.isfence(latitudelongitude, latitudelongitudes); + //如果在 则代表车辆驶入围栏内 返回的是true 则发送警报 + if(isfence){ + System.out.println("正常"); + }else{//如果不在 则代表车辆依旧在电子围栏外 返回的是false 则显示正常 +// try { +// MimeMessage mimeMessage = javaMailSender.createMimeMessage(); +// MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true); +// helper.setSubject("通知"); +// helper.setText("您的车辆已经超出围栏!!!"); +// helper.setFrom("3079188394@qq.com"); +// helper.setTo("3079188394@qq.com"); +// javaMailSender.send(mimeMessage); +// } catch (MessagingException e) { +// throw new RuntimeException(e); +// } + rabbitTemplate.convertAndSend("sendFactorError",JSON.toJSONString(messages),message -> { + message.getMessageProperties().setMessageId(UUID.randomUUID().toString().replaceAll("-","")); + return message; + }); + System.out.println("实现报警"); + } + }else if(item.getRecordStatus()==2){//驶入则判断是否在电子围栏内 + //调用方法 + Latitudelongitude latitudelongitude = new Latitudelongitude(); + latitudelongitude.setLatitude(latitude); + latitudelongitude.setLongitude(longitude); + + String logLat = item.getLogLat(); + //调用方法实现切割经度纬度 + ArrayList latitudelongitudes = getList(logLat); + Boolean isfence = FenceUtils.isfence(latitudelongitude, latitudelongitudes); + + //如果在 则代表车辆依旧在围栏内 返回的是true 则显示正常 + if(isfence){ + System.out.println("正常"); + }else{//如果不在 则代表车辆驶出电子围栏 返回的是true 则显示报警 + System.out.println("实现报警"); + rabbitTemplate.convertAndSend("sendFactorError",JSON.toJSONString(messages),message -> { + message.getMessageProperties().setMessageId(UUID.randomUUID().toString().replaceAll("-","")); + return message; + }); + } + } + }); + } +// private static boolean check(Point2D.Double point, List polygon) { +// //创建一个GeneralPath对象,用于绘制闭合图形和操作路径。 +// GeneralPath peneralPath = new GeneralPath(); +// //创建一个Poin2D的first变量 获取集合中的第一个坐标并赋值给first变量 +// Point2D.Double first = polygon.get(0); +// // 通过移动到指定坐标(以双精度指定),将一个点添加到路径中 作为操作路径的起始点 +// peneralPath.moveTo(first.x, first.y); +// //从多边形列表中移除第一个坐标点对象 因为第一个坐标已经在操作路径当中 +// polygon.remove(0); +// //遍历多边形列表中的剩余点 +// for (Point2D.Double pol : polygon) { +// peneralPath.lineTo(pol.x, pol.y); +// } +// // 循环结束后的最后一个坐标通过lineTo的方式 移动到起始点 形成一个通用路径 包含围栏所有节点的坐标点 通过通用路径形成了闭环图形 +// peneralPath.lineTo(first.x, first.y); +// peneralPath.closePath();//创建完成后 关闭路径 +// // 测试指定的 Point2D 是否在 Shape 的边界内。 +// return peneralPath.contains(point); +// } + + public ArrayList getList(String logLat){ + //切割出经度 + //121.357205,31.309392;121.647537,31.191832;121.39515,31.120632 + //121.357205,31.309392 121.647537,31.191832 121.39515,31.120632 + String[] split = logLat.split(";"); + int count=0;//定数器实现切割判断经度纬度 + ArrayList log = new ArrayList<>(); + ArrayList lal = new ArrayList<>(); + for (String s : split) { + String[] split1 = s.split(","); + for (String s1 : split1) { + count++;//每次循环计数器加1 + if(count%2!=0){//计数器不是2的倍数代表经度 + log.add(s1); + }else{ //计数器是2的倍数 代表是纬度 + lal.add(s1); + } + } + } + ArrayList latitudelongitudes = new ArrayList<>(); + for (int i = 0; i < log.size(); i++) { + Latitudelongitude latitudelongitude1 = new Latitudelongitude(); + latitudelongitude1.setLongitude(Double.parseDouble(log.get(i))); + latitudelongitude1.setLatitude(Double.parseDouble(lal.get(i))); + latitudelongitudes.add(latitudelongitude1); + } + return latitudelongitudes; + } +} diff --git a/ruoyi-collect-server/src/main/java/com/ruoyi/collect/service/impl/EmpServiceImpl.java b/ruoyi-collect-server/src/main/java/com/ruoyi/collect/service/impl/EmpServiceImpl.java new file mode 100644 index 0000000..6ae8a5c --- /dev/null +++ b/ruoyi-collect-server/src/main/java/com/ruoyi/collect/service/impl/EmpServiceImpl.java @@ -0,0 +1,50 @@ +package com.ruoyi.collect.service.impl; + +import com.ruoyi.collect.domain.Emp; +import com.ruoyi.collect.mapper.EmpMapper; +import com.ruoyi.collect.service.EmpService; +import com.ruoyi.common.core.domain.R; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * @author Lff + * @Date: 2023/8/30 18:55 + * @Description: + */ +@Service +public class EmpServiceImpl implements EmpService { + @Autowired + private EmpMapper empMapper; + + @Override + public List EmpAll() { + //查询员工列表 + List emps = empMapper.EmpAll(); + + return emps; + } + + @Override + public int addEmp(Emp emp) { + return empMapper.addEmp(emp); + } + + @Override + public List showEmpById(Integer empId) { + List emps = empMapper.showEmpById(empId); + return emps; + } + + @Override + public R updateEmp(Emp emp) { + int i = empMapper.updateEmp(emp); + if(i>0){ + return R.ok("修改成功"); + }else{ + return R.ok("修改失败"); + } + } +} diff --git a/ruoyi-collect-server/src/main/java/com/ruoyi/collect/service/impl/IdentificationServiceImpl.java b/ruoyi-collect-server/src/main/java/com/ruoyi/collect/service/impl/IdentificationServiceImpl.java new file mode 100644 index 0000000..9969203 --- /dev/null +++ b/ruoyi-collect-server/src/main/java/com/ruoyi/collect/service/impl/IdentificationServiceImpl.java @@ -0,0 +1,67 @@ +package com.ruoyi.collect.service.impl; + +import com.ruoyi.collect.domain.Identification; +import com.ruoyi.collect.mapper.IdentificationMapper; +import com.ruoyi.collect.service.IdentificationService; +import com.ruoyi.common.core.domain.R; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * @author Lff + * @Date: 2023/9/11 20:50 + * @Description: + */ +@Service +public class IdentificationServiceImpl implements IdentificationService { + @Autowired + private IdentificationMapper identificationMapper; + @Override + public R> showIdentification() { + List identifications = identificationMapper.showIdentification(); + return R.ok(identifications); + } + + @Override + public R addIdentification(Identification identification) { + //添加標識表 + int i = identificationMapper.addIdentification(identification); + if(i>0){ + int i1=0; + for (Integer fence : identification.getFences()) { + i1 = identificationMapper.addFenceRecord(identification.getIdentificationId(), fence); + } + if(i1>0){ + return R.ok("添加成功"); + } + } + return R.ok("添加失敗"); + } + + @Override + public R updateIdentification(Identification identification) { + //修改標識 + int i = identificationMapper.deleteIdentification(identification.getIdentificationId()); + if(i>0){ + int i1=0; + for (Integer fence : identification.getFences()) { + i1 = identificationMapper.addFenceRecord(identification.getIdentificationId(), fence); + } + if(i1>0){ + return R.ok("修改成功"); + } + } + return R.ok("修改失敗"); + } + + @Override + public R deleteIdentification(Integer identificationId) { + int i = identificationMapper.deleteIdentification(identificationId); + if(i>0){ + return R.ok("刪除成功"); + } + return R.ok("刪除失敗"); + } +} diff --git a/ruoyi-collect-server/src/main/java/com/ruoyi/collect/utils/FenceUtils.java b/ruoyi-collect-server/src/main/java/com/ruoyi/collect/utils/FenceUtils.java new file mode 100644 index 0000000..c8e383c --- /dev/null +++ b/ruoyi-collect-server/src/main/java/com/ruoyi/collect/utils/FenceUtils.java @@ -0,0 +1,77 @@ +package com.ruoyi.collect.utils; + + + + +import java.awt.geom.GeneralPath; +import java.awt.geom.Point2D; +import java.util.ArrayList; +import java.util.List; + +public class FenceUtils { + + /** + * 此方法获取获取参数进行处理 + * @param latitudelongitude 需要判断的点位纵横坐标 + * @param list 区域各定点的纵横坐标 + * @return Boolean 是否存在于多变形内 + */ + public static Boolean isfence(Latitudelongitude latitudelongitude, List list){ + //经度坐标 + List lons = new ArrayList<>(); + //维度坐标 + List lats = new ArrayList<>(); + //车辆经度 + double plon= latitudelongitude.getLongitude(); + //车辆维度 + double plat= latitudelongitude.getLatitude(); + //围栏坐标点集合 + list.stream().forEach(item->{ + lons.add(item.getLongitude()); + lats.add(item.getLatitude()); + }); + return isInPolygon(plon,plat,lons,lats); + } + + + public static boolean isInPolygon(double pointLon,double pointLat, List lons,List lats){ + + //获取车辆坐标 转换成点 + Point2D.Double point=new Point2D.Double(pointLon,pointLat); + //创建一个点集合 + ArrayList points = new ArrayList<>(); + double polygonPoint_x=0.0; + double polygonPoint_y=0.0; + //116.00,25.00 114.00,53.00 + for (int i = 0; i < lons.size(); i++) { + polygonPoint_x=lons.get(i); + polygonPoint_y=lats.get(i); + Point2D.Double polygonPoint=new Point2D.Double(polygonPoint_x,polygonPoint_y); + points.add(polygonPoint); + } + //判断当前坐标点和围栏的关系 + return verdict(point, points); + } + + private static boolean verdict(Point2D.Double point, ArrayList points) { + //verdict + //创建一个GenralPath对象 + GeneralPath generalPath = new GeneralPath(); + //创建第一个临近点 + Point2D.Double p1= points.get(0); + //通过移动到指定坐标,将一个点添加到路径中,作为操作第一个点 + generalPath.moveTo(p1.x,p1.y); + //从多边形列表一处第一个坐标点 + //points.remove(0); + //判断其他多边形的其他点 + for (Point2D.Double pp : points) { + generalPath.lineTo(pp.x,pp.y); + } + //循环结束后的最后一个坐标 行程闭环 + generalPath.lineTo(p1.x,p1.y); + //创建完成,关闭路径 + generalPath.closePath(); + //测试指定的点 是否在边界内 + return generalPath.contains(point); + } +} diff --git a/ruoyi-collect-server/src/main/java/com/ruoyi/collect/utils/Latitudelongitude.java b/ruoyi-collect-server/src/main/java/com/ruoyi/collect/utils/Latitudelongitude.java new file mode 100644 index 0000000..f8c10de --- /dev/null +++ b/ruoyi-collect-server/src/main/java/com/ruoyi/collect/utils/Latitudelongitude.java @@ -0,0 +1,9 @@ +package com.ruoyi.collect.utils; + +import lombok.Data; + +@Data +public class Latitudelongitude { + public double longitude; + public double Latitude; +} diff --git a/ruoyi-collect-server/src/main/java/com/ruoyi/collect/utils/Text.java b/ruoyi-collect-server/src/main/java/com/ruoyi/collect/utils/Text.java new file mode 100644 index 0000000..aff3462 --- /dev/null +++ b/ruoyi-collect-server/src/main/java/com/ruoyi/collect/utils/Text.java @@ -0,0 +1,58 @@ +package com.ruoyi.collect.utils; + +import java.util.ArrayList; +import java.util.List; + +public class Text { + + public static void main(String[] args) { + //车辆坐标 121.477937,31.238281(内) =========================== + Latitudelongitude indoor = new Latitudelongitude(); + //纬度坐标 + indoor.setLatitude(121.477937); + //经度坐标 + indoor.setLongitude(31.238281); + //车辆坐标 120.521853,31.607563(外)=========================== + Latitudelongitude outdoor = new Latitudelongitude(); + //纬度坐标 + outdoor.setLatitude(120.521853); + //经度坐标 + outdoor.setLongitude(31.607563); + + //121.357205,31.309392;121.647537,31.191832;121.39515,31.120632 + // ===============================在多边形坐标点集合=================================== + List latitudelongitudes = new ArrayList<>(); + //121.357205,31.309392 121.647537,31.191832 121.39515,31.120632 + Latitudelongitude l1 = new Latitudelongitude(); + //纬度坐标 + + l1.setLatitude(121.357205); + //经度坐标 + l1.setLongitude(31.309392); + Latitudelongitude l2 = new Latitudelongitude(); + //纬度坐标 + l2.setLatitude(121.647537); + //经度坐标 + l2.setLongitude(31.191832); + Latitudelongitude l3 = new Latitudelongitude(); + //纬度坐标 + l3.setLatitude(121.39515); + //经度坐标 + l3.setLongitude(31.120632); + latitudelongitudes.add(l1); + latitudelongitudes.add(l2); + latitudelongitudes.add(l3); + + for (Latitudelongitude latitudelongitude1 : latitudelongitudes) { + System.out.println("坐标点:"+latitudelongitude1); + } + Boolean isfence = FenceUtils.isfence(outdoor, latitudelongitudes); + if (isfence==true){ + System.out.println("在电子围栏内部"); + }else { + + System.out.println("在电子围栏外部"); + } + + } +} diff --git a/ruoyi-collect-server/src/main/resources/banner.txt b/ruoyi-collect-server/src/main/resources/banner.txt new file mode 100644 index 0000000..fbd45f5 --- /dev/null +++ b/ruoyi-collect-server/src/main/resources/banner.txt @@ -0,0 +1,10 @@ +Spring Boot Version: ${spring-boot.version} +Spring Application Name: ${spring.application.name} + _ _ + (_) | | + _ __ _ _ ___ _ _ _ ______ ___ _ _ ___ | |_ ___ _ __ ___ +| '__|| | | | / _ \ | | | || ||______|/ __|| | | |/ __|| __| / _ \| '_ ` _ \ +| | | |_| || (_) || |_| || | \__ \| |_| |\__ \| |_ | __/| | | | | | +|_| \__,_| \___/ \__, ||_| |___/ \__, ||___/ \__| \___||_| |_| |_| + __/ | __/ | + |___/ |___/ \ No newline at end of file diff --git a/ruoyi-collect-server/src/main/resources/bootstrap.yml b/ruoyi-collect-server/src/main/resources/bootstrap.yml new file mode 100644 index 0000000..865a73f --- /dev/null +++ b/ruoyi-collect-server/src/main/resources/bootstrap.yml @@ -0,0 +1,47 @@ +# Tomcat +server: + port: 3336 +# Spring +spring: + rabbitmq: + host: 10.100.27.4 + port: 5672 + username: guest + password: guest + virtualHost: / + listener: + simple: + prefetch: 1 # 每次只能获取一条,处理完成才能获取下一条 + acknowledge-mode: manual # 设置消费端手动ack确认 + retry: + enabled: true # 是否支持重试 + publisher-confirm-type: correlated #确认消息已发送到交换机(Exchange) + publisher-returns: true #确认消息已发送到队列(Queue) + + mail: + host: smtp.qq.com + port: 587 + username: 3079188394@qq.com + password: olztxtpchenrdfdi + application: + # 应用名称 + name: ruoyi-collect + profiles: + # 环境配置 + active: dev + cloud: + nacos: + discovery: + # 服务注册地址 + server-addr: 10.100.27.4:8848 + config: + # 配置中心地址 + server-addr: 10.100.27.4:8848 + # 配置文件格式 + file-extension: yml + # 共享配置 + shared-configs: + - application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension} +kafka: + bootstrap-servers: 43.142.96.146:9092,43.142.96.146:9093,43.142.96.146:9094 + diff --git a/ruoyi-collect-server/src/main/resources/logback.xml b/ruoyi-collect-server/src/main/resources/logback.xml new file mode 100644 index 0000000..7cf104f --- /dev/null +++ b/ruoyi-collect-server/src/main/resources/logback.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + ${log.pattern} + + + + + + ${log.path}/info.log + + + + ${log.path}/info.%d{yyyy-MM-dd}.log + + 60 + + + ${log.pattern} + + + + INFO + + ACCEPT + + DENY + + + + + ${log.path}/error.log + + + + ${log.path}/error.%d{yyyy-MM-dd}.log + + 60 + + + ${log.pattern} + + + + ERROR + + ACCEPT + + DENY + + + + + + + + + + + + + + + + + + diff --git a/ruoyi-collect-server/src/main/resources/mapper/collect/BusinessMapper.xml b/ruoyi-collect-server/src/main/resources/mapper/collect/BusinessMapper.xml new file mode 100644 index 0000000..77b3040 --- /dev/null +++ b/ruoyi-collect-server/src/main/resources/mapper/collect/BusinessMapper.xml @@ -0,0 +1,55 @@ + + + + + insert into electronic_fence_setting ( + firm_id, + fence_name, + address, + log_lat, + create_time, + create_name, + update_time, + end_time, + update_name, + deletion, + fence_status + ) + values ( + #{firmId}, + #{fenceName}, + #{address}, + null, + #{createTime}, + #{createName}, + null, + null, + null, + 1, + 1 + ) + + + update electronic_fence_setting set + firm_id=#{firmId},fence_name=#{fenceName},address=#{address}, + log_lat=#{logLat},create_time=#{createTime},create_name=#{createName}, + update_time=#{updateTime},end_time=#{endTime},update_name=#{updateName},fence_status=#{fenceStatus} + where fence_id=#{fenceId} + + + update electronic_fence_setting set deletion=2 where fence_id=#{fenceId} + + + update electronic_fence_setting set fence_status=#{fenceStatus} where fence_id=#{fenceId} + + + + + + diff --git a/ruoyi-collect-server/src/main/resources/mapper/collect/CarMapper.xml b/ruoyi-collect-server/src/main/resources/mapper/collect/CarMapper.xml new file mode 100644 index 0000000..e8171b7 --- /dev/null +++ b/ruoyi-collect-server/src/main/resources/mapper/collect/CarMapper.xml @@ -0,0 +1,149 @@ + + + + + insert into car( + car_id, + car_name, + type_id, + manufacturer_name, + battery_name, + manufacturer_desc, + battery_desc, + car_status, + car_vin, + firm_id, + deletion + ) values( + 0, + #{carName}, + #{typeId}, + #{manufacturerName}, + #{batteryName}, + #{manufacturerDesc}, + #{batteryDesc}, + 0, + #{carVin}, + #{firmId}, + 1 + ) + + + + insert into car_record (car_vin,create_date,start_key) values (#{carVin},#{createDate},#{startKey}) + + + insert into car_bs_record values (null,#{identificationId},#{carId},1) + + + update car set deletion=2 where car_id=#{carId} + + + update car set car_name=#{carName},type_id=#{typeId}, + manufacturer_name=#{manufacturerName}, + battery_name=#{batteryName},manufacturer_desc=#{manufacturerDesc}, + battery_desc=#{batteryDesc}, + car_vin=#{carVin},firm_id=#{firmId} + where car_id=#{carId} + + + update car set car_status=1 where car_vin=#{carVin} + + + update car set car_status=0 where car_vin=#{carVin} + + + update car_record set end_date=#{endDate},end_key=#{endKey} where record_id=#{recordId} + + + delete from car_bs_record where car_id=#{carId} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ruoyi-collect-server/src/main/resources/mapper/collect/EmpMapper.xml b/ruoyi-collect-server/src/main/resources/mapper/collect/EmpMapper.xml new file mode 100644 index 0000000..d312d63 --- /dev/null +++ b/ruoyi-collect-server/src/main/resources/mapper/collect/EmpMapper.xml @@ -0,0 +1,22 @@ + + + + + insert into f_emp (emp_name,emp_sex,emp_phone,email,firm_id,emp_status) + values (#{empName},#{empSex},#{empPhone},#{email},#{firmId},1) + + + update f_emp set emp_name=#{empName},emp_sex=#{empSex},emp_phone=#{empPhone},email=#{email},firm_id=#{firmId} where emp_id=#{empId} + + + + + + diff --git a/ruoyi-collect-server/src/main/resources/mapper/collect/IdentificationMapper.xml b/ruoyi-collect-server/src/main/resources/mapper/collect/IdentificationMapper.xml new file mode 100644 index 0000000..7650c3d --- /dev/null +++ b/ruoyi-collect-server/src/main/resources/mapper/collect/IdentificationMapper.xml @@ -0,0 +1,18 @@ + + + + + insert into identification values (null,#{identificationName},1) + + + insert into fence_record values (null,#{identificationId},#{fence},1) + + + delete from fence_record where identification_id=#{identificationId} + + + diff --git a/ruoyi-vehicle-cache/pom.xml b/ruoyi-vehicle-cache/pom.xml new file mode 100644 index 0000000..c4b0874 --- /dev/null +++ b/ruoyi-vehicle-cache/pom.xml @@ -0,0 +1,25 @@ + + + 4.0.0 + + com.ruoyi + ruoyi-modules-collect + 3.6.3 + + + com.gu + ruoyi-vehicle-cache + pom + + ruoyi-business-cache + + + + 8 + 8 + UTF-8 + + + \ No newline at end of file diff --git a/ruoyi-vehicle-cache/ruoyi-business-cache/.gitignore b/ruoyi-vehicle-cache/ruoyi-business-cache/.gitignore new file mode 100644 index 0000000..5ff6309 --- /dev/null +++ b/ruoyi-vehicle-cache/ruoyi-business-cache/.gitignore @@ -0,0 +1,38 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/ruoyi-vehicle-cache/ruoyi-business-cache/pom.xml b/ruoyi-vehicle-cache/ruoyi-business-cache/pom.xml new file mode 100644 index 0000000..12cdd9f --- /dev/null +++ b/ruoyi-vehicle-cache/ruoyi-business-cache/pom.xml @@ -0,0 +1,28 @@ + + + 4.0.0 + + com.gu + ruoyi-vehicle-cache + 3.6.3 + + + ruoyi-business-cache + + + 8 + 8 + UTF-8 + + + + + com.ruoyi + ruoyi-collect-common + 3.6.3 + + + + \ No newline at end of file diff --git a/ruoyi-vehicle-cache/ruoyi-business-cache/src/main/java/com/ruoyi/vehicle/cache/fence/FenceCache.java b/ruoyi-vehicle-cache/ruoyi-business-cache/src/main/java/com/ruoyi/vehicle/cache/fence/FenceCache.java new file mode 100644 index 0000000..f8dfdc9 --- /dev/null +++ b/ruoyi-vehicle-cache/ruoyi-business-cache/src/main/java/com/ruoyi/vehicle/cache/fence/FenceCache.java @@ -0,0 +1,31 @@ +package com.ruoyi.vehicle.cache.fence; + + +import com.ruoyi.collect.domain.cache.fence.FenceIdTypeCache; + +import java.util.List; +import java.util.concurrent.ConcurrentHashMap; + +/** + * 围栏缓存 + */ +public class FenceCache { + + /** + * 车辆和围栏的绑定 + */ + private final static ConcurrentHashMap FENCE_MAP = new ConcurrentHashMap<>(); + + protected static void put(String vin,double[][] coordinate){ + FENCE_MAP.put(vin,coordinate); + } + + protected static double[][] get(String vin){ + return FENCE_MAP.get(vin); + } + + protected static void remove(String vin){ + FENCE_MAP.remove(vin); + } + +} diff --git a/ruoyi-vehicle-cache/ruoyi-business-cache/src/main/java/com/ruoyi/vehicle/cache/fence/VehicleFenceCache.java b/ruoyi-vehicle-cache/ruoyi-business-cache/src/main/java/com/ruoyi/vehicle/cache/fence/VehicleFenceCache.java new file mode 100644 index 0000000..e3d81aa --- /dev/null +++ b/ruoyi-vehicle-cache/ruoyi-business-cache/src/main/java/com/ruoyi/vehicle/cache/fence/VehicleFenceCache.java @@ -0,0 +1,31 @@ +package com.ruoyi.vehicle.cache.fence; + + +import com.ruoyi.collect.domain.cache.fence.FenceIdTypeCache; + +import java.util.List; +import java.util.concurrent.ConcurrentHashMap; + +/** + * 车辆围栏 + */ +public class VehicleFenceCache { + + /** + * 车辆和围栏的绑定 + */ + private final static ConcurrentHashMap> CACHE_MAP = new ConcurrentHashMap<>(); + + protected static List getFenceList(String vin) { + return CACHE_MAP.get(vin); + } + + protected static void setFenceList(String vin,List fenceIdTypeCacheList) { + CACHE_MAP.put(vin,fenceIdTypeCacheList); + } + + protected static void remove(String vin){ + CACHE_MAP.remove(vin); + } + +} diff --git a/ruoyi-vehicle-cache/ruoyi-business-cache/src/main/java/com/ruoyi/vehicle/cache/fence/VehicleFenceCacheService.java b/ruoyi-vehicle-cache/ruoyi-business-cache/src/main/java/com/ruoyi/vehicle/cache/fence/VehicleFenceCacheService.java new file mode 100644 index 0000000..118b6d7 --- /dev/null +++ b/ruoyi-vehicle-cache/ruoyi-business-cache/src/main/java/com/ruoyi/vehicle/cache/fence/VehicleFenceCacheService.java @@ -0,0 +1,29 @@ +package com.ruoyi.vehicle.cache.fence; + +import com.ruoyi.collect.domain.cache.fence.FenceIdTypeCache; +import com.ruoyi.collect.domain.cache.fence.FenceInfoTypeCache; + +import java.util.ArrayList; +import java.util.List; +import java.util.function.Function; +import java.util.stream.Collectors; + +/** + * 围栏车辆缓存 + */ +public class VehicleFenceCacheService { + + public List get(String vin){ + List fenceList = VehicleFenceCache.getFenceList(vin); + if (fenceList == null || fenceList.size() == 0){ + return new ArrayList<>(); + } + + return fenceList.stream().map(fenceIdTypeCache -> FenceInfoTypeCache.builder() + .coordinate(FenceCache.get(fenceIdTypeCache.getFenceId())) + .fenceType(fenceIdTypeCache.getFenceType()) + .build()) + .collect(Collectors.toList()); + } + +} diff --git a/ruoyi-vehicle-cache/ruoyi-business-cache/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/ruoyi-vehicle-cache/ruoyi-business-cache/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports new file mode 100644 index 0000000..f245874 --- /dev/null +++ b/ruoyi-vehicle-cache/ruoyi-business-cache/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -0,0 +1 @@ +com.ruoyi.vehicle.cache.fence.VehicleFenceCacheService \ No newline at end of file