Pu Zhibing
2024-12-31 8f22c7b297417ac7df12cb07eb9edd3a77dd01a1
ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/service/impl/TChargingPileServiceImpl.java
@@ -30,6 +30,10 @@
import com.ruoyi.integration.api.feignClient.UploadRealTimeMonitoringDataClient;
import com.ruoyi.integration.api.model.QrCodeDelivery;
import com.ruoyi.integration.api.model.UploadRealTimeMonitoringData;
import com.ruoyi.integration.api.vo.AddDevice;
import com.ruoyi.integration.api.vo.AddDeviceResp;
import com.ruoyi.integration.api.vo.DeleteDeviceResp;
import com.ruoyi.integration.api.vo.ShowDeviceResp;
import com.ruoyi.order.api.feignClient.ChargingOrderAccountingStrategyClient;
import com.ruoyi.order.api.feignClient.ChargingOrderClient;
import com.ruoyi.order.api.model.TChargingOrder;
@@ -173,18 +177,23 @@
         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());
//         }
//      }
      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{
         return AjaxResult.error("华为创建设备失败");
      }
      this.save(chargingPile);
      return AjaxResult.success();
   }
@@ -248,6 +257,34 @@
      if(null != one && !one.getId().equals(chargingPile.getId())){
         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("删除设备异常,请查看华为设备管理");
         }
      }
      //调用华为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{
         return AjaxResult.error("华为创建设备失败");
      }
      this.updateById(chargingPile);
      
      List<TChargingGun> list = chargingGunService.list(new LambdaQueryWrapper<TChargingGun>().eq(TChargingGun::getChargingPileId, chargingPile.getId()).eq(TChargingGun::getDelFlag, 0));
@@ -288,11 +325,17 @@
      for (Integer id : ids) {
         TChargingPile chargingPile = this.getById(id);
         //调用华为Iot删除设备
//         if(StringUtils.isNotEmpty(chargingPile.getIotdDeviceId())){
//            DeleteDeviceResp deviceResp = iotInterfaceClient.deleteDevice(chargingPile.getIotdDeviceId()).getData();
//            if(null != deviceResp && deviceResp.getHttpStatusCode() == 0){
//            }
//         }
         if(StringUtils.isNotEmpty(chargingPile.getIotdDeviceId())){
            ShowDeviceResp showDeviceResp = iotInterfaceClient.showDeviceRequest(chargingPile.getCode()).getData();
            if(null != showDeviceResp){
               DeleteDeviceResp deleteDeviceResp = iotInterfaceClient.deleteDevice(chargingPile.getCode()).getData();
               if(null == deleteDeviceResp || (deleteDeviceResp.getHttpStatusCode() != 200 && deleteDeviceResp.getHttpStatusCode() != 201 && deleteDeviceResp.getHttpStatusCode() != 204)){
                  return AjaxResult.error("删除设备异常,请查看华为设备管理");
               }
               chargingPile.setIotdDeviceId("");
            }
         }
         this.removeById(chargingPile);
      }
      return AjaxResult.success();