mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-21 03:25:12 +08:00
新增 商家推送充电设备动态数据 接口
This commit is contained in:
35
jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/amap/domain/AMapConnectorStatusInfo.java
vendored
Normal file
35
jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/amap/domain/AMapConnectorStatusInfo.java
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
package com.jsowell.thirdparty.amap.domain;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 高德地图充电枪状态
|
||||
*
|
||||
* @author Lemon
|
||||
* @Date 2023/6/15 16:00
|
||||
*/
|
||||
@Data
|
||||
public class AMapConnectorStatusInfo {
|
||||
|
||||
//充电设备接口编码,同一运营商内唯一
|
||||
@JSONField(name = "ConnectorID")
|
||||
private String connectorID;
|
||||
|
||||
// 充电枪所属的桩设备ID
|
||||
@JSONField(name = "EquipmentID")
|
||||
private String equipmentID;
|
||||
|
||||
/**
|
||||
* 状态
|
||||
* 0:离网
|
||||
* 1:空闲
|
||||
* 2:占用(未充电)
|
||||
* 3:占用(充电中)
|
||||
* 4:占用(预约锁定)
|
||||
* 255:故障
|
||||
*/
|
||||
@JSONField(name = "Status")
|
||||
private String status;
|
||||
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.jsowell.thirdparty.amap.service;
|
||||
|
||||
import com.jsowell.pile.dto.amap.ChargeDeviceDynamicsDTO;
|
||||
import com.jsowell.pile.dto.amap.GetStationInfoDTO;
|
||||
import com.jsowell.thirdparty.amap.domain.AMapStationInfo;
|
||||
|
||||
@@ -19,4 +20,12 @@ public interface AMapService {
|
||||
* @return
|
||||
*/
|
||||
List<AMapStationInfo> getStationInfos(GetStationInfoDTO dto);
|
||||
|
||||
/**
|
||||
* 商家推送充电设备动态数据
|
||||
* @param pileConnectorCode
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
String pushChargingDeviceDynamics(String pileConnectorCode) throws Exception;
|
||||
}
|
||||
|
||||
@@ -1,20 +1,22 @@
|
||||
package com.jsowell.thirdparty.amap.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.jsowell.common.constant.Constants;
|
||||
import com.jsowell.common.exception.BusinessException;
|
||||
import com.jsowell.common.util.PageUtils;
|
||||
import com.jsowell.common.util.StringUtils;
|
||||
import com.jsowell.pile.domain.PileBasicInfo;
|
||||
import com.jsowell.pile.domain.PileStationInfo;
|
||||
import com.jsowell.pile.dto.amap.ChargeDeviceDynamicsDTO;
|
||||
import com.jsowell.pile.dto.amap.GetStationInfoDTO;
|
||||
import com.jsowell.pile.service.*;
|
||||
import com.jsowell.pile.vo.base.ConnectorInfoVO;
|
||||
import com.jsowell.pile.vo.uniapp.BillingPriceVO;
|
||||
import com.jsowell.pile.vo.uniapp.PileConnectorDetailVO;
|
||||
import com.jsowell.pile.vo.web.PileModelInfoVO;
|
||||
import com.jsowell.thirdparty.amap.domain.AMapConnectorInfo;
|
||||
import com.jsowell.thirdparty.amap.domain.AMapEquipmentInfo;
|
||||
import com.jsowell.thirdparty.amap.domain.AMapPriceChargingInfo;
|
||||
import com.jsowell.thirdparty.amap.domain.AMapStationInfo;
|
||||
import com.jsowell.thirdparty.amap.domain.*;
|
||||
import com.jsowell.thirdparty.amap.service.AMapService;
|
||||
import com.jsowell.thirdparty.amap.util.AMapUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
@@ -102,12 +104,10 @@ public class AMapServiceImpl implements AMapService {
|
||||
aMapInfo.setAMapPriceChargingInfo(priceList);
|
||||
|
||||
Map<String, Integer> pileNumMap = getPileNum(stationInfo.getId());
|
||||
|
||||
aMapInfo.setFastEquipmentNum(pileNumMap.get("fastTotal"));
|
||||
aMapInfo.setSlowEquipmentNum(pileNumMap.get("slowTotal"));
|
||||
|
||||
List<AMapEquipmentInfo> aMapEquipmentInfos = getPileListByStationId(String.valueOf(stationInfo.getId()));
|
||||
|
||||
aMapInfo.setAMapEquipmentInfos(aMapEquipmentInfos);
|
||||
|
||||
resultList.add(aMapInfo);
|
||||
@@ -116,6 +116,47 @@ public class AMapServiceImpl implements AMapService {
|
||||
return resultList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 商家推送充电设备动态数据
|
||||
* @param pileConnectorCode
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
@Override
|
||||
public String pushChargingDeviceDynamics(String pileConnectorCode) throws Exception {
|
||||
// 根据枪口号查出桩信息
|
||||
PileConnectorDetailVO pileConnectorDetailVO = pileBasicInfoService.queryPileConnectorDetail(pileConnectorCode);
|
||||
if (pileConnectorDetailVO == null) {
|
||||
throw new BusinessException("", "");
|
||||
}
|
||||
String stationId = pileConnectorDetailVO.getStationId();
|
||||
Map<String, Integer> pileNumMap = getPileNum(Long.parseLong(stationId));
|
||||
|
||||
AMapConnectorStatusInfo info = new AMapConnectorStatusInfo();
|
||||
info.setConnectorID(pileConnectorCode);
|
||||
info.setEquipmentID(pileConnectorDetailVO.getPileSn());
|
||||
info.setStatus(pileConnectorDetailVO.getConnectorStatus());
|
||||
|
||||
// 拼装业务参数
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("stationID", stationId);
|
||||
json.put("fast_free", pileNumMap.get("fastFree"));
|
||||
json.put("fast_total", pileNumMap.get("fastTotal"));
|
||||
json.put("slow_free", pileNumMap.get("slowFree"));
|
||||
json.put("slow_total", pileNumMap.get("slowTotal"));
|
||||
json.put("connectorStatusInfo", info);
|
||||
|
||||
String SPI = "amap.charging.pushStationStatus";
|
||||
|
||||
Map<String, String> map = AMapUtils.generateParamMap(json, SPI);
|
||||
|
||||
// 调用高德接口
|
||||
return AMapUtils.sendPost(map);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 根据站点id查询快、慢充设备数量
|
||||
* @param stationId
|
||||
@@ -123,20 +164,30 @@ public class AMapServiceImpl implements AMapService {
|
||||
*/
|
||||
private Map<String, Integer> getPileNum(Long stationId) {
|
||||
int fastTotal = 0;
|
||||
int fastFree = 0;
|
||||
int slowTotal = 0;
|
||||
int slowFree = 0;
|
||||
List<ConnectorInfoVO> connectorList = pileConnectorInfoService.getUniAppConnectorList(stationId);
|
||||
for (ConnectorInfoVO connectorVO : connectorList) {
|
||||
if (StringUtils.equals(connectorVO.getChargingType(), Constants.ONE)) {
|
||||
// 快充
|
||||
fastTotal += 1;
|
||||
if (StringUtils.equals(connectorVO.getConnectorStatus(), Constants.ONE)) {
|
||||
fastFree += 1;
|
||||
}
|
||||
} else {
|
||||
// 慢充
|
||||
slowTotal += 1;
|
||||
if (StringUtils.equals(connectorVO.getConnectorStatus(), Constants.ONE)) {
|
||||
slowFree += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
Map<String, Integer> map = new LinkedHashMap<>();
|
||||
map.put("fastTotal", fastTotal);
|
||||
map.put("fastFree", fastFree);
|
||||
map.put("slowTotal", slowTotal);
|
||||
map.put("slowFree", slowFree);
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,14 @@
|
||||
package com.jsowell.thirdparty.amap.util;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import java.io.*;
|
||||
import java.security.*;
|
||||
@@ -19,6 +27,9 @@ public class AMapUtils {
|
||||
@Value("${aMap.aMapPublicKey}")
|
||||
private static String AMAP_PUBLIC_KEY;
|
||||
|
||||
@Value("${aMap.appId}")
|
||||
private static String APP_ID;
|
||||
|
||||
/**
|
||||
* 使用商家私钥生成签名
|
||||
*
|
||||
@@ -32,6 +43,69 @@ public class AMapUtils {
|
||||
return getSign(signContent, MERCHANT_PRIVATE_KEY);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构造参数map
|
||||
* @param bizContent 业务参数
|
||||
* @param SPI 高德文档中每个接口的SPI
|
||||
* @return 构造好可直接发送请求的map参数
|
||||
*/
|
||||
public static Map<String, String> generateParamMap(JSONObject bizContent, String SPI) throws Exception {
|
||||
Map<String, String> map = new LinkedHashMap<>();
|
||||
map.put("biz_content", JSONObject.toJSONString(bizContent));
|
||||
map.put("app_id", APP_ID);
|
||||
map.put("utc_timestamp", String.valueOf(System.currentTimeMillis()));
|
||||
map.put("version", "1.0");
|
||||
map.put("charset", "UTF-8");
|
||||
map.put("method", SPI);
|
||||
// 生成签名
|
||||
String sign = AMapUtils.generateSign(map);
|
||||
map.put("sign", sign);
|
||||
map.put("sign_type", "RSA2");
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
/**
|
||||
* 向高德地图发送请求
|
||||
* @param paramMap 请求参数
|
||||
* @return 高德返回结果
|
||||
*/
|
||||
public static String sendPost(Map<String, String> paramMap) {
|
||||
// 定义Content-type、初始化HttpEntity
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
|
||||
MultiValueMap<String, Object> formBody = convertToMultiValueMap(paramMap);
|
||||
HttpEntity<MultiValueMap<String, Object>> entity = new HttpEntity<>(formBody, headers);
|
||||
|
||||
// 调用高德接口
|
||||
// 线下联调环境:https://restapi.amap.com/rest/openmp/devgw?key=高德云店秘钥key
|
||||
// 线上环境:https://restapi.amap.com/rest/openmp/gw?key=高德云店秘钥key
|
||||
// 高德云店秘钥key请登录高德云店「接入准备及配置」页面查看
|
||||
String url = "https://restapi.amap.com/rest/openmp/devgw?key=77ff5350723d29901fa859515f553644";
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
ResponseEntity<String> resp = restTemplate.postForEntity(url, entity, String.class);
|
||||
if (resp.getBody() != null && !"".equals(resp.getBody())) {
|
||||
JSONObject respObj = JSONObject.parseObject(resp.getBody());
|
||||
System.out.println("高德返回结果:" + respObj);
|
||||
return JSONObject.toJSONString(respObj);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将Map转为MultiValueMap
|
||||
* (MultiValueMap 可一个 key 对应多个 value)
|
||||
* @param paramMap 业务参数map
|
||||
* @return MultiValueMap
|
||||
*/
|
||||
private static MultiValueMap<String, Object> convertToMultiValueMap(Map<String, String> paramMap) {
|
||||
MultiValueMap<String, Object> multiValueMap = new LinkedMultiValueMap<>();
|
||||
for (Map.Entry<String, String> entry : paramMap.entrySet()) {
|
||||
multiValueMap.add(entry.getKey(), entry.getValue());
|
||||
}
|
||||
return multiValueMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* 参数转换为待加签字符串
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user