|
@@ -63,7 +63,12 @@ public class DeviceController {
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private DeviceControlerService deviceControlerService;
|
|
private DeviceControlerService deviceControlerService;
|
|
|
|
|
|
|
|
- /* *//**
|
|
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private RedisCache redisCache;
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /* *//**
|
|
|
* 接收到充电桩后台提交的云快充连接设备进行保存
|
|
* 接收到充电桩后台提交的云快充连接设备进行保存
|
|
|
*
|
|
*
|
|
|
* @param
|
|
* @param
|
|
@@ -128,8 +133,70 @@ public class DeviceController {
|
|
|
*/
|
|
*/
|
|
|
@DeleteMapping("/{pileCode}")
|
|
@DeleteMapping("/{pileCode}")
|
|
|
public AjaxResult delete( @PathVariable("pileCode") String pileCode) {
|
|
public AjaxResult delete( @PathVariable("pileCode") String pileCode) {
|
|
|
- AjaxResult ajaxResult = deviceService.deleteDevice(pileCode);
|
|
|
|
|
- return ajaxResult;
|
|
|
|
|
|
|
+// AjaxResult ajaxResult = deviceService.deleteDevice(pileCode);
|
|
|
|
|
+
|
|
|
|
|
+ QueryWrapper<DeviceStatus> deviceStatusQueryWrapper = new QueryWrapper<>();
|
|
|
|
|
+ deviceStatusQueryWrapper.eq("pile_code", pileCode);
|
|
|
|
|
+ List<DeviceStatus> deviceStatusList = deviceStatusService.list(deviceStatusQueryWrapper);
|
|
|
|
|
+ List<DeviceStatus> collect = deviceStatusList.stream().filter(deviceStatus ->
|
|
|
|
|
+ deviceStatus.getGunStatus() == StatusConstant.CHARGING
|
|
|
|
|
+ ).collect(Collectors.toList());
|
|
|
|
|
+ if (collect.size() > 0) {
|
|
|
|
|
+ //设备有正在充电的端口
|
|
|
|
|
+ return AjaxResult.error("设备有正在充电端口,不能进行删除!");
|
|
|
|
|
+ } else {
|
|
|
|
|
+ //断开socket
|
|
|
|
|
+ if (socketHandle.existDeviceConnection(pileCode)) {
|
|
|
|
|
+ socketHandle.removeDeviceConnection(pileCode);
|
|
|
|
|
+ }
|
|
|
|
|
+ //断开socket后,删除状态数据
|
|
|
|
|
+ try {
|
|
|
|
|
+ boolean b1 = deviceStatusService.removeBatchByIds(deviceStatusList);
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ logger.info("YKC-device:"+pileCode+">删除状态失败");
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //和计费模板数据
|
|
|
|
|
+ QueryWrapper<BillingModel> billingModelQueryWrapper = new QueryWrapper<>();
|
|
|
|
|
+ billingModelQueryWrapper.eq("pile_code", pileCode);
|
|
|
|
|
+ BillingModel billingModel = billingModelService.getOne(billingModelQueryWrapper);
|
|
|
|
|
+ try {
|
|
|
|
|
+ boolean b2 = billingModelService.removeById(billingModel);
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ logger.info("YKC-device:"+pileCode+">删除计费模板失败");
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //删除设备
|
|
|
|
|
+ QueryWrapper<Device> deviceQueryWrapper = new QueryWrapper<>();
|
|
|
|
|
+ deviceQueryWrapper.eq("pile_code", pileCode);
|
|
|
|
|
+ Device device = deviceService.getOne(deviceQueryWrapper);
|
|
|
|
|
+ try {
|
|
|
|
|
+ boolean b3 = deviceService.removeById(device);
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ return AjaxResult.error("删除设备失败");
|
|
|
|
|
+ }
|
|
|
|
|
+ //通讯密钥也要删除掉
|
|
|
|
|
+
|
|
|
|
|
+ redisCache.deleteCacheMapValue(RedisConstant.YKC_KEY_MAP,pileCode);
|
|
|
|
|
+// redisCache.deleteObject(RedisConstant.KEYS + pileCode);
|
|
|
|
|
+
|
|
|
|
|
+ if (redisCache.hasKey(RedisConstant.DEVICE_INFO)) {
|
|
|
|
|
+ Set<String> imeis = redisCache.getCacheObject(RedisConstant.DEVICE_INFO);
|
|
|
|
|
+ logger.info("delete imeis>>>" + device.toString() + ">>>>>" + imeis.size());
|
|
|
|
|
+ imeis.stream().forEach(s -> logger.info("s>>" + s));
|
|
|
|
|
+ if (imeis.contains(device.getDeviceImei())) {
|
|
|
|
|
+ imeis.remove(device.getDeviceImei());
|
|
|
|
|
+ }
|
|
|
|
|
+ //redisCache.setCacheObject(RedisConstant.DEVICE_INFO, imeis, 6 * 1000 * 60, TimeUnit.MILLISECONDS);
|
|
|
|
|
+ redisCache.setCacheObject(RedisConstant.DEVICE_INFO,imeis);
|
|
|
|
|
+ }
|
|
|
|
|
+ redisCache.deleteCacheMapValue(RedisConstant.DEVICE_IMEI_PILE_MAP, device.getDeviceImei());
|
|
|
|
|
+ }
|
|
|
|
|
+ return AjaxResult.success();
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@GetMapping("order")
|
|
@GetMapping("order")
|