This commit is contained in:
YAS\29473
2024-11-27 10:49:08 +08:00
parent f114365347
commit a96ea5aafd
2 changed files with 154 additions and 3 deletions

View File

@@ -26,7 +26,7 @@ public enum ThirdPlatformTypeEnum {
ZHE_JIANG_PLATFORM("15", "浙江省平台", "002485048"),
SU_ZHOU_PLATFORM("16", "苏州市平台", "MAC1MFJ1X"),
GAN_SU_PLATFORM("17", "甘肃省平台", ""),
GUI_ZHOU_PLATFORM("18", "贵州省平台", ""),
GUI_ZHOU_PLATFORM("18", "贵州省平台", "009390404"),
NAN_RUI_PLATFORM("19", "南瑞平台", ""),
;

View File

@@ -27,6 +27,7 @@ import com.jsowell.pile.service.*;
import com.jsowell.pile.thirdparty.CommonParamsDTO;
import com.jsowell.pile.thirdparty.EquipmentInfo;
import com.jsowell.pile.util.MerchantUtils;
import com.jsowell.pile.vo.SupStationStatsVO;
import com.jsowell.pile.vo.ThirdPartySecretInfoVO;
import com.jsowell.pile.vo.base.ConnectorInfoVO;
import com.jsowell.pile.vo.base.MerchantInfoVO;
@@ -59,6 +60,7 @@ import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
@@ -195,7 +197,7 @@ public class GuiZhouPlatformServiceImpl implements ThirdPartyPlatformService {
/**
* 查询充电站信息 query_stations_info
* supervise_query_operator_info
* supervise_query_stations_info
* 此接口用于查询对接平台的充电站的信息
*
* @param dto 查询站点信息dto
@@ -686,6 +688,155 @@ public class GuiZhouPlatformServiceImpl implements ThirdPartyPlatformService {
return result;
}
/**
* 推送充换电站用能统计信息 supervise_notification_operation_stats_info
*
* @param stationId
* @throws UnsupportedOperationException 未实现异常
*/
@Override
public String notificationOperationStatsInfo(String stationId) {
SupStationStatsInfo.
EquipmentStatsInfo equipmentStatsInfo = new SupStationStatsInfo.EquipmentStatsInfo();
List<SupStationStatsInfo.
EquipmentStatsInfo> equipmentStatsInfoList = new ArrayList<>();
SupStationStatsInfo.
EquipmentStatsInfo.
ConnectorStatsInfo connectorStatsInfo = null;
List<SupStationStatsInfo.
EquipmentStatsInfo.
ConnectorStatsInfo> connectorStatsInfoList = new ArrayList<>();
// 根据站点id查询订单记录 (新建Service方法)
List<SupStationStatsVO> orderVOS = orderBasicInfoService.queryOrderListByStationId(stationId);
// 根据订单信息汇总出站点充电数据
BigDecimal stationTotalElectricity = BigDecimal.ZERO; // 充电站累计用电量
int stationChargeTime = Constants.zero; // 充电站累计充电次数
for (SupStationStatsVO orderVO : orderVOS) {
// 充电站累计用电量
BigDecimal totalPower = orderVO.getTotalPower();
if (totalPower == null || orderVO.getChargingTime() == null) {
continue;
}
stationTotalElectricity = stationTotalElectricity.add(totalPower);
// 充电站累计充电时长(分钟)
stationChargeTime += orderVO.getChargingTime();
}
// 根据枪口排序,分组,将充电时长和充电量累加
Map<String, SupStationStatsVO> collect = orderVOS.stream()
.sorted(Comparator.comparing(SupStationStatsVO::getPileConnectorCode))
.filter(vo -> vo.getChargingTime() != null && vo.getTotalPower() != null)
.collect(Collectors.toMap(SupStationStatsVO::getPileConnectorCode, Function.identity(),
(a, b) -> {
a.setChargingTime(a.getChargingTime() + b.getChargingTime());
a.setTotalPower(a.getTotalPower().add(b.getTotalPower()));
return a;
}));
TreeMap<String, SupStationStatsVO> sortedMap = new TreeMap<>(collect);
// 初始化相关数据
String pileSn = "";
BigDecimal pileTotalPower = BigDecimal.ZERO;
int pileChargeTime = Constants.zero;
// key : pileConnectorCode
// value: SupStationStatsVO
for (Map.Entry<String, SupStationStatsVO> entry : sortedMap.entrySet()) {
String pileConnectorCode = entry.getKey();
SupStationStatsVO vo = entry.getValue();
connectorStatsInfo = new SupStationStatsInfo.EquipmentStatsInfo.ConnectorStatsInfo();
// 先封装枪口数据
connectorStatsInfo.setConnectorId(pileConnectorCode);
connectorStatsInfo.setEquipmentClassification(1);
connectorStatsInfo.setConnectorElectricity(vo.getTotalPower());
connectorStatsInfo.setConnectorTotalChargeTime(vo.getChargingTime());
// TODO connectorStatsInfo.setConnectorTotalChargeNum();
connectorStatsInfo.setConnectorTotalWarningNum(0);
// 对比这次循环到的桩编号和上次的桩编号如果是同一台桩将数据进行汇总如果不是新建桩数据并将之前的累计数据清0
String newPileSn = vo.getPileSn();
if (!StringUtils.equals(pileSn, newPileSn)) {
pileSn = newPileSn;
pileTotalPower = BigDecimal.ZERO;
pileChargeTime = Constants.zero;
equipmentStatsInfo = new SupStationStatsInfo.EquipmentStatsInfo();
connectorStatsInfoList = new ArrayList<>();
equipmentStatsInfo.setEquipmentId(pileSn);
equipmentStatsInfo.setEquipmentClassification(1);
equipmentStatsInfo.setEquipmentElectricity(vo.getTotalPower());
equipmentStatsInfo.setEquipmentTotalChargeTime(vo.getChargingTime());
// TODO equipmentStatsInfo.setEquipmentTotalChargeNum();
pileTotalPower = pileTotalPower.add(vo.getTotalPower());
pileChargeTime += vo.getChargingTime();
connectorStatsInfoList.add(connectorStatsInfo);
equipmentStatsInfo.setConnectorStatsInfos(connectorStatsInfoList);
equipmentStatsInfoList.add(equipmentStatsInfo);
} else {
// 同一台桩,枪口号不同,累加桩数据,将枪口数据新建
pileTotalPower = pileTotalPower.add(vo.getTotalPower());
pileChargeTime += vo.getChargingTime();
equipmentStatsInfo.setEquipmentElectricity(pileTotalPower); // 第一次判断时一定不会进入到这里,所以不用判断 equipmentStatsInfo 是否为 null
equipmentStatsInfo.setEquipmentTotalChargeTime(pileChargeTime);
connectorStatsInfoList.add(connectorStatsInfo);
equipmentStatsInfo.setConnectorStatsInfos(connectorStatsInfoList);
equipmentStatsInfoList.add(equipmentStatsInfo);
}
}
// 创建对象
String startTime = DateUtils.getYesterdayStr() + " 00:00:00";
String endTime = DateUtils.getYesterdayStr() + " 23:59:59";
SupStationStatsInfo supStationStatsInfo = SupStationStatsInfo.builder()
.stationId(stationId)
.operatorId(Constants.OPERATORID_JIANG_SU)
// .equipmentOwnerId(orderVOS.get(0).getOrganizationCode())
.stationClassification(1)
.startTime(startTime)
.endTime(endTime)
.stationElectricity(stationTotalElectricity)
.stationTotalChargeEnergy(stationTotalElectricity)
.stationTotalChargeNum(orderVOS.size())
.stationTotalChargeTime(stationChargeTime)
.stationTotalWarningNum(0)
.equipmentStatsInfos(equipmentStatsInfoList)
.build();
JSONObject json = new JSONObject();
json.put("StationStatsInfos", supStationStatsInfo);
String jsonString = JSON.toJSONString(json);
// 发送推送请求
ThirdPartySecretInfoVO guiZhouPlatformSecretInfo = getGuiZhouPlatformSecretInfo();
String operatorId = guiZhouPlatformSecretInfo.getOurOperatorId();
String operatorSecret = guiZhouPlatformSecretInfo.getTheirOperatorSecret();
String signSecret = guiZhouPlatformSecretInfo.getTheirSigSecret();
String dataSecret = guiZhouPlatformSecretInfo.getTheirDataSecret();
String dataSecretIv = guiZhouPlatformSecretInfo.getTheirDataSecretIv();
String urlAddress = guiZhouPlatformSecretInfo.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);
return result;
}
/**
* 推送充换电站实时功率 supervise_notification_realtime_power_info
*
@@ -802,7 +953,7 @@ public class GuiZhouPlatformServiceImpl implements ThirdPartyPlatformService {
private ThirdPartySecretInfoVO getGuiZhouPlatformSecretInfo() {
String thirdPartyType = ThirdPlatformTypeEnum.GUI_ZHOU_PLATFORM.getTypeCode();
// 通过第三方平台类型查询相关配置信息
ThirdPartySecretInfoVO thirdPartySecretInfoVO = thirdpartySecretInfoService.queryByThirdPlatformType(ThirdPlatformTypeEnum.GUI_ZHOU_PLATFORM.getTypeCode());
ThirdPartySecretInfoVO thirdPartySecretInfoVO = thirdpartySecretInfoService.queryByThirdPlatformType(thirdPartyType);
if (thirdPartySecretInfoVO == null) {
throw new BusinessException(ReturnCodeEnum.CODE_SELECT_INFO_IS_NULL);
}