COMMIT FIRST
commit
63906dc829
|
@ -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
|
|
@ -0,0 +1,18 @@
|
|||
#起始镜像
|
||||
FROM anolis-registry.cn-zhangjiakou.cr.aliyuncs.com/openanolis/openjdk:17-8.6
|
||||
#暴露端口号
|
||||
EXPOSE 8066
|
||||
#挂载目录的位置
|
||||
VOLUME /home/logs/vehicleTest
|
||||
#构建复制外部文件到docker
|
||||
COPY /target/VehicleTest-0.0.1-SNAPSHOT.jar /home/app.jar
|
||||
#工作目录 exec -it 进入容器内部后的默认的起始目录
|
||||
WORKDIR /home
|
||||
ENV TIME_ZONE Asia/Shanghai
|
||||
#指定东八区
|
||||
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
|
||||
|
||||
#启动java 程序
|
||||
ENTRYPOINT ["java","-Dfile.encoding=UTF-8","-jar","/home/app.jar"]
|
||||
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.vehicle</groupId>
|
||||
<artifactId>VehicleTest</artifactId>
|
||||
<version>3.6.3</version>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
<version>2.7.15</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
<version>2.7.15</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>8.0.29</version>
|
||||
</dependency>
|
||||
<!-- mybatis - plus 依赖 -->
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||
<version>3.5.3.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.28</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains</groupId>
|
||||
<artifactId>annotations</artifactId>
|
||||
<version>13.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>jakarta.validation</groupId>
|
||||
<artifactId>jakarta.validation-api</artifactId>
|
||||
<version>2.0.2</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -0,0 +1,39 @@
|
|||
package com.vehicle.controller;
|
||||
|
||||
|
||||
import com.vehicle.domain.common.req.VehicleOnlineReq;
|
||||
import com.vehicle.service.VehicleService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* @author 冯凯
|
||||
* @version 1.0
|
||||
* @description: 车辆上线控制层
|
||||
* @date 2023/11/27 14:01
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/vehicle")
|
||||
public class VehicleOnlineController {
|
||||
|
||||
@Autowired
|
||||
private VehicleService vehicleService;
|
||||
|
||||
/**
|
||||
* 将车辆在线请求转换为车辆在线对象
|
||||
*
|
||||
* @param vehicleOnlineReq 车辆在线请求对象
|
||||
*/
|
||||
@PostMapping("/online")
|
||||
public String vehicleOnline(@RequestBody @Validated VehicleOnlineReq vehicleOnlineReq) {
|
||||
vehicleService.vehicleOnline(vehicleOnlineReq);
|
||||
//返回该车辆的主题
|
||||
return "topic_"+vehicleOnlineReq.getVin();
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
package com.vehicle.domain.common.req;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @author 冯凯
|
||||
* @version 1.0
|
||||
* @description: 车辆上线请求实体类
|
||||
* @date 2023/11/27 14:14
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@TableName("user")
|
||||
public class VehicleOnlineReq {
|
||||
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Integer id;
|
||||
/**
|
||||
* 车辆VIN
|
||||
*/
|
||||
@NotNull( message= "VIN不能为空")
|
||||
private String vin;
|
||||
|
||||
/**
|
||||
* 车辆登陆用户名
|
||||
*/
|
||||
@NotNull(message = "用户名不能为空")
|
||||
private String username;
|
||||
|
||||
/**
|
||||
* 上线时间
|
||||
*/
|
||||
@TableField(exist = false)
|
||||
private Date onlineTime;
|
||||
|
||||
/**
|
||||
* 车辆登陆密码
|
||||
*/
|
||||
@NotNull(message = "密码不能为空")
|
||||
private String password;
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package com.vehicle.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
import com.vehicle.domain.common.req.VehicleOnlineReq;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* @author 冯凯
|
||||
* @version 1.0
|
||||
* @description: 车辆上线接口
|
||||
* @date 2023/11/27 14:30
|
||||
*/
|
||||
|
||||
@Mapper
|
||||
public interface VehicleOnlineMapper extends BaseMapper<VehicleOnlineReq> {
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package com.vehicle.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.vehicle.domain.common.req.VehicleOnlineReq;
|
||||
|
||||
|
||||
/**
|
||||
* @author 冯凯
|
||||
* @version 1.0
|
||||
* @description: 车辆业务
|
||||
* @date 2023/11/27 14:26
|
||||
*/
|
||||
public interface VehicleService extends IService<VehicleOnlineReq> {
|
||||
void vehicleOnline(VehicleOnlineReq vehicleOnlineReq);
|
||||
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
package com.vehicle.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
|
||||
import com.vehicle.domain.common.req.VehicleOnlineReq;
|
||||
import com.vehicle.mapper.VehicleOnlineMapper;
|
||||
import com.vehicle.service.VehicleService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import static com.vehicle.utils.Md5Util.md5Encrypt;
|
||||
|
||||
|
||||
/**
|
||||
* @author 冯凯
|
||||
* @version 1.0
|
||||
* @description: 车辆业务实现类
|
||||
* @date 2023/11/27 14:27
|
||||
*/
|
||||
@Service
|
||||
public class VehicleServiceImpl extends ServiceImpl<VehicleOnlineMapper, VehicleOnlineReq> implements VehicleService {
|
||||
/**
|
||||
* 车辆上线请求的回调函数
|
||||
*
|
||||
* @param vehicleOnlineReq 车辆上线请求参数
|
||||
*/
|
||||
@Override
|
||||
public void vehicleOnline(VehicleOnlineReq vehicleOnlineReq) {
|
||||
String vin = vehicleOnlineReq.getVin();
|
||||
String username = vehicleOnlineReq.getUsername();
|
||||
String time = System.currentTimeMillis() + "";
|
||||
// String time = vehicleOnlineReq.getOnlineTime().getTime() + "";
|
||||
String message=vin+time+username; // 拼接所要加密消息
|
||||
String password = md5Encrypt(message); // 加密
|
||||
vehicleOnlineReq.setPassword(password);
|
||||
this.save(vehicleOnlineReq);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
package com.vehicle.utils;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
/**
|
||||
* @author 冯凯
|
||||
* @version 1.0
|
||||
* @description:
|
||||
* @date 2023/11/27 14:46
|
||||
*/
|
||||
public class Md5Util {
|
||||
|
||||
public static String md5Encrypt(String message) {
|
||||
try {
|
||||
// 创建MD5消息摘要对象
|
||||
MessageDigest md = MessageDigest.getInstance("MD5");
|
||||
|
||||
// 更新消息摘要
|
||||
md.update(message.getBytes());
|
||||
|
||||
// 获取摘要结果
|
||||
byte[] digest = md.digest();
|
||||
|
||||
// 将字节数组转换为BigInteger类型
|
||||
BigInteger bigInt = new BigInteger(1, digest);
|
||||
|
||||
// 将BigInteger类型转换为16进制字符串
|
||||
String encryptedMessage = bigInt.toString(16);
|
||||
|
||||
// 补齐前导0直到长度为32
|
||||
while (encryptedMessage.length() < 32) {
|
||||
encryptedMessage = "0" + encryptedMessage;
|
||||
}
|
||||
|
||||
return encryptedMessage;
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
spring:
|
||||
application:
|
||||
name: mqttDemo
|
||||
datasource:
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
url: jdbc:mysql://124.221.216.186:3306/mqtt?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8
|
||||
username: root
|
||||
password: 27a9601cb3545824
|
||||
server:
|
||||
port: 8066
|
Loading…
Reference in New Issue