无关风月
2025-02-20 0d4c9f50ee2bc3e4a03abd91ac7c9e03891d37f2
ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/service/impl/TChargingPileServiceImpl.java
@@ -3,7 +3,9 @@
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.account.api.dto.SendMessageDTO;
import com.ruoyi.account.api.feignClient.AppUserCarClient;
import com.ruoyi.account.api.feignClient.AppUserClient;
import com.ruoyi.account.api.model.TAppUserCar;
import com.ruoyi.chargingPile.api.dto.PageChargingPileListDTO;
import com.ruoyi.chargingPile.api.model.*;
@@ -24,10 +26,7 @@
import com.ruoyi.common.redis.service.RedisService;
import com.ruoyi.common.security.service.TokenService;
import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.integration.api.feignClient.IntegrationClient;
import com.ruoyi.integration.api.feignClient.IotInterfaceClient;
import com.ruoyi.integration.api.feignClient.SendMessageClient;
import com.ruoyi.integration.api.feignClient.UploadRealTimeMonitoringDataClient;
import com.ruoyi.integration.api.feignClient.*;
import com.ruoyi.integration.api.model.QrCodeDelivery;
import com.ruoyi.integration.api.model.UploadRealTimeMonitoringData;
import com.ruoyi.integration.api.vo.AddDevice;
@@ -67,6 +66,9 @@
   
   @Resource
   private TChargingGunService chargingGunService;
   @Resource
   private TCECClient tcecClient;
   
   @Resource
   private SysUserClient sysUserClient;
@@ -117,11 +119,14 @@
   private SendMessageClient sendMessageClient;
   @Resource
   private TokenService tokenService;
   @Resource
   private TChargingPileNotificationService chargingPileNotificationService;
   @Resource
   private AppUserClient appUserClient;
   
   
   /**
    * 获取充电桩列表数据
    * @param page
@@ -177,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();
@@ -258,32 +269,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);
      
@@ -292,6 +308,7 @@
         TChargingGun chargingGun1 = new TChargingGun();
         chargingGun1.setId(chargingGun.getId());
         chargingGun1.setFullNumber(chargingPile.getCode() + chargingGun.getCode());
         chargingGun1.setSiteId(chargingPile.getSiteId());
         chargingGunService.updateById(chargingGun1);
         
         //下发硬件充电二维码
@@ -334,7 +351,7 @@
               }
               chargingPile.setIotdDeviceId("");
            }
         }
         this.removeById(chargingPile);
      }
@@ -469,16 +486,18 @@
      chargeTrend.put("value", value1);
      chargeMonitoring.setChargeTrend(chargeTrend);
      
      //每日利用率=当日充电度数/(总桩数量*桩总功率*24小时)
      //每日利用率=当日充电度数/(桩总功率*24小时)
      List<TChargingPile> list = this.list(new LambdaQueryWrapper<TChargingPile>().in(TChargingPile::getSiteId, siteIds).eq(TChargingPile::getDelFlag, 0));
      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 = 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);
         }
      }
@@ -596,6 +615,8 @@
               if(null != appUserCarId){
                  TAppUserCar tAppUserCar = appUserCarClient.getCarByIds(Arrays.asList(appUserCarId)).getData().get(0);
                  gunMonitoring.setLicensePlate(tAppUserCar.getLicensePlate());
               }else{
                  gunMonitoring.setLicensePlate(chargingOrder.getPlateNum());
               }
               UploadRealTimeMonitoringData data = uploadRealTimeMonitoringDataClient.chargingOrderInfo(chargingOrder.getCode()).getData();
@@ -677,6 +698,8 @@
            chargingGun1.setId(chargingGun.getId());
            chargingGun1.setStatus(1);
            chargingGunService.updateById(chargingGun1);
            //推送状态给三方平台
            tcecClient.pushChargingGunStatus(chargingGun1.getFullNumber(), chargingGun1.getStatus());
            
            //桩处于正常,桩所属的枪都处于非正常,修改桩状态为异常
            TChargingPile chargingPile = this.getById(chargingGun.getChargingPileId());
@@ -703,6 +726,20 @@
               faultMessage.setDelFlag(false);
               faultMessage.setContent("设备离线");
               faultMessageService.save(faultMessage);
               // 发送故障短信
               Site site = siteService.getById(faultMessage.getSiteId());
               String siteName = site.getName();
               SendMessageDTO sendMessageDTO = new SendMessageDTO();
               sendMessageDTO.setPhone(site.getPhone());
               sendMessageDTO.setSite(site.getName());
               sendMessageDTO.setChargeGun(chargingPile.getNumber() + "");
               sendMessageDTO.setType(3);
               String result = appUserClient.sendMessage(sendMessageDTO).getData();
               if(siteName.length()>10){
                  siteName = siteName.substring(0,10);
               }
               chargingPileNotificationService.saveData(4,faultMessage.getSiteId(),faultMessage.getChargingPileId(),site.getPhone(),"检测到"+siteName+"..."+chargingPile.getNumber()+"号桩设备离线,请及时查看处理!");
            }
         }
      }