mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-06-13 03:39:55 +08:00
update 高德地图工具类
This commit is contained in:
@@ -0,0 +1,60 @@
|
|||||||
|
package com.jsowell.amap;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.alibaba.fastjson2.JSON;
|
||||||
|
import com.jsowell.common.annotation.Anonymous;
|
||||||
|
import com.jsowell.common.core.controller.BaseController;
|
||||||
|
import com.jsowell.pile.dto.amap.GetStationInfoDTO;
|
||||||
|
import com.jsowell.thirdparty.amap.common.AMapCommonParams;
|
||||||
|
import com.jsowell.thirdparty.amap.common.AMapCommonResult;
|
||||||
|
import com.jsowell.thirdparty.amap.domain.AMapStationInfo;
|
||||||
|
import com.jsowell.thirdparty.amap.service.AMapService;
|
||||||
|
import com.jsowell.thirdparty.amap.util.AMapUtils;
|
||||||
|
import org.apache.poi.ss.formula.functions.T;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.util.CollectionUtils;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TODO
|
||||||
|
*
|
||||||
|
* @author Lemon
|
||||||
|
* @Date 2023/6/16 13:56
|
||||||
|
*/
|
||||||
|
@Anonymous
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/amap/charging")
|
||||||
|
public class AMapController extends BaseController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private AMapService aMapService;
|
||||||
|
|
||||||
|
@PostMapping("/queryStationInfo")
|
||||||
|
public AMapCommonResult queryStationInfo(@RequestParam Map<String, String> requestMap) {
|
||||||
|
AMapCommonResult result = new AMapCommonResult();
|
||||||
|
String paramString = JSON.toJSONString(requestMap);
|
||||||
|
logger.info("高德拉取充电站静态数据 params:{}", paramString);
|
||||||
|
try {
|
||||||
|
// Map map = JSON.parseObject(paramString, Map.class);
|
||||||
|
// Map<String, String> paramMap = (Map<String, String>)JSON.parse(paramString);
|
||||||
|
if (AMapUtils.checkSign(requestMap)) {
|
||||||
|
// true 验签成功
|
||||||
|
String bizContent = requestMap.get("biz_content");
|
||||||
|
GetStationInfoDTO dto = JSON.parseObject(bizContent, GetStationInfoDTO.class);
|
||||||
|
List<AMapStationInfo> stationInfos = aMapService.getStationInfos(dto);
|
||||||
|
logger.info("高德拉取充电站静态数据 success");
|
||||||
|
return result.successResponse(stationInfos);
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("高德拉取充电站静态数据 error", e);
|
||||||
|
return result.failedResponse();
|
||||||
|
}
|
||||||
|
logger.error("高德拉取充电站静态数据验签失败");
|
||||||
|
return result.checkSignFailed();
|
||||||
|
// logger.info("高德拉取充电站静态数据 result:{}", );
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -134,3 +134,4 @@ aMap:
|
|||||||
appId: 202306150188103814
|
appId: 202306150188103814
|
||||||
devUrl: https://restapi.amap.com/rest/openmp/devgw?key=7967738241f0a580b5a1342f43793a61
|
devUrl: https://restapi.amap.com/rest/openmp/devgw?key=7967738241f0a580b5a1342f43793a61
|
||||||
prdUrl: https://restapi.amap.com/rest/openmp/gw?key=7967738241f0a580b5a1342f43793a61
|
prdUrl: https://restapi.amap.com/rest/openmp/gw?key=7967738241f0a580b5a1342f43793a61
|
||||||
|
openId: 2089000923284502
|
||||||
@@ -11,27 +11,11 @@ import lombok.NoArgsConstructor;
|
|||||||
* @Date 2023/6/14 13:11
|
* @Date 2023/6/14 13:11
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
public class AMapCommonResult {
|
public class AMapCommonResult {
|
||||||
|
|
||||||
private Response response;
|
private AMapResponse response;
|
||||||
|
|
||||||
|
|
||||||
@Data
|
|
||||||
public static class Response{
|
|
||||||
private String code;
|
|
||||||
|
|
||||||
private String msg;
|
|
||||||
|
|
||||||
private Object data;
|
|
||||||
}
|
|
||||||
|
|
||||||
public AMapCommonResult(Response response) {
|
|
||||||
this.response = response;
|
|
||||||
}
|
|
||||||
|
|
||||||
public AMapCommonResult() {
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 成功响应
|
* 成功响应
|
||||||
@@ -39,17 +23,24 @@ public class AMapCommonResult {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public AMapCommonResult successResponse(Object responseData) {
|
public AMapCommonResult successResponse(Object responseData) {
|
||||||
AMapCommonResult result = new AMapCommonResult();
|
AMapResponse response = new AMapResponse();
|
||||||
result.response.setCode("1000");
|
response.setCode("1000");
|
||||||
result.response.setMsg("请求成功");
|
response.setMsg("请求成功");
|
||||||
result.response.setData(responseData);
|
response.setData(responseData);
|
||||||
return new AMapCommonResult(result.response);
|
return new AMapCommonResult(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
public AMapCommonResult failedResponse() {
|
public AMapCommonResult failedResponse() {
|
||||||
AMapCommonResult result = new AMapCommonResult();
|
AMapResponse response = new AMapResponse();
|
||||||
result.response.setCode("40004");
|
response.setCode("40004");
|
||||||
result.response.setMsg("接口异常");
|
response.setMsg("接口异常");
|
||||||
return new AMapCommonResult(result.response);
|
return new AMapCommonResult(response);
|
||||||
|
}
|
||||||
|
|
||||||
|
public AMapCommonResult checkSignFailed() {
|
||||||
|
AMapResponse response = new AMapResponse();
|
||||||
|
response.setCode("40002");
|
||||||
|
response.setMsg("验签错误,请检查!");
|
||||||
|
return new AMapCommonResult(response);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
18
jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/amap/common/AMapResponse.java
vendored
Normal file
18
jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/amap/common/AMapResponse.java
vendored
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
package com.jsowell.thirdparty.amap.common;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TODO
|
||||||
|
*
|
||||||
|
* @author Lemon
|
||||||
|
* @Date 2023/6/16 15:50
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class AMapResponse {
|
||||||
|
private String code;
|
||||||
|
|
||||||
|
private String msg;
|
||||||
|
|
||||||
|
private Object data;
|
||||||
|
}
|
||||||
@@ -28,4 +28,11 @@ public interface AMapService {
|
|||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
String pushChargingDeviceDynamics(String pileConnectorCode) throws Exception;
|
String pushChargingDeviceDynamics(String pileConnectorCode) throws Exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 商家推送充电订单信息
|
||||||
|
* @param orderCode
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
String pushChargingOrderInfo(String orderCode);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import com.jsowell.common.constant.Constants;
|
|||||||
import com.jsowell.common.exception.BusinessException;
|
import com.jsowell.common.exception.BusinessException;
|
||||||
import com.jsowell.common.util.PageUtils;
|
import com.jsowell.common.util.PageUtils;
|
||||||
import com.jsowell.common.util.StringUtils;
|
import com.jsowell.common.util.StringUtils;
|
||||||
|
import com.jsowell.pile.domain.OrderBasicInfo;
|
||||||
import com.jsowell.pile.domain.PileBasicInfo;
|
import com.jsowell.pile.domain.PileBasicInfo;
|
||||||
import com.jsowell.pile.domain.PileStationInfo;
|
import com.jsowell.pile.domain.PileStationInfo;
|
||||||
import com.jsowell.pile.dto.amap.ChargeDeviceDynamicsDTO;
|
import com.jsowell.pile.dto.amap.ChargeDeviceDynamicsDTO;
|
||||||
@@ -52,6 +53,9 @@ public class AMapServiceImpl implements AMapService {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private IPileModelInfoService pileModelInfoService;
|
private IPileModelInfoService pileModelInfoService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private IOrderBasicInfoService orderBasicInfoService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 高德拉取充电站静态数据
|
* 高德拉取充电站静态数据
|
||||||
* @param dto
|
* @param dto
|
||||||
@@ -125,6 +129,7 @@ public class AMapServiceImpl implements AMapService {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String pushChargingDeviceDynamics(String pileConnectorCode) throws Exception {
|
public String pushChargingDeviceDynamics(String pileConnectorCode) throws Exception {
|
||||||
|
|
||||||
// 根据枪口号查出桩信息
|
// 根据枪口号查出桩信息
|
||||||
PileConnectorDetailVO pileConnectorDetailVO = pileBasicInfoService.queryPileConnectorDetail(pileConnectorCode);
|
PileConnectorDetailVO pileConnectorDetailVO = pileBasicInfoService.queryPileConnectorDetail(pileConnectorCode);
|
||||||
if (pileConnectorDetailVO == null) {
|
if (pileConnectorDetailVO == null) {
|
||||||
@@ -155,6 +160,24 @@ public class AMapServiceImpl implements AMapService {
|
|||||||
return AMapUtils.sendPost(map);
|
return AMapUtils.sendPost(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 商家推送充电订单信息
|
||||||
|
* @param orderCode
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String pushChargingOrderInfo(String orderCode) {
|
||||||
|
// 根据订单编号查询信息
|
||||||
|
OrderBasicInfo orderBasicInfo = orderBasicInfoService.getOrderInfoByOrderCode(orderCode);
|
||||||
|
|
||||||
|
// 拼装业务参数
|
||||||
|
JSONObject json = new JSONObject();
|
||||||
|
json.put("", "");
|
||||||
|
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据站点id查询计费模板
|
* 根据站点id查询计费模板
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import org.springframework.http.HttpEntity;
|
|||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.util.LinkedMultiValueMap;
|
import org.springframework.util.LinkedMultiValueMap;
|
||||||
import org.springframework.util.MultiValueMap;
|
import org.springframework.util.MultiValueMap;
|
||||||
import org.springframework.web.client.RestTemplate;
|
import org.springframework.web.client.RestTemplate;
|
||||||
@@ -19,22 +20,38 @@ import java.util.*;
|
|||||||
/**
|
/**
|
||||||
* 高德地图工具类
|
* 高德地图工具类
|
||||||
*/
|
*/
|
||||||
|
@Component
|
||||||
public class AMapUtils {
|
public class AMapUtils {
|
||||||
|
private static String MERCHANT_PRIVATE_KEY;
|
||||||
|
private static String AMAP_PUBLIC_KEY;
|
||||||
|
private static String APP_ID;
|
||||||
|
private static String DEV_URL;
|
||||||
|
private static String PRD_URL;
|
||||||
|
|
||||||
@Value("${aMap.merchantPrivateKey}")
|
@Value("${aMap.merchantPrivateKey}")
|
||||||
private static String MERCHANT_PRIVATE_KEY;
|
public static void setMerchantPrivateKey(String merchantPrivateKey) {
|
||||||
|
AMapUtils.MERCHANT_PRIVATE_KEY = merchantPrivateKey;
|
||||||
|
}
|
||||||
|
|
||||||
@Value("${aMap.aMapPublicKey}")
|
@Value("${aMap.aMapPublicKey}")
|
||||||
private static String AMAP_PUBLIC_KEY;
|
public void setAmapPublicKey(String amapPublicKey) {
|
||||||
|
AMapUtils.AMAP_PUBLIC_KEY = amapPublicKey;
|
||||||
|
}
|
||||||
|
|
||||||
@Value("${aMap.appId}")
|
@Value("${aMap.appId}")
|
||||||
private static String APP_ID;
|
public void setAppId(String appId) {
|
||||||
|
AMapUtils.APP_ID = appId;
|
||||||
|
}
|
||||||
|
|
||||||
@Value("${aMap.devUrl}")
|
@Value("${aMap.devUrl}")
|
||||||
private static String DEV_URL;
|
public void setDevUrl(String devUrl) {
|
||||||
|
AMapUtils.DEV_URL = devUrl;
|
||||||
|
}
|
||||||
|
|
||||||
@Value("${aMap.prdUrl}")
|
@Value("${aMap.prdUrl}")
|
||||||
private static String PRD_URL;
|
public void setPrdUrl(String prdUrl) {
|
||||||
|
AMapUtils.PRD_URL = prdUrl;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 使用商家私钥生成签名
|
* 使用商家私钥生成签名
|
||||||
|
|||||||
Reference in New Issue
Block a user