| | |
| | | package com.ruoyi.chargingPile.util; |
| | | |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; |
| | | import com.ruoyi.chargingPile.api.model.Site; |
| | | import com.ruoyi.chargingPile.api.model.TChargingGun; |
| | | import com.ruoyi.chargingPile.service.ISiteService; |
| | | import com.ruoyi.chargingPile.service.TChargingGunService; |
| | | import com.ruoyi.chargingPile.service.TChargingPileService; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.core.utils.StringUtils; |
| | | import com.ruoyi.integration.api.elutong.model.*; |
| | | import com.ruoyi.integration.api.feignClient.ELuTongClient; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.boot.web.context.WebServerInitializedEvent; |
| | | import org.springframework.context.ApplicationListener; |
| | | import org.springframework.scheduling.annotation.Scheduled; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | |
| | | /** |
| | | * 定时任务工具类 |
| | | */ |
| | | @Slf4j |
| | | @Component |
| | | public class TaskUtil { |
| | | public class TaskUtil implements ApplicationListener<WebServerInitializedEvent> { |
| | | |
| | | @Resource |
| | | private TChargingPileService chargingPileService;; |
| | | private TChargingPileService chargingPileService; |
| | | |
| | | private Integer port = null; |
| | | |
| | | @Resource |
| | | private ELuTongClient eLuTongClient; |
| | | |
| | | @Resource |
| | | private ISiteService siteService; |
| | | |
| | | @Resource |
| | | private TChargingGunService chargingGunService; |
| | | |
| | | |
| | | @Override |
| | | public void onApplicationEvent(WebServerInitializedEvent event) { |
| | | port = event.getWebServer().getPort(); |
| | | System.out.println("端口号:" + port); |
| | | } |
| | | |
| | | /** |
| | | * 每隔1分钟去处理的定时任务 |
| | | */ |
| | | @Scheduled(fixedRate = 60000) |
| | | public void taskMinute(){ |
| | | if(null != port && port == 5300){ |
| | | chargingPileService.updateStatus(); |
| | | pushStationsStatus(); |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 每隔一分钟去处理的定时任务 |
| | | * 1分钟定时推送设备状态E路通 |
| | | */ |
| | | @Scheduled(fixedRate = 1000 * 60) |
| | | public void taskMinute(){ |
| | | chargingPileService.updateStatus(); |
| | | private void pushStationsStatus(){ |
| | | List<Site> list = siteService.list(new LambdaQueryWrapper<Site>().eq(Site::getDelFlag, 0).isNotNull(Site::getSerAreaCode)); |
| | | for (Site site : list) { |
| | | if(StringUtils.isEmpty(site.getSerAreaCode())){ |
| | | continue; |
| | | } |
| | | StationsStatusReq stationsStatusReq = new StationsStatusReq(); |
| | | stationsStatusReq.setOperatorId("91510903906171535D"); |
| | | stationsStatusReq.setSerAreaCode(site.getSerAreaCode()); |
| | | stationsStatusReq.setStationId(site.getId().toString()); |
| | | List<StationStatusInfo> stationStausInfos = new ArrayList<>(); |
| | | stationStausInfos.add(buildStationStaus(site)); |
| | | stationsStatusReq.setItemSize(stationStausInfos.size()); |
| | | stationsStatusReq.setStationStatusInfos(stationStausInfos); |
| | | R r = eLuTongClient.pushStationsStatus(stationsStatusReq); |
| | | if(200 != r.getCode()){ |
| | | log.error(r.getMsg()); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | private StationStatusInfo buildStationStaus(Site site){ |
| | | StationStatusInfo stationStausInfo = new StationStatusInfo(); |
| | | stationStausInfo.setStationId(site.getId().toString()); |
| | | stationStausInfo.setConnectorStatusInfos(buildConnectorStatus(site)); |
| | | return stationStausInfo; |
| | | } |
| | | |
| | | private List<ConnectorStatusInfo> buildConnectorStatus(Site site){ |
| | | List<TChargingGun> list = chargingGunService.list(new LambdaQueryWrapper<TChargingGun>().eq(TChargingGun::getDelFlag, 0) |
| | | .eq(TChargingGun::getSiteId, site.getId())); |
| | | return new ArrayList<ConnectorStatusInfo>(){{ |
| | | for (TChargingGun chargingGun : list) { |
| | | ConnectorStatusInfo connectorStatusInfo = new ConnectorStatusInfo(); |
| | | connectorStatusInfo.setConnectorId(chargingGun.getId().toString()); |
| | | switch (chargingGun.getStatus()){ |
| | | case 1: |
| | | connectorStatusInfo.setStatus(0); |
| | | break; |
| | | case 2: |
| | | connectorStatusInfo.setStatus(1); |
| | | break; |
| | | case 3: |
| | | connectorStatusInfo.setStatus(2); |
| | | break; |
| | | case 4: |
| | | connectorStatusInfo.setStatus(3); |
| | | break; |
| | | case 5: |
| | | connectorStatusInfo.setStatus(3); |
| | | break; |
| | | case 6: |
| | | connectorStatusInfo.setStatus(4); |
| | | break; |
| | | case 7: |
| | | connectorStatusInfo.setStatus(255); |
| | | break; |
| | | } |
| | | connectorStatusInfo.setSoc(0D); |
| | | connectorStatusInfo.setRemainingTime(0); |
| | | add(connectorStatusInfo); |
| | | } |
| | | }}; |
| | | } |
| | | } |