parent
a4c44b9a17
commit
8c5049762a
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -28,6 +28,11 @@ public class GatewayNodeSetVinCache extends GatewayCacheAbs<String> {
|
|||
redisService.setCacheSet(encode(gatewayNodeSetVinCache)+node,vin);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除节点对应的vin
|
||||
* @param nodeId
|
||||
* @param vin
|
||||
*/
|
||||
public void remove(String nodeId,String vin){
|
||||
redisService.deleteCacheSet(encode(gatewayNodeSetVinCache)+nodeId,vin);
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ public class GatewayVehicleNode extends GatewayCacheAbs<String> {
|
|||
}
|
||||
|
||||
/**
|
||||
* 获取车辆
|
||||
* 获取车辆 nodeId
|
||||
* @param vin
|
||||
* @return
|
||||
*/
|
||||
|
|
|
@ -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);
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue