车辆上下线
master
JangCan 2024-04-20 11:31:57 +08:00
parent a4c44b9a17
commit 8c5049762a
5 changed files with 107 additions and 1 deletions

View File

@ -0,0 +1,39 @@
package com.loadcenter.controller;
import com.loadcenter.common.domain.resp.Result;
import com.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;
/**
* 线 @JangC
*/
@RestController
@RequestMapping("/vehicle")
public class GatewayVehicleController {
/**
* 线
*/
@Autowired
private GatewayVehicleService gatewayVehicleService;
/**
* 线
*/
@GetMapping("/load/onLine/{vin}")
public Result<String> onLine(@PathVariable String vin) {
return gatewayVehicleService.onLine(vin);
}
/**
* 线
* @param vin
*/
@GetMapping("/load/downLine/{vin}")
public void downLine(@PathVariable String vin){
gatewayVehicleService.downLine(vin);
}
}

View File

@ -28,6 +28,11 @@ public class GatewayNodeSetVinCache extends GatewayCacheAbs<String> {
redisService.setCacheSet(encode(gatewayNodeSetVinCache)+node,vin); redisService.setCacheSet(encode(gatewayNodeSetVinCache)+node,vin);
} }
/**
* vin
* @param nodeId
* @param vin
*/
public void remove(String nodeId,String vin){ public void remove(String nodeId,String vin){
redisService.deleteCacheSet(encode(gatewayNodeSetVinCache)+nodeId,vin); redisService.deleteCacheSet(encode(gatewayNodeSetVinCache)+nodeId,vin);
} }

View File

@ -36,7 +36,7 @@ public class GatewayVehicleNode extends GatewayCacheAbs<String> {
} }
/** /**
* * nodeId
* @param vin * @param vin
* @return * @return
*/ */

View File

@ -0,0 +1,9 @@
package com.loadcenter.service;
import com.loadcenter.common.domain.resp.Result;
public interface GatewayVehicleService {
Result<String> onLine(String vin);
void downLine(String vin);
}

View File

@ -0,0 +1,53 @@
package com.loadcenter.service.impl;
import com.loadcenter.common.domain.resp.Result;
import com.loadcenter.gateway.cache.GatewayNodeSetVinCache;
import com.loadcenter.gateway.cache.GatewayVehicleNode;
import com.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;
@Service
@AllArgsConstructor
@Log4j2
public class GatewayVehicleServiceImpl implements GatewayVehicleService {
private final GatewayNodeSetVinCache gatewayNodeSetVinCache;
private final GatewayVehicleNode gatewayVehicleNode;
@Autowired
private RestTemplate restTemplate;
/**
* 线
* @param vin
* @return
*/
@Override
public Result<String> onLine(String vin) {
String URL ="http://127.0.0.1:9010/gateway/load/node";
Result data = restTemplate.getForObject(URL, Result.class);
gatewayVehicleNode.put(vin,data.getData().toString());
gatewayNodeSetVinCache.put(data.getData().toString(),vin);
return Result.success(data.getData().toString());
}
/**
* 线
* @param vin
*/
@Override
public void downLine(String vin) {
String nodeId = gatewayVehicleNode.get(vin);
gatewayNodeSetVinCache.remove(nodeId,vin);
gatewayVehicleNode.remove(vin);
}
}