update 联联接口

This commit is contained in:
Lemon
2023-05-27 15:56:26 +08:00
parent 35413920d3
commit a87c35430f
5 changed files with 152 additions and 64 deletions

View File

@@ -7,11 +7,15 @@ import com.jsowell.common.enums.ykc.ReturnCodeEnum;
import com.jsowell.common.exception.BusinessException;
import com.jsowell.common.response.RestApiResponse;
import com.jsowell.common.util.StringUtils;
import com.jsowell.pile.domain.DockingPlatformConfig;
import com.jsowell.pile.dto.*;
import com.jsowell.pile.service.IDockingPlatformConfigService;
import com.jsowell.thirdparty.lianlian.common.CommonResult;
import com.jsowell.thirdparty.lianlian.domain.StationStatsInfo;
import com.jsowell.thirdparty.lianlian.dto.QueryTokenDTO;
import com.jsowell.thirdparty.lianlian.dto.CommonParamsDTO;
import com.jsowell.thirdparty.lianlian.service.LianLianService;
import com.jsowell.thirdparty.lianlian.util.Cryptos;
import com.jsowell.thirdparty.lianlian.util.Encodes;
import com.jsowell.thirdparty.lianlian.vo.*;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
@@ -35,6 +39,8 @@ public class LianLianController extends BaseController {
@Autowired
private LianLianService lianLianService;
@Autowired
private IDockingPlatformConfigService dockingPlatformConfigService;
/**
* 推送充电站信息 notification_stationInfo
@@ -149,23 +155,25 @@ public class LianLianController extends BaseController {
* @param dto
* @return
*/
@PostMapping("/query_stations_info")
public RestApiResponse<?> query_stations_info(@RequestBody QueryStationInfoDTO dto) {
logger.info("联联平台查询充电站信息 params:{}", JSONObject.toJSONString(dto));
RestApiResponse<?> response = null;
try {
LianLianPageResponse pageResponse = lianLianService.query_stations_info(dto);
response = new RestApiResponse<>(pageResponse);
}catch (BusinessException e) {
logger.error("联联平台查询充电站信息 error",e);
response = new RestApiResponse<>(e.getCode(), e.getMessage());
}catch (Exception e) {
logger.error("联联平台查询充电站信息 error", e);
response = new RestApiResponse<>(e);
}
logger.info("联联平台查询充电站信息 result:{}", response);
return response;
}
// @PostMapping("/query_stations_info")
// public RestApiResponse<?> query_stations_info(@RequestBody QueryStationInfoDTO dto) {
// logger.info("联联平台查询充电站信息 params:{}", JSONObject.toJSONString(dto));
// RestApiResponse<?> response = null;
// try {
// // 校验签名
// // lianLianService.checkoutSign();
// LianLianPageResponse pageResponse = lianLianService.query_stations_info(dto);
// response = new RestApiResponse<>(pageResponse);
// }catch (BusinessException e) {
// logger.error("联联平台查询充电站信息 error",e);
// response = new RestApiResponse<>(e.getCode(), e.getMessage());
// }catch (Exception e) {
// logger.error("联联平台查询充电站信息 error", e);
// response = new RestApiResponse<>(e);
// }
// logger.info("联联平台查询充电站信息 result:{}", response);
// return response;
// }
/**
* 联联平台查询充电站状态信息
@@ -320,7 +328,7 @@ public class LianLianController extends BaseController {
* http://localhost:8080/LianLian/v1/query_token
*/
@PostMapping("/v1/query_token")
public CommonResult<?> queryToken(QueryTokenDTO dto) {
public CommonResult<?> queryToken(CommonParamsDTO dto) {
try {
Map<String, String> map = lianLianService.generateToken(dto);
return CommonResult.success(0, "", map.get("data"), map.get("sig"));
@@ -329,4 +337,34 @@ public class LianLianController extends BaseController {
return CommonResult.failed("获取token发生异常");
}
}
/**
* 联联平台查询充电站信息
* http://localhost:8080/LianLian/query_stations_info
* @param dto
* @return
*/
@PostMapping("/query_stations_info")
public CommonResult<?> query_stations_info(@RequestBody CommonParamsDTO dto) {
try {
// 校验签名
Map<String, String> resultMap = lianLianService.checkoutSign(dto);
if (resultMap == null) {
// 签名错误
return CommonResult.failed("签名校验错误");
}
String operatorSecret = resultMap.get("OperatorSecret");
String dataString = resultMap.get("Data");
// 解密data
byte[] plainText = Cryptos.aesDecrypt(Encodes.decodeBase64(dataString), operatorSecret.getBytes(), operatorSecret.getBytes());
String dataStr = new String(plainText, "UTF-8");
// 转换成相应对象
QueryStationInfoDTO queryStationInfoDTO = JSONObject.parseObject(dataStr, QueryStationInfoDTO.class);
LianLianPageResponse response = lianLianService.query_stations_info(queryStationInfoDTO);
return CommonResult.success(response);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}