master
肖凡 2024-04-20 10:30:11 +08:00
parent 79e1240de4
commit 1f4a28ea11
7 changed files with 125 additions and 0 deletions

View File

@ -214,6 +214,9 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>

View File

@ -0,0 +1,21 @@
package com.xiaofan.loadcenter.common.aliyun.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;
/**
* @ProjectName: LoadCenter
* @PackageName: com.xiaofan.loadcenter.common.aliyun.config
* @Description TODO
* @Author XiaoFan
* @Date 2024/4/20 10:28
* @Version 1.0
*/
@Configuration
public class AppConfig {
@Bean
public RestTemplate restTemplate(){
return new RestTemplate();
}
}

View File

@ -0,0 +1,34 @@
package com.xiaofan.loadcenter.controller;
import com.xiaofan.loadcenter.common.domain.Result;
import com.xiaofan.loadcenter.service.GatewayVehicleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @ProjectName: LoadCenter
* @PackageName: com.xiaofan.loadcenter.controller
* @Description TODO
* @Author XiaoFan
* @Date 2024/4/20 09:44
* @Version 1.0
*/
@RestController
@RequestMapping("/vehicle")
public class GatewayVehicleController {
@Autowired
private GatewayVehicleService gatewayVehicleService;
@GetMapping("/load/topLine/{vin}")
public Result<String> topLine(@PathVariable String vin){
return gatewayVehicleService.topLine(vin);
}
@GetMapping("/load/downLine/{vin}")
public void loadDownLine(@PathVariable String vin){
gatewayVehicleService.loadDownLine(vin);
}
}

View File

@ -1,6 +1,7 @@
package com.xiaofan.loadcenter.gateway.cache;
import com.xiaofan.loadcenter.gateway.abs.GatewayCacheAbs;
import org.springframework.stereotype.Component;
/**
* @ProjectName: LoadCenter
@ -10,6 +11,7 @@ import com.xiaofan.loadcenter.gateway.abs.GatewayCacheAbs;
* @Date 2024/4/18 17:21
* @Version 1.0
*/
@Component
public class GatewayNodeSetVinCache extends GatewayCacheAbs<String> {
private final static String gatewayNodeSetVinCache="many:";
@Override

View File

@ -1,6 +1,7 @@
package com.xiaofan.loadcenter.gateway.cache;
import com.xiaofan.loadcenter.gateway.abs.GatewayCacheAbs;
import org.springframework.stereotype.Component;
/**
* @ProjectName: LoadCenter
@ -10,6 +11,7 @@ import com.xiaofan.loadcenter.gateway.abs.GatewayCacheAbs;
* @Date 2024/4/18 17:20
* @Version 1.0
*/
@Component
public class GatewayVehicleLineNodeCache extends GatewayCacheAbs<String> {
private final static String gatewayCarBusiness="business:";
@Override

View File

@ -0,0 +1,17 @@
package com.xiaofan.loadcenter.service;
import com.xiaofan.loadcenter.common.domain.Result;
/**
* @ProjectName: LoadCenter
* @PackageName: com.xiaofan.loadcenter.service
* @Description TODO
* @Author XiaoFan
* @Date 2024/4/20 09:46
* @Version 1.0
*/
public interface GatewayVehicleService {
Result<String> topLine(String vin);
void loadDownLine(String vin);
}

View File

@ -0,0 +1,46 @@
package com.xiaofan.loadcenter.service.impl;
import com.xiaofan.loadcenter.common.domain.Result;
import com.xiaofan.loadcenter.gateway.cache.GatewayNodeSetVinCache;
import com.xiaofan.loadcenter.gateway.cache.GatewayVehicleLineNodeCache;
import com.xiaofan.loadcenter.service.GatewayVehicleService;
import lombok.AllArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
/**
* @ProjectName: LoadCenter
* @PackageName: com.xiaofan.loadcenter.service.impl
* @Description TODO
* @Author XiaoFan
* @Date 2024/4/20 09:46
* @Version 1.0
*/
@Service
@AllArgsConstructor
@Log4j2
public class GatewayVehicleServiceimpl implements GatewayVehicleService {
private final GatewayNodeSetVinCache gatewayNodeSetVinCache;
private final GatewayVehicleLineNodeCache gatewayVehicleLineNodeCache;
@Autowired
private RestTemplate restTemplate;
@Override
public Result<String> topLine(String vin) {
String url="http://127.0.0.1:9011/gateway/load/node";
Result data=restTemplate.getForObject(url,Result.class);
gatewayVehicleLineNodeCache.put(vin,data.getData().toString());
gatewayNodeSetVinCache.put(data.getData().toString(),vin);
return Result.success(data.getData().toString());
}
@Override
public void loadDownLine(String vin) {
String nodeId = gatewayVehicleLineNodeCache.get(vin);
gatewayNodeSetVinCache.remove(nodeId,vin);
gatewayVehicleLineNodeCache.remove(vin);
}
}