无关风月
2025-02-07 8a038cf6f0792cfe260a94e86d954b50f068e758
ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/service/impl/TChargingPileServiceImpl.java
@@ -182,22 +182,28 @@
         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(chargingPile.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("华为创建设备失败");
         chargingPile.setIotdDeviceId(showDeviceResp.getDeviceId());
      }
      this.save(chargingPile);
      return AjaxResult.success();
@@ -268,10 +274,14 @@
         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)){
            if(null == deleteDeviceResp){
               return AjaxResult.error("删除设备异常,请查看华为设备管理");
            }
         }
      }
      ShowDeviceResp showDeviceResp = iotInterfaceClient.showDeviceRequest(tChargingPile.getCode()).getData();
      if(null == showDeviceResp){
         //调用华为Iot创建设备
         AddDevice addDevice = new AddDevice();
         addDevice.setProductId("66da68d21837002b28b34ec0");
@@ -298,6 +308,7 @@
         TChargingGun chargingGun1 = new TChargingGun();
         chargingGun1.setId(chargingGun.getId());
         chargingGun1.setFullNumber(chargingPile.getCode() + chargingGun.getCode());
         chargingGun1.setSiteId(chargingPile.getSiteId());
         chargingGunService.updateById(chargingGun1);
         
         //下发硬件充电二维码
@@ -480,11 +491,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);
         }
      }