mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-20 02:55:04 +08:00
update
This commit is contained in:
@@ -642,8 +642,6 @@ public class SiChuanPlatformServiceImpl implements ThirdPartyPlatformService {
|
||||
String dataSecret = thirdPartySecretInfoVO.getTheirDataSecret();
|
||||
String dataSecretIv = thirdPartySecretInfoVO.getTheirDataSecretIv();
|
||||
String urlAddress = thirdPartySecretInfoVO.getTheirUrlPrefix();
|
||||
// 查询站点信息
|
||||
PileStationVO stationInfo = pileStationInfoService.getStationInfo(orderInfo.getStationId());
|
||||
|
||||
// 查询枪口实时状态
|
||||
List<RealTimeMonitorData> chargingRealTimeData = orderBasicInfoService.getChargingRealTimeData(orderInfo.getTransactionCode());
|
||||
@@ -697,7 +695,7 @@ public class SiChuanPlatformServiceImpl implements ThirdPartyPlatformService {
|
||||
.orderStatus(Integer.parseInt(orderStatus))
|
||||
.equipmentClassification(Constants.one)
|
||||
.pushTimeStamp(dateTime)
|
||||
.connectorStatus(Integer.parseInt(realTimeMonitorData.getConnectorStatus())) // 3-充电中
|
||||
.connectorStatus(info.getStatus()) // 3-充电中
|
||||
.currentA(current.setScale(4, RoundingMode.HALF_UP))
|
||||
.voltageA(voltage.setScale(4, RoundingMode.HALF_UP))
|
||||
.soc(new BigDecimal(soc).setScale(1, RoundingMode.HALF_UP))
|
||||
@@ -719,12 +717,6 @@ public class SiChuanPlatformServiceImpl implements ThirdPartyPlatformService {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 推送充换电站用能统计信息 supervise_notification_operation_stats_info
|
||||
*
|
||||
* @param stationId
|
||||
* @throws UnsupportedOperationException 未实现异常
|
||||
*/
|
||||
@Override
|
||||
public String notificationOperationStatsInfo(String stationId) {
|
||||
// 1. 获取统计时间范围(前一日的00:00:00至23:59:59)
|
||||
@@ -743,6 +735,7 @@ public class SiChuanPlatformServiceImpl implements ThirdPartyPlatformService {
|
||||
log.info("站点{}没有查询到前一日的订单信息", stationId);
|
||||
return null;
|
||||
}
|
||||
log.info("站点{}查询到{}条订单信息", stationId, orderBasicInfos.size());
|
||||
} catch (Exception e) {
|
||||
log.error("查询站点{}订单信息失败", stationId, e);
|
||||
return "查询订单失败: " + e.getMessage();
|
||||
@@ -785,106 +778,103 @@ public class SiChuanPlatformServiceImpl implements ThirdPartyPlatformService {
|
||||
// 如果未获取到统计开始或结束时间,使用默认值
|
||||
if (startChargeTime == null) {
|
||||
startChargeTime = startTime;
|
||||
log.warn("站点{}未获取到有效订单开始时间,使用默认开始时间: {}", stationId, startTime);
|
||||
}
|
||||
if (endChargeTime == null) {
|
||||
endChargeTime = endTime;
|
||||
log.warn("站点{}未获取到有效订单结束时间,使用默认结束时间: {}", stationId, endTime);
|
||||
}
|
||||
|
||||
// 4. 按枪口排序,分组,将充电时长和充电量累加
|
||||
// 4. 按枪口分组统计
|
||||
Map<String, List<SupStationStatsVO>> collect = orderBasicInfos.stream()
|
||||
.filter(vo -> vo.getChargingTime() != null)
|
||||
.filter(vo -> vo.getPileConnectorCode() != null) // 仅过滤枪号为空的订单
|
||||
.collect(Collectors.groupingBy(SupStationStatsVO::getPileConnectorCode));
|
||||
TreeMap<String, List<SupStationStatsVO>> sortedMap = new TreeMap<>(collect);
|
||||
|
||||
List<SupStationStatsInfo.EquipmentStatsInfo> equipmentStatsInfoList = new ArrayList<>();
|
||||
// 初始化相关数据
|
||||
String pileSn = "";
|
||||
BigDecimal pileTotalPower = BigDecimal.ZERO;
|
||||
int pileChargeTime = 0;
|
||||
|
||||
List<SupStationStatsInfo.EquipmentStatsInfo> equipmentStatsInfoList = new ArrayList<>();
|
||||
String currentPileSn = ""; // 当前处理的桩编号
|
||||
BigDecimal currentPilePower = BigDecimal.ZERO; // 当前桩的总电量
|
||||
int currentPileChargeTime = 0; // 当前桩的总充电时长
|
||||
List<SupStationStatsInfo.EquipmentStatsInfo.ConnectorStatsInfo> currentConnectorList = new ArrayList<>();
|
||||
|
||||
// 遍历每个枪口分组
|
||||
for (Map.Entry<String, List<SupStationStatsVO>> entry : sortedMap.entrySet()) {
|
||||
String pileConnectorCode = entry.getKey();
|
||||
List<SupStationStatsVO> voList = entry.getValue();
|
||||
List<SupStationStatsVO> connectorOrders = entry.getValue();
|
||||
|
||||
SupStationStatsInfo.EquipmentStatsInfo.ConnectorStatsInfo connectorStatsInfo = null;
|
||||
List<SupStationStatsInfo.EquipmentStatsInfo.ConnectorStatsInfo> connectorStatsInfoList = new ArrayList<>();
|
||||
|
||||
for (SupStationStatsVO vo : voList) {
|
||||
connectorStatsInfo = new SupStationStatsInfo.EquipmentStatsInfo.ConnectorStatsInfo();
|
||||
|
||||
// 先封装枪口数据
|
||||
// 处理该枪号下的所有订单
|
||||
for (SupStationStatsVO order : connectorOrders) {
|
||||
// 创建并初始化枪口统计信息
|
||||
SupStationStatsInfo.EquipmentStatsInfo.ConnectorStatsInfo connectorStatsInfo =
|
||||
new SupStationStatsInfo.EquipmentStatsInfo.ConnectorStatsInfo();
|
||||
connectorStatsInfo.setConnectorId(pileConnectorCode);
|
||||
connectorStatsInfo.setEquipmentClassification(1);
|
||||
|
||||
BigDecimal power = vo.getTotalPower();
|
||||
// 设置枪口用电量(如果不为空)
|
||||
BigDecimal power = order.getTotalPower();
|
||||
if (power != null) {
|
||||
connectorStatsInfo.setConnectorElectricity(power.setScale(4, RoundingMode.HALF_UP));
|
||||
}
|
||||
|
||||
String newPileSn = vo.getPileSn();
|
||||
if (!StringUtils.equals(pileSn, newPileSn)) {
|
||||
if (!pileSn.isEmpty()) {
|
||||
SupStationStatsInfo.EquipmentStatsInfo equipmentStatsInfo = new SupStationStatsInfo.EquipmentStatsInfo();
|
||||
equipmentStatsInfo.setEquipmentId(pileSn);
|
||||
equipmentStatsInfo.setEquipmentClassification(1);
|
||||
equipmentStatsInfo.setEquipmentElectricity(pileTotalPower.setScale(4, RoundingMode.HALF_UP));
|
||||
equipmentStatsInfo.setEquipmentTotalChargeTime(pileChargeTime);
|
||||
equipmentStatsInfo.setEquipmentTotalChargeNum(voList.size());
|
||||
equipmentStatsInfo.setEquipmentTotalWarningNum(0);
|
||||
equipmentStatsInfo.setConnectorStatsInfos(connectorStatsInfoList);
|
||||
equipmentStatsInfo.setSupconnectorStatsInfos(connectorStatsInfoList);
|
||||
equipmentStatsInfoList.add(equipmentStatsInfo);
|
||||
// 获取当前订单的桩编号(处理可能为空的情况)
|
||||
String pileSn = order.getPileSn() != null ? order.getPileSn() : "unknown_pile";
|
||||
|
||||
// 检查是否需要创建新的桩统计信息
|
||||
if (!pileSn.equals(currentPileSn)) {
|
||||
// 如果不是第一个桩,保存之前的桩统计信息
|
||||
if (!currentPileSn.isEmpty()) {
|
||||
saveCurrentPileStats(
|
||||
currentPileSn,
|
||||
currentPilePower,
|
||||
currentPileChargeTime,
|
||||
currentConnectorList,
|
||||
equipmentStatsInfoList
|
||||
);
|
||||
}
|
||||
pileSn = newPileSn;
|
||||
pileTotalPower = BigDecimal.ZERO;
|
||||
pileChargeTime = 0;
|
||||
connectorStatsInfoList = new ArrayList<>();
|
||||
|
||||
// 初始化新桩的统计信息
|
||||
currentPileSn = pileSn;
|
||||
currentPilePower = BigDecimal.ZERO;
|
||||
currentPileChargeTime = 0;
|
||||
currentConnectorList = new ArrayList<>();
|
||||
}
|
||||
|
||||
Integer chargingTime = vo.getChargingTime();
|
||||
if (chargingTime != null) {
|
||||
pileChargeTime += chargingTime;
|
||||
}
|
||||
|
||||
power = vo.getTotalPower();
|
||||
// 累加当前桩的总电量和总充电时长
|
||||
if (power != null) {
|
||||
pileTotalPower = pileTotalPower.add(power);
|
||||
currentPilePower = currentPilePower.add(power);
|
||||
}
|
||||
|
||||
connectorStatsInfo.setConnectorTotalChargeTime(chargingTime != null? chargingTime : 0);
|
||||
connectorStatsInfo.setConnectorTotalChargeNum(voList.size());
|
||||
String startTimeStr = order.getStartTime();
|
||||
String endTimeStr = order.getEndTime();
|
||||
int chargeTime = 0;
|
||||
|
||||
if (startTimeStr != null && endTimeStr != null) {
|
||||
try {
|
||||
chargeTime = (int) DateUtils.intervalTime(startTimeStr, endTimeStr);
|
||||
currentPileChargeTime += chargeTime;
|
||||
} catch (Exception e) {
|
||||
log.error("计算订单{}充电时长失败", order.getOrderCode(), e);
|
||||
}
|
||||
}
|
||||
connectorStatsInfo.setConnectorTotalChargeTime(chargeTime);
|
||||
connectorStatsInfo.setConnectorTotalChargeNum(connectorOrders.size());
|
||||
connectorStatsInfo.setConnectorTotalWarningNum(0);
|
||||
connectorStatsInfoList.add(connectorStatsInfo);
|
||||
}
|
||||
|
||||
if (!pileSn.isEmpty()) {
|
||||
SupStationStatsInfo.EquipmentStatsInfo equipmentStatsInfo = new SupStationStatsInfo.EquipmentStatsInfo();
|
||||
equipmentStatsInfo.setEquipmentId(pileSn);
|
||||
equipmentStatsInfo.setEquipmentClassification(1);
|
||||
equipmentStatsInfo.setEquipmentElectricity(pileTotalPower.setScale(4, RoundingMode.HALF_UP));
|
||||
equipmentStatsInfo.setEquipmentTotalChargeTime(pileChargeTime);
|
||||
equipmentStatsInfo.setEquipmentTotalChargeNum(voList.size());
|
||||
equipmentStatsInfo.setEquipmentTotalWarningNum(0);
|
||||
equipmentStatsInfo.setConnectorStatsInfos(connectorStatsInfoList);
|
||||
equipmentStatsInfo.setSupconnectorStatsInfos(connectorStatsInfoList);
|
||||
equipmentStatsInfoList.add(equipmentStatsInfo);
|
||||
currentConnectorList.add(connectorStatsInfo);
|
||||
}
|
||||
}
|
||||
|
||||
// 5. 获取站点和商户信息
|
||||
PileStationVO stationInfo;
|
||||
PileMerchantInfoVO pileMerchantInfoVO;
|
||||
try {
|
||||
stationInfo = pileStationInfoService.getStationInfo(stationId);
|
||||
pileMerchantInfoVO = pileMerchantInfoService.queryMerchantInfoByStationId(String.valueOf(stationInfo.getId()));
|
||||
} catch (Exception e) {
|
||||
log.error("查询站点{}或商户信息失败", stationId, e);
|
||||
return "查询站点/商户信息失败: " + e.getMessage();
|
||||
if (!currentPileSn.isEmpty() && !currentConnectorList.isEmpty()) {
|
||||
saveCurrentPileStats(
|
||||
currentPileSn,
|
||||
currentPilePower,
|
||||
currentPileChargeTime,
|
||||
currentConnectorList,
|
||||
equipmentStatsInfoList
|
||||
);
|
||||
log.info("站点{}最终统计到{}个充电桩数据", stationId, equipmentStatsInfoList.size());
|
||||
} else {
|
||||
log.warn("站点{}未统计到任何充电桩数据!", stationId);
|
||||
}
|
||||
|
||||
// 6. 构建请求对象
|
||||
SupStationStatsInfo supStationStatsInfo = SupStationStatsInfo.builder()
|
||||
.stationId(stationId)
|
||||
.operatorId(Constants.OPERATORID_JIANG_SU)
|
||||
@@ -894,7 +884,7 @@ public class SiChuanPlatformServiceImpl implements ThirdPartyPlatformService {
|
||||
.endTime(endChargeTime)
|
||||
.stationElectricity(stationTotalElectricity)
|
||||
.stationTotalChargeEnergy(stationTotalElectricity)
|
||||
.stationTotalOtherEnergy(new BigDecimal(0).setScale(4, RoundingMode.HALF_UP))
|
||||
.stationTotalOtherEnergy(BigDecimal.ZERO.setScale(4, RoundingMode.HALF_UP))
|
||||
.stationTotalSwapChargeNum(0)
|
||||
.stationTotalChargeNum(orderBasicInfos.size())
|
||||
.stationTotalChargeTime(stationTotalChargeTime)
|
||||
@@ -918,17 +908,21 @@ public class SiChuanPlatformServiceImpl implements ThirdPartyPlatformService {
|
||||
String dataSecretIv = thirdPartySecretInfoVO.getTheirDataSecretIv();
|
||||
String urlAddress = thirdPartySecretInfoVO.getTheirUrlPrefix();
|
||||
String url = urlAddress + "supervise_notification_operation_stats_info";
|
||||
|
||||
// 获取令牌
|
||||
String token = getToken(urlAddress, operatorId, operatorSecret, dataSecretIv, signSecret, dataSecret);
|
||||
if (StringUtils.isBlank(token)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 调用平台接口
|
||||
String result = HttpRequestUtil.sendPost(token, jsonString, url, dataSecret, dataSecretIv, operatorId, signSecret);
|
||||
log.info("站点{}推送结果: {}", stationId, result);
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 推送充电订单信息
|
||||
* supervise_notification_charge_order_info
|
||||
@@ -1138,7 +1132,27 @@ public class SiChuanPlatformServiceImpl implements ThirdPartyPlatformService {
|
||||
|
||||
}*/
|
||||
|
||||
private void saveCurrentPileStats(
|
||||
String pileSn,
|
||||
BigDecimal pileTotalPower,
|
||||
int pileTotalChargeTime,
|
||||
List<SupStationStatsInfo.EquipmentStatsInfo.ConnectorStatsInfo> connectorList,
|
||||
List<SupStationStatsInfo.EquipmentStatsInfo> resultList
|
||||
) {
|
||||
SupStationStatsInfo.EquipmentStatsInfo equipmentStatsInfo = new SupStationStatsInfo.EquipmentStatsInfo();
|
||||
equipmentStatsInfo.setEquipmentId(pileSn);
|
||||
equipmentStatsInfo.setEquipmentClassification(1);
|
||||
equipmentStatsInfo.setEquipmentElectricity(pileTotalPower.setScale(4, RoundingMode.HALF_UP));
|
||||
equipmentStatsInfo.setEquipmentTotalChargeTime(pileTotalChargeTime);
|
||||
equipmentStatsInfo.setEquipmentTotalChargeNum(connectorList.size()); // 改为每个桩的订单数
|
||||
equipmentStatsInfo.setEquipmentTotalWarningNum(0);
|
||||
equipmentStatsInfo.setConnectorStatsInfos(connectorList);
|
||||
equipmentStatsInfo.setSupconnectorStatsInfos(connectorList);
|
||||
|
||||
resultList.add(equipmentStatsInfo);
|
||||
log.debug("添加桩统计信息: 桩编号={}, 电量={}, 充电时长={}, 枪数量={}",
|
||||
pileSn, pileTotalPower, pileTotalChargeTime, connectorList.size());
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单推送数据封装
|
||||
|
||||
Reference in New Issue
Block a user