diff --git a/cloud-modules/cloud-modules-vehiclegateway/src/main/java/com/muyu/vehicle/ManageInstance.java b/cloud-modules/cloud-modules-vehiclegateway/src/main/java/com/muyu/vehicle/ManageInstance.java index 3e590ca..51e009b 100644 --- a/cloud-modules/cloud-modules-vehiclegateway/src/main/java/com/muyu/vehicle/ManageInstance.java +++ b/cloud-modules/cloud-modules-vehiclegateway/src/main/java/com/muyu/vehicle/ManageInstance.java @@ -121,11 +121,11 @@ public class ManageInstance implements ApplicationRunner { log.info("正在加载实例"); Thread.sleep(30000); List 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); } } diff --git a/cloud-modules/cloud-modules-vehiclegateway/src/main/java/com/muyu/vehicle/config/ConnectFluxMq.java b/cloud-modules/cloud-modules-vehiclegateway/src/main/java/com/muyu/vehicle/config/ConnectFluxMq.java new file mode 100644 index 0000000..44fa9e6 --- /dev/null +++ b/cloud-modules/cloud-modules-vehiclegateway/src/main/java/com/muyu/vehicle/config/ConnectFluxMq.java @@ -0,0 +1,8 @@ +package com.muyu.vehicle.config; + +/** + * 链接fluxMq + */ +public class ConnectFluxMq { + +} diff --git a/cloud-modules/cloud-modules-vehiclegateway/src/main/java/com/muyu/vehicle/config/RestTemplateConfig.java b/cloud-modules/cloud-modules-vehiclegateway/src/main/java/com/muyu/vehicle/config/RestTemplateConfig.java deleted file mode 100644 index 2cff8fb..0000000 --- a/cloud-modules/cloud-modules-vehiclegateway/src/main/java/com/muyu/vehicle/config/RestTemplateConfig.java +++ /dev/null @@ -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; - } -} diff --git a/cloud-modules/cloud-modules-vehiclegateway/src/main/java/com/muyu/vehicle/config/SelectInstance.java b/cloud-modules/cloud-modules-vehiclegateway/src/main/java/com/muyu/vehicle/config/SelectInstance.java index 73c5a00..c6645c2 100644 --- a/cloud-modules/cloud-modules-vehiclegateway/src/main/java/com/muyu/vehicle/config/SelectInstance.java +++ b/cloud-modules/cloud-modules-vehiclegateway/src/main/java/com/muyu/vehicle/config/SelectInstance.java @@ -35,7 +35,7 @@ public class SelectInstance { DescribeInstancesResponse resp = client.describeInstancesWithOptions(describeInstancesRequest, runtime); DescribeInstancesResponseBody body = resp.getBody(); - ArrayList exampleInformations = new ArrayList<>(); + ArrayList 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; } diff --git a/cloud-modules/cloud-modules-vehiclegateway/src/main/java/com/muyu/vehicle/controller/CarInstanceController.java b/cloud-modules/cloud-modules-vehiclegateway/src/main/java/com/muyu/vehicle/controller/CarInstanceController.java index 2ba2c33..4c90f15 100644 --- a/cloud-modules/cloud-modules-vehiclegateway/src/main/java/com/muyu/vehicle/controller/CarInstanceController.java +++ b/cloud-modules/cloud-modules-vehiclegateway/src/main/java/com/muyu/vehicle/controller/CarInstanceController.java @@ -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(); } } diff --git a/cloud-modules/cloud-modules-vehiclegateway/src/main/java/com/muyu/vehicle/domain/VehicleAuthentication.java b/cloud-modules/cloud-modules-vehiclegateway/src/main/java/com/muyu/vehicle/domain/VehicleAuthentication.java new file mode 100644 index 0000000..1a3a95e --- /dev/null +++ b/cloud-modules/cloud-modules-vehiclegateway/src/main/java/com/muyu/vehicle/domain/VehicleAuthentication.java @@ -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(); + } + + + +} diff --git a/cloud-modules/cloud-modules-vehiclegateway/src/main/java/com/muyu/vehicle/mapper/VehicleAuthenticationMapper.java b/cloud-modules/cloud-modules-vehiclegateway/src/main/java/com/muyu/vehicle/mapper/VehicleAuthenticationMapper.java new file mode 100644 index 0000000..0777888 --- /dev/null +++ b/cloud-modules/cloud-modules-vehiclegateway/src/main/java/com/muyu/vehicle/mapper/VehicleAuthenticationMapper.java @@ -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 { +} diff --git a/cloud-modules/cloud-modules-vehiclegateway/src/main/java/com/muyu/vehicle/service/VehicleAuthenticationService.java b/cloud-modules/cloud-modules-vehiclegateway/src/main/java/com/muyu/vehicle/service/VehicleAuthenticationService.java new file mode 100644 index 0000000..6a4833e --- /dev/null +++ b/cloud-modules/cloud-modules-vehiclegateway/src/main/java/com/muyu/vehicle/service/VehicleAuthenticationService.java @@ -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 { + Integer insertVehicleAuthentication(VehicleAuthentication vehicleAuthentication); +} diff --git a/cloud-modules/cloud-modules-vehiclegateway/src/main/java/com/muyu/vehicle/service/impl/CarInstanceServiceImpl.java b/cloud-modules/cloud-modules-vehiclegateway/src/main/java/com/muyu/vehicle/service/impl/CarInstanceServiceImpl.java index 20cbe53..e5f57a6 100644 --- a/cloud-modules/cloud-modules-vehiclegateway/src/main/java/com/muyu/vehicle/service/impl/CarInstanceServiceImpl.java +++ b/cloud-modules/cloud-modules-vehiclegateway/src/main/java/com/muyu/vehicle/service/impl/CarInstanceServiceImpl.java @@ -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; /** diff --git a/cloud-modules/cloud-modules-vehiclegateway/src/main/java/com/muyu/vehicle/service/impl/VehicleAuthenticationServiceImpl.java b/cloud-modules/cloud-modules-vehiclegateway/src/main/java/com/muyu/vehicle/service/impl/VehicleAuthenticationServiceImpl.java new file mode 100644 index 0000000..e85b35b --- /dev/null +++ b/cloud-modules/cloud-modules-vehiclegateway/src/main/java/com/muyu/vehicle/service/impl/VehicleAuthenticationServiceImpl.java @@ -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 implements VehicleAuthenticationService { + @Autowired + private VehicleAuthenticationMapper vehicleAuthenticationMapper; + @Override + public Integer insertVehicleAuthentication(VehicleAuthentication vehicleAuthentication) { + return vehicleAuthenticationMapper.insert(vehicleAuthentication); + } +}