package com.ruoyi.jianguan.dongfu; import cn.hutool.http.HttpUtil; import com.alibaba.fastjson2.JSONObject; import com.ruoyi.chargingPile.api.feignClient.ChargingGunClient; import com.ruoyi.chargingPile.api.feignClient.ChargingPileClient; import com.ruoyi.chargingPile.api.feignClient.SiteClient; import com.ruoyi.chargingPile.api.model.Site; import com.ruoyi.chargingPile.api.model.TChargingGun; import com.ruoyi.chargingPile.api.model.TChargingPile; import com.ruoyi.common.core.domain.R; import com.ruoyi.integration.api.elutong.model.ChargingGunInfo; import com.ruoyi.integration.api.elutong.model.ChargingPileInfo; import com.ruoyi.integration.api.elutong.model.ChargingStationInfo; import com.ruoyi.jianguan.chengdujianguan.util.HttpRequestUtil; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import java.util.ArrayList; import java.util.List; /** * 站桩枪、订单 临时数据接口 * * @author stylefeng * @Date 2018/7/20 23:39 */ @RestController @RequestMapping("/chargingStationInfo") @Slf4j public class ChargingInfoController { /** * 推送地址 */ private final String PUSH_URL = "https://kdgkg.dftzyxgs.com/scenic"; /** * 推送站点 */ private final String PUSH_SITE_URL = "/open/xw/charging/push/station"; /** * 推送桩 */ private final String PUSH_PILE_URL = "/open/xw/charging/push/pile"; /** * 推送枪 */ private final String PUSH_GUN_URL = "/open/xw/charging/push/gun"; @Autowired private ChargingGunClient chargingGunClient; @Autowired private ChargingPileClient chargingPileClient; @Autowired private SiteClient siteClient; /** * 推送充电站信息 * @return */ @PostMapping("/pushChargingStation") public R pushChargingStation(){ R> siteListR = siteClient.getSiteAll(); List siteList = siteListR.getData(); if(!CollectionUtils.isEmpty(siteList)){ List chargingStationInfoList = new ArrayList<>(); for (Site site : siteList) { ChargingStationInfo chargingStationInfo = new ChargingStationInfo(); chargingStationInfo.setId(site.getId().toString()); chargingStationInfo.setName(site.getName()); chargingStationInfo.setStatus(site.getStatus()==1?1:0); chargingStationInfoList.add(chargingStationInfo); } // 推送http请求 String result = HttpUtil.post(PUSH_URL + PUSH_SITE_URL, JSONObject.toJSONString(chargingStationInfoList)); log.info("推送充电站信息:{}",result); } return R.ok(); } /** * 推送充电桩信息 * @return */ @PostMapping("/pushChargingPile") public R pushChargingPile(){ R> pileListR = chargingPileClient.getAllPile(); List chargingPiles = pileListR.getData(); if(!CollectionUtils.isEmpty(chargingPiles)){ List chargingPileInfoList = new ArrayList<>(); for (TChargingPile pile : chargingPiles) { ChargingPileInfo chargingPileInfo = new ChargingPileInfo(); chargingPileInfo.setId(pile.getId().toString()); chargingPileInfo.setName(pile.getName()); if(pile.getStatus() == 1){ chargingPileInfo.setStatus(2); }else { chargingPileInfo.setStatus(0); } chargingPileInfo.setStatus(pile.getStatus()==1?1:0); chargingPileInfo.setFast(1); chargingPileInfo.setStationId(pile.getSiteId().toString()); chargingPileInfoList.add(chargingPileInfo); } // 推送http请求 String result = HttpUtil.post(PUSH_URL + PUSH_PILE_URL, JSONObject.toJSONString(chargingPileInfoList)); log.info("推送充电桩信息:{}",result); } return R.ok(); } /** * 推送充电枪信息 * @return */ @PostMapping("/pushChargingGun") public R pushChargingGun(){ R> gunListR = chargingGunClient.getAllGun(); List chargingGuns = gunListR.getData(); if(!CollectionUtils.isEmpty(chargingGuns)){ List chargingGunInfoList = new ArrayList<>(); for (TChargingGun gun : chargingGuns) { ChargingGunInfo chargingGunInfo = new ChargingGunInfo(); chargingGunInfo.setId(gun.getId().toString()); chargingGunInfo.setName(gun.getName()); if(gun.getStatus() == 1 || gun.getStatus() == 7){ chargingGunInfo.setStatus(0); }else if (gun.getStatus() == 2){ chargingGunInfo.setStatus(1); }else { chargingGunInfo.setStatus(2); } chargingGunInfo.setPileId(gun.getChargingPileId().toString()); chargingGunInfoList.add(chargingGunInfo); } // 推送http请求 String result = HttpUtil.post(PUSH_URL + PUSH_GUN_URL, JSONObject.toJSONString(chargingGunInfoList)); log.info("推送充电枪信息:{}",result); } return R.ok(); } }