From 792cbb986fb8c32f6bbc1638c4ae264372e7a28f Mon Sep 17 00:00:00 2001 From: Pu Zhibing <393733352@qq.com> Date: 星期四, 23 一月 2025 19:31:36 +0800 Subject: [PATCH] 新增引流接口及业务逻辑 --- ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/service/impl/TChargingPileServiceImpl.java | 51 +++++++++++++++++++++++++++++---------------------- 1 files changed, 29 insertions(+), 22 deletions(-) diff --git a/ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/service/impl/TChargingPileServiceImpl.java b/ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/service/impl/TChargingPileServiceImpl.java index aacc202..b9b4859 100644 --- a/ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/service/impl/TChargingPileServiceImpl.java +++ b/ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/service/impl/TChargingPileServiceImpl.java @@ -263,32 +263,37 @@ return AjaxResult.error("设备编号已存在"); } TChargingPile tChargingPile = this.getById(chargingPile.getId()); - ShowDeviceResp showDeviceResp = iotInterfaceClient.showDeviceRequest(tChargingPile.getCode()).getData(); - if(null != showDeviceResp){ - DeleteDeviceResp deleteDeviceResp = iotInterfaceClient.deleteDevice(tChargingPile.getCode()).getData(); - if(null == deleteDeviceResp || (deleteDeviceResp.getHttpStatusCode() != 200 && deleteDeviceResp.getHttpStatusCode() != 201 && deleteDeviceResp.getHttpStatusCode() != 204)){ - return AjaxResult.error("删除设备异常,请查看华为设备管理"); + //桩号不相同,需要重新绑定设备 + if(!tChargingPile.getCode().equals(chargingPile.getCode())){ + ShowDeviceResp showDeviceResp = iotInterfaceClient.showDeviceRequest(tChargingPile.getCode()).getData(); + if(null != showDeviceResp){ + DeleteDeviceResp deleteDeviceResp = iotInterfaceClient.deleteDevice(tChargingPile.getCode()).getData(); + if(null == deleteDeviceResp){ + return AjaxResult.error("删除设备异常,请查看华为设备管理"); + } } } - - - //调用华为Iot创建设备 - AddDevice addDevice = new AddDevice(); - addDevice.setProductId("66da68d21837002b28b34ec0"); - addDevice.setNodeId(chargingPile.getCode()); - addDevice.setDeviceName(chargingPile.getName()); - addDevice.setDescription(chargingPile.getNumber().toString()); - AddDeviceResp deviceResp = iotInterfaceClient.addDevice(addDevice).getData(); - if(null != deviceResp){ - int httpStatusCode = deviceResp.getHttpStatusCode(); - if(httpStatusCode == 201){ - chargingPile.setIotdDeviceId(deviceResp.getDeviceId()); + + ShowDeviceResp showDeviceResp = iotInterfaceClient.showDeviceRequest(tChargingPile.getCode()).getData(); + if(null == showDeviceResp){ + //调用华为Iot创建设备 + AddDevice addDevice = new AddDevice(); + addDevice.setProductId("66da68d21837002b28b34ec0"); + addDevice.setNodeId(chargingPile.getCode()); + addDevice.setDeviceName(chargingPile.getName()); + addDevice.setDescription(chargingPile.getNumber().toString()); + AddDeviceResp deviceResp = iotInterfaceClient.addDevice(addDevice).getData(); + if(null != deviceResp){ + int httpStatusCode = deviceResp.getHttpStatusCode(); + if(httpStatusCode == 201){ + chargingPile.setIotdDeviceId(deviceResp.getDeviceId()); + }else{ + log.error("华为创建设备失败" + JSON.toJSONString(deviceResp)); + return AjaxResult.error("华为创建设备失败"); + } }else{ - log.error("华为创建设备失败" + JSON.toJSONString(deviceResp)); return AjaxResult.error("华为创建设备失败"); } - }else{ - return AjaxResult.error("华为创建设备失败"); } this.updateById(chargingPile); @@ -479,11 +484,13 @@ BigDecimal v = list.stream().map(TChargingPile::getRatedPower).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(4, RoundingMode.HALF_EVEN); List<Double> data = chargingOrderAccountingStrategyClient.getDailyChargingDegree(6, siteIds).getData(); List<Double> value2 = new ArrayList<>(); + BigDecimal multiply = new BigDecimal(list.size()).multiply(v).multiply(new BigDecimal(24)); for (Double datum : data) { if(list.size() == 0){ value2.add(0D); }else{ - Double datum1 = new BigDecimal(datum).divide(new BigDecimal(list.size()).multiply(v).multiply(new BigDecimal(24)), new MathContext(4, RoundingMode.HALF_EVEN)).multiply(new BigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue(); + Double datum1 = new BigDecimal(datum).divide(multiply, new MathContext(4, RoundingMode.HALF_EVEN)) + .multiply(new BigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue(); value2.add(datum1); } } -- Gitblit v1.7.1