This commit is contained in:
2023-05-27 17:49:32 +08:00
4 changed files with 74 additions and 28 deletions

View File

@@ -211,23 +211,23 @@ public class LianLianController extends BaseController {
* @param dto * @param dto
* @return * @return
*/ */
@PostMapping("/query_station_stats") // @PostMapping("/query_station_stats")
public RestApiResponse<?> query_station_stats(@RequestBody QueryStationInfoDTO dto) { // public RestApiResponse<?> query_station_stats(@RequestBody QueryStationInfoDTO dto) {
logger.info("联联平台查询统计信息 params :{}", JSONObject.toJSONString(dto)); // logger.info("联联平台查询统计信息 params :{}", JSONObject.toJSONString(dto));
RestApiResponse<?> response; // RestApiResponse<?> response;
try { // try {
StationStatsInfo stationStatsInfo = lianLianService.query_station_stats(dto); // StationStatsInfo stationStatsInfo = lianLianService.query_station_stats(dto);
response = new RestApiResponse<>(stationStatsInfo); // response = new RestApiResponse<>(stationStatsInfo);
}catch (BusinessException e) { // }catch (BusinessException e) {
logger.error("联联平台查询统计信息 error",e); // logger.error("联联平台查询统计信息 error",e);
response = new RestApiResponse<>(e.getCode(), e.getMessage()); // response = new RestApiResponse<>(e.getCode(), e.getMessage());
} catch (Exception e) { // } catch (Exception e) {
logger.error("联联平台查询统计信息 error", e); // logger.error("联联平台查询统计信息 error", e);
response = new RestApiResponse<>(e); // response = new RestApiResponse<>(e);
} // }
logger.info("联联平台查询统计信息 result :{}", response); // logger.info("联联平台查询统计信息 result :{}", response);
return response; // return response;
} // }
/** /**
* 请求设备认证 * 请求设备认证
@@ -404,4 +404,36 @@ public class LianLianController extends BaseController {
} }
return CommonResult.failed("查询充电站状态信息发生异常"); return CommonResult.failed("查询充电站状态信息发生异常");
} }
/**
* 查询统计信息
* http://localhost:8080/LianLian/query_station_stats
*
* @param dto
* @return
*/
@PostMapping("/query_station_stats")
public CommonResult<?> query_station_stats(@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);
queryStationInfoDTO.setOperatorId(dto.getOperatorID());
Map<String, String> map = lianLianService.query_station_stats(queryStationInfoDTO);
return CommonResult.success(0, "查询统计信息成功!", map.get("Data"), map.get("Sig"));
} catch (Exception e) {
e.printStackTrace();
}
return CommonResult.failed("查询统计信息发生异常");
}
} }

View File

@@ -239,7 +239,11 @@ public class SpringBootTestController {
// String dataJson = JSONUtil.toJsonStr(data); // String dataJson = JSONUtil.toJsonStr(data);
JSONObject json = new JSONObject(); JSONObject json = new JSONObject();
json.put("StationIDs", com.google.common.collect.Lists.newArrayList("1", "2")); // json.put("StationIDs", com.google.common.collect.Lists.newArrayList("1", "2"));
json.put("StationID", "2");
json.put("StartTime", "2023-02-01");
json.put("EndTime", "2023-06-01");
String dataJson = JSONObject.toJSONString(json); String dataJson = JSONObject.toJSONString(json);
// 加密 // 加密
byte[] encryptText = Cryptos.aesEncrypt(dataJson.getBytes("UTF-8"), byte[] encryptText = Cryptos.aesEncrypt(dataJson.getBytes("UTF-8"),

View File

@@ -45,7 +45,7 @@ public interface LianLianService {
* @param dto * @param dto
* @return * @return
*/ */
StationStatsInfo query_station_stats(QueryStationInfoDTO dto); Map<String, String> query_station_stats(QueryStationInfoDTO dto);
/** /**

View File

@@ -389,17 +389,15 @@ public class LianLianServiceImpl implements LianLianService {
* @return * @return
*/ */
@Override @Override
public StationStatsInfo query_station_stats(QueryStationInfoDTO dto) { public Map<String, String> query_station_stats(QueryStationInfoDTO dto) {
DockingPlatformConfig configInfo = dockingPlatformConfigService.getInfoByOperatorId(dto.getOperatorId());
if (configInfo == null) {
return null;
}
// 根据站点id 查出这段时间的充电量 // 根据站点id 查出这段时间的充电量
List<AccumulativeInfoVO> list = orderBasicInfoService.getAccumulativeInfoForLianLian(dto); List<AccumulativeInfoVO> list = orderBasicInfoService.getAccumulativeInfoForLianLian(dto);
if (CollectionUtils.isEmpty(list)) { if (CollectionUtils.isEmpty(list)) {
return StationStatsInfo.builder() return null;
.StationID(dto.getStationID())
.StartTime(dto.getStartTime())
.EndTime(dto.getEndTime())
.StationElectricity(BigDecimal.ZERO)
.equipmentStatsInfos(Lists.newArrayList()) // 设备列表
.build();
} }
// 根据充电桩编号分组 key=充电桩编号 // 根据充电桩编号分组 key=充电桩编号
@@ -465,7 +463,19 @@ public class LianLianServiceImpl implements LianLianService {
.equipmentStatsInfos(equipmentStatsInfoList) // 设备列表 .equipmentStatsInfos(equipmentStatsInfoList) // 设备列表
.build(); .build();
return stationStatsInfo; // 加密
Map<String, String> resultMap = Maps.newLinkedHashMap();
// 加密数据
byte[] encryptText = Cryptos.aesEncrypt(JSONObject.toJSONString(stationStatsInfo).getBytes(),
configInfo.getOperatorSecret().getBytes(), configInfo.getDataSecretIv().getBytes());
String encryptData = Encodes.encodeBase64(encryptText);
resultMap.put("Data", encryptData);
// 生成sig
String resultSign = GBSignUtils.sign(resultMap, configInfo.getOperatorSecret());
resultMap.put("Sig", resultSign);
return resultMap;
} }
/** /**