feat():账号密码存入数据库

dev.vehiclegateway
SuiXxx 2024-10-06 20:04:08 +08:00
parent 6ba71a95d4
commit 705414778c
10 changed files with 116 additions and 42 deletions

View File

@ -121,11 +121,11 @@ public class ManageInstance implements ApplicationRunner {
log.info("正在加载实例");
Thread.sleep(30000);
List<InstanceInfo> instanceInfos = SelectInstance.selectInstance(list);
log.info("实例信息加载成功");
for (InstanceInfo instanceInfo : instanceInfos) {
redisService.getCacheObject(instanceInfo.getInstanceId());
} log.info("实例信息:{}",instanceInfos);
log.info("实例信息查询成功");
// for (InstanceInfo instanceInfo : instanceInfos) {
// redisService.getCacheObject(instanceInfo.getInstanceId());
// }
log.info("实例信息:",instanceInfos);
}
}

View File

@ -0,0 +1,8 @@
package com.muyu.vehicle.config;
/**
* fluxMq
*/
public class ConnectFluxMq {
}

View File

@ -1,29 +0,0 @@
package com.muyu.vehicle.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.ClientHttpRequestFactory;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;
@Configuration
public class RestTemplateConfig {
@Bean
public RestTemplate restTemplate(ClientHttpRequestFactory factory){
return new RestTemplate(factory);
}
@Bean
public ClientHttpRequestFactory simpleClientHttpRequestFactory() {
SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
//超时设置
factory.setReadTimeout(5000);//ms
factory.setConnectTimeout(15000);//ms
return factory;
}
}

View File

@ -35,7 +35,7 @@ public class SelectInstance {
DescribeInstancesResponse resp = client.describeInstancesWithOptions(describeInstancesRequest, runtime);
DescribeInstancesResponseBody body = resp.getBody();
ArrayList<InstanceInfo> exampleInformations = new ArrayList<>();
ArrayList<InstanceInfo> list = new ArrayList<>();
for (DescribeInstancesResponseBody.DescribeInstancesResponseBodyInstancesInstance instance : body.getInstances().getInstance()){
InstanceInfo instanceInfo = new InstanceInfo();
instanceInfo.setInstanceId(instance.getInstanceId());
@ -44,9 +44,9 @@ public class SelectInstance {
log.info("实例状态:{}",instanceInfo.getStatus());
instanceInfo.setIpAddress(String.valueOf(instance.getPublicIpAddress().getIpAddress()));
log.info("实例IP:{}",instanceInfo.getIpAddress());
exampleInformations.add(instanceInfo);
list.add(instanceInfo);
}
log.info("实例信息:{}",instanceInfos);
log.info("实例信息:",list);
return instanceInfos;
}

View File

@ -1,19 +1,27 @@
package com.muyu.vehicle.controller;
import com.muyu.common.core.domain.Result;
import com.muyu.vehicle.domain.VehicleAuthentication;
import com.muyu.vehicle.domain.req.VehicleConnectionReq;
import com.muyu.vehicle.service.VehicleAuthenticationService;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@RestController
@Log4j2
@RestController
@RequestMapping("/carInstance")
public class CarInstanceController {
@Autowired
private VehicleAuthenticationService vehicleAuthenticationService;
@PostMapping("/receiveMsg/connect")
@PostMapping("/receiveMsg")
public Result receiveMsg(@RequestBody VehicleConnectionReq vehicleConnectionReq){
log.info("=======>"+vehicleConnectionReq);
return Result.success();
VehicleAuthentication vehicleAuthentication = VehicleAuthentication.buildVehicle(vehicleConnectionReq);
Integer i = vehicleAuthenticationService.insertVehicleAuthentication(vehicleAuthentication);
return i>0?Result.success():Result.error();
}
}

View File

@ -0,0 +1,51 @@
package com.muyu.vehicle.domain;
import com.muyu.vehicle.domain.req.VehicleConnectionReq;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
/**
*
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class VehicleAuthentication {
/**
* ID
*/
private Integer id;
/**
* VIN
*/
private String vin;
/**
*
*/
private String userName;
/**
*
*/
private String password;
public static VehicleAuthentication buildVehicle(VehicleConnectionReq req){
return builder()
.vin(req.getVehicleVin())
.userName(req.getUsername())
.password((req.getVehicleVin()+req.getTimestamp()+req.getNonce()))
.build();
}
}

View File

@ -0,0 +1,9 @@
package com.muyu.vehicle.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.muyu.vehicle.domain.VehicleAuthentication;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface VehicleAuthenticationMapper extends BaseMapper<VehicleAuthentication> {
}

View File

@ -0,0 +1,10 @@
package com.muyu.vehicle.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.muyu.common.domain.DataType;
import com.muyu.vehicle.domain.VehicleAuthentication;
import org.springframework.beans.factory.annotation.Autowired;
public interface VehicleAuthenticationService extends IService<VehicleAuthentication> {
Integer insertVehicleAuthentication(VehicleAuthentication vehicleAuthentication);
}

View File

@ -2,12 +2,10 @@ package com.muyu.vehicle.service.impl;
import com.muyu.common.core.domain.Result;
import com.muyu.common.core.utils.uuid.UUID;
import com.muyu.vehicle.config.RestTemplateConfig;
import com.muyu.vehicle.domain.MqttServerModel;
import com.muyu.vehicle.domain.req.VehicleConnectionReq;
import com.muyu.vehicle.service.CarInstanceService;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**

View File

@ -0,0 +1,19 @@
package com.muyu.vehicle.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.muyu.vehicle.domain.VehicleAuthentication;
import com.muyu.vehicle.mapper.VehicleAuthenticationMapper;
import com.muyu.vehicle.service.VehicleAuthenticationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class VehicleAuthenticationServiceImpl extends ServiceImpl<VehicleAuthenticationMapper, VehicleAuthentication> implements VehicleAuthenticationService {
@Autowired
private VehicleAuthenticationMapper vehicleAuthenticationMapper;
@Override
public Integer insertVehicleAuthentication(VehicleAuthentication vehicleAuthentication) {
return vehicleAuthenticationMapper.insert(vehicleAuthentication);
}
}