update空指针接口

This commit is contained in:
YAS\29473
2025-07-09 18:36:46 +08:00
parent b50178aad3
commit 35ce808ee7
5 changed files with 218 additions and 167 deletions

View File

@@ -414,4 +414,6 @@ public interface OrderBasicInfoMapper {
* @return * @return
*/ */
List<OrderBasicInfo> getOrderBasicInfoByTimeInterval(@Param("stationIds") List<String> stationIds, @Param("startTime") String startTime, @Param("endTime") String endTime); List<OrderBasicInfo> getOrderBasicInfoByTimeInterval(@Param("stationIds") List<String> stationIds, @Param("startTime") String startTime, @Param("endTime") String endTime);
}
List<SupStationStatsVO> queryOrderListByStationIdAndTime(@Param("stationId") String stationId , @Param("startTime") String startTime , @Param("endTime") String endTime);
}

View File

@@ -581,4 +581,12 @@ public interface OrderBasicInfoService{
List<OrderBasicInfo> getOrderBasicInfoByTimeInterval(List<String> stationIds, String startTime, String endTime); List<OrderBasicInfo> getOrderBasicInfoByTimeInterval(List<String> stationIds, String startTime, String endTime);
/**
* 查询站点订单时间段用电量列表
* @param stationId
* @param startTime
* @param endTime
* @return
*/
List<SupStationStatsVO> queryOrderListByStationIdAndTime(String stationId , String startTime , String endTime);
} }

View File

@@ -5400,5 +5400,10 @@ public class OrderBasicInfoServiceImpl implements OrderBasicInfoService {
public List<OrderBasicInfo> getOrderBasicInfoByTimeInterval(List<String> stationIds, String startTime, String endTime) { public List<OrderBasicInfo> getOrderBasicInfoByTimeInterval(List<String> stationIds, String startTime, String endTime) {
return orderBasicInfoMapper.getOrderBasicInfoByTimeInterval(stationIds, startTime, endTime); return orderBasicInfoMapper.getOrderBasicInfoByTimeInterval(stationIds, startTime, endTime);
} }
@Override
public List<SupStationStatsVO> queryOrderListByStationIdAndTime(String stationId , String startTime , String endTime) {
return orderBasicInfoMapper.queryOrderListByStationIdAndTime(stationId, startTime, endTime);
}
} }

View File

@@ -3302,4 +3302,24 @@
</foreach> </foreach>
and create_time between #{startTime,jdbcType=VARCHAR} and #{endTime,jdbcType=VARCHAR} and create_time between #{startTime,jdbcType=VARCHAR} and #{endTime,jdbcType=VARCHAR}
</select> </select>
<select id="queryOrderListByStationIdAndTime" resultType="com.jsowell.pile.vo.SupStationStatsVO">
select
t1.order_code as orderCode,
t3.organization_code as organizationCode,
t1.station_id AS stationId,
t1.pile_sn AS pileSn,
t1.pile_connector_code AS pileConnectorCode,
t1.charge_start_time AS StartTime,
t1.charge_end_time AS EndTime,
t2.total_used_electricity AS totalPower
FROM order_basic_info t1
JOIN order_detail t2 ON t1.order_code = t2.order_code
AND t1.del_flag = '0'
JOIN pile_merchant_info t3 on t1.merchant_id = t3.id
where t1.station_id = #{stationId,jdbcType=VARCHAR}
and t1.create_time <![CDATA[ >= ]]> #{startTime,jdbcType=VARCHAR}
and t1.create_time <![CDATA[ <= ]]> #{endTime,jdbcType=VARCHAR}
order by t1.create_time DESC
</select>
</mapper> </mapper>

View File

@@ -11,6 +11,7 @@ import com.google.common.collect.Lists;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.jsowell.common.constant.Constants; import com.jsowell.common.constant.Constants;
import com.jsowell.common.core.domain.ykc.RealTimeMonitorData; import com.jsowell.common.core.domain.ykc.RealTimeMonitorData;
import com.jsowell.common.core.redis.RedisCache;
import com.jsowell.common.enums.lianlian.LianLianPileStatusEnum; import com.jsowell.common.enums.lianlian.LianLianPileStatusEnum;
import com.jsowell.common.enums.thirdparty.ThirdPlatformTypeEnum; import com.jsowell.common.enums.thirdparty.ThirdPlatformTypeEnum;
import com.jsowell.common.enums.ykc.*; import com.jsowell.common.enums.ykc.*;
@@ -53,8 +54,12 @@ import org.springframework.stereotype.Service;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.RoundingMode; import java.math.RoundingMode;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*; import java.util.*;
import java.util.function.Function; import java.util.function.Function;
import java.util.logging.Logger;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@Service @Service
@@ -94,6 +99,9 @@ public class SiChuanPlatformServiceImpl implements ThirdPartyPlatformService {
@Autowired @Autowired
private PileMerchantInfoService pileMerchantInfoService; private PileMerchantInfoService pileMerchantInfoService;
@Autowired
RedisCache redisCache;
@@ -273,11 +281,12 @@ public class SiChuanPlatformServiceImpl implements ThirdPartyPlatformService {
SupStationInfoDTO stationInfo = new SupStationInfoDTO(); SupStationInfoDTO stationInfo = new SupStationInfoDTO();
stationInfo.setStationID(String.valueOf(pileStationInfo.getId())); stationInfo.setStationID(String.valueOf(pileStationInfo.getId()));
stationInfo.setOperatorID(Constants.OPERATORID_JIANG_SU); // 组织机构代码 stationInfo.setOperatorID(Constants.OPERATORID_JIANG_SU); // 组织机构代码
String organizationCode = pileStationInfo.getOrganizationCode(); // 充电服务运营商 填写为个人
// 充电服务运营商 stationInfo.setEquipmentOwnerID("999999999");
stationInfo.setEquipmentOwnerID(ThirdPartyPlatformUtils.extractEquipmentOwnerID(organizationCode));
stationInfo.setStationName(pileStationInfo.getStationName()); stationInfo.setStationName(pileStationInfo.getStationName());
stationInfo.setCountryCode(pileStationInfo.getCountryCode()); stationInfo.setCountryCode(pileStationInfo.getCountryCode());
String areaCode = pileStationInfo.getAreaCode(); // 330000,330200,330213 String areaCode = pileStationInfo.getAreaCode(); // 330000,330200,330213
// 根据逗号分组 // 根据逗号分组
String[] split = StringUtils.split(areaCode, ","); String[] split = StringUtils.split(areaCode, ",");
@@ -374,7 +383,6 @@ public class SiChuanPlatformServiceImpl implements ThirdPartyPlatformService {
map.put("PageCount", pageInfo.getPages()); map.put("PageCount", pageInfo.getPages());
map.put("PageNo", pageInfo.getPageNum()); map.put("PageNo", pageInfo.getPageNum());
map.put("StationInfos", resultList); map.put("StationInfos", resultList);
log.info("queryStationsInfo result : " + JSON.toJSONString(map));
return ThirdPartyPlatformUtils.generateResultMap(map, thirdPartySecretInfoVO); return ThirdPartyPlatformUtils.generateResultMap(map, thirdPartySecretInfoVO);
} }
@@ -404,6 +412,7 @@ public class SiChuanPlatformServiceImpl implements ThirdPartyPlatformService {
SupStationInfoDTO info = SupStationInfoDTO.builder() SupStationInfoDTO info = SupStationInfoDTO.builder()
.stationID(stationId) .stationID(stationId)
.operatorID(Constants.OPERATORID_JIANG_SU) .operatorID(Constants.OPERATORID_JIANG_SU)
.equipmentOwnerID("999999999")//充换电服务运营商ID所属方 为个人时填写999999999
.stationName(pileStationInfo.getStationName()) .stationName(pileStationInfo.getStationName())
.countryCode(pileStationInfo.getCountryCode()) .countryCode(pileStationInfo.getCountryCode())
.areaCode(pileStationInfo.getAreaCode()) .areaCode(pileStationInfo.getAreaCode())
@@ -482,12 +491,6 @@ public class SiChuanPlatformServiceImpl implements ThirdPartyPlatformService {
if (StringUtils.isBlank(info.getAreaCodeCountryside())){ if (StringUtils.isBlank(info.getAreaCodeCountryside())){
info.setAreaCodeCountryside("12345678901"); info.setAreaCodeCountryside("12345678901");
} }
// 截取运营商组织机构代码(去除最后一位后的最后九位)
MerchantInfoVO merchantInfo = pileMerchantInfoService.getMerchantInfoVO(String.valueOf(pileStationInfo.getMerchantId()));
String organizationCode = merchantInfo.getOrganizationCode();
info.setEquipmentOwnerID(ThirdPartyPlatformUtils.extractEquipmentOwnerID(organizationCode));
// 站点图片 // 站点图片
if (StringUtils.isNotBlank(pileStationInfo.getPictures())) { if (StringUtils.isNotBlank(pileStationInfo.getPictures())) {
@@ -537,19 +540,16 @@ public class SiChuanPlatformServiceImpl implements ThirdPartyPlatformService {
List<ConnectorInfoVO> voList = entry.getValue(); List<ConnectorInfoVO> voList = entry.getValue();
StationStatusInfo stationStatusInfo = new StationStatusInfo(); StationStatusInfo stationStatusInfo = new StationStatusInfo();
PileStationVO stationInfo = pileStationInfoService.getStationInfo(stationId);
PileMerchantInfoVO pileMerchantInfoVO = pileMerchantInfoService.queryMerchantInfoByStationId(String.valueOf(stationInfo.getId()));
String organizationCode = pileMerchantInfoVO.getOrganizationCode();
stationStatusInfo.setOperatorId(Constants.OPERATORID_JIANG_SU); stationStatusInfo.setOperatorId(Constants.OPERATORID_JIANG_SU);
stationStatusInfo.setEquipmentOwnerId(ThirdPartyPlatformUtils.extractEquipmentOwnerID(organizationCode)); stationStatusInfo.setEquipmentOwnerId("999999999");
stationStatusInfo.setStationId(stationId); stationStatusInfo.setStationId(stationId);
ConnectorStatusInfo connectorStatusInfo; ConnectorStatusInfo connectorStatusInfo;
for (ConnectorInfoVO connectorInfoVO : voList) { for (ConnectorInfoVO connectorInfoVO : voList) {
connectorStatusInfo = ConnectorStatusInfo.builder() connectorStatusInfo = ConnectorStatusInfo.builder()
.operatorId(Constants.OPERATORID_JIANG_SU) .operatorId(Constants.OPERATORID_JIANG_SU)
.equipmentOwnerId(ThirdPartyPlatformUtils.extractEquipmentOwnerID(organizationCode)) .equipmentOwnerId("999999999")
.stationId(connectorInfoVO.getStationId()) .stationId(connectorInfoVO.getStationId())
.equipmentId(connectorInfoVO.getPileSn()) .equipmentId(connectorInfoVO.getPileSn())
.connectorID(connectorInfoVO.getPileConnectorCode()) .connectorID(connectorInfoVO.getPileConnectorCode())
@@ -596,7 +596,7 @@ public class SiChuanPlatformServiceImpl implements ThirdPartyPlatformService {
SupConnectorStatusInfo info = SupConnectorStatusInfo.builder() SupConnectorStatusInfo info = SupConnectorStatusInfo.builder()
.operatorID(Constants.OPERATORID_JIANG_SU) .operatorID(Constants.OPERATORID_JIANG_SU)
.equipmentOwnerID(MerchantUtils.getOperatorID(merchantInfoVO.getOrganizationCode())) .equipmentOwnerID("999999999")
.stationID(connectorInfo.getStationId()) .stationID(connectorInfo.getStationId())
.equipmentID(connectorInfo.getPileSn()) .equipmentID(connectorInfo.getPileSn())
.connectorID(pileConnectorCode) .connectorID(pileConnectorCode)
@@ -644,8 +644,6 @@ public class SiChuanPlatformServiceImpl implements ThirdPartyPlatformService {
String urlAddress = thirdPartySecretInfoVO.getTheirUrlPrefix(); String urlAddress = thirdPartySecretInfoVO.getTheirUrlPrefix();
// 查询站点信息 // 查询站点信息
PileStationVO stationInfo = pileStationInfoService.getStationInfo(orderInfo.getStationId()); PileStationVO stationInfo = pileStationInfoService.getStationInfo(orderInfo.getStationId());
PileMerchantInfoVO pileMerchantInfoVO = pileMerchantInfoService.queryMerchantInfoByStationId(String.valueOf(stationInfo.getId()));
String organizationCode = pileMerchantInfoVO.getOrganizationCode();
// 查询枪口实时状态 // 查询枪口实时状态
List<RealTimeMonitorData> chargingRealTimeData = orderBasicInfoService.getChargingRealTimeData(orderInfo.getTransactionCode()); List<RealTimeMonitorData> chargingRealTimeData = orderBasicInfoService.getChargingRealTimeData(orderInfo.getTransactionCode());
@@ -665,11 +663,6 @@ public class SiChuanPlatformServiceImpl implements ThirdPartyPlatformService {
if (Objects.isNull(info)) { if (Objects.isNull(info)) {
throw new BusinessException(ReturnCodeEnum.CODE_CONNECTOR_INFO_NULL_ERROR); throw new BusinessException(ReturnCodeEnum.CODE_CONNECTOR_INFO_NULL_ERROR);
} }
String merchantId = info.getMerchantId();
MerchantInfoVO merchantInfoVO = pileMerchantInfoService.getMerchantInfoVO(merchantId);
if (Objects.isNull(merchantInfoVO)) {
throw new BusinessException(ReturnCodeEnum.CODE_CONNECTOR_INFO_NULL_ERROR);
}
String orderStatus = orderInfo.getOrderStatus(); String orderStatus = orderInfo.getOrderStatus();
if (StringUtils.equals(OrderStatusEnum.IN_THE_CHARGING.getValue(), orderStatus)) { if (StringUtils.equals(OrderStatusEnum.IN_THE_CHARGING.getValue(), orderStatus)) {
// 充电中 // 充电中
@@ -692,11 +685,11 @@ public class SiChuanPlatformServiceImpl implements ThirdPartyPlatformService {
BigDecimal current = realTimeMonitorData.getOutputCurrent() == null ? BigDecimal.ZERO : new BigDecimal(realTimeMonitorData.getOutputCurrent()); BigDecimal current = realTimeMonitorData.getOutputCurrent() == null ? BigDecimal.ZERO : new BigDecimal(realTimeMonitorData.getOutputCurrent());
BigDecimal voltage = realTimeMonitorData.getOutputVoltage() == null ? BigDecimal.ZERO : new BigDecimal(realTimeMonitorData.getOutputVoltage()); BigDecimal voltage = realTimeMonitorData.getOutputVoltage() == null ? BigDecimal.ZERO : new BigDecimal(realTimeMonitorData.getOutputVoltage());
String soc = realTimeMonitorData.getSOC() == null ? Constants.ZERO : realTimeMonitorData.getSOC(); String soc = realTimeMonitorData.getSOC() == null ? Constants.ZERO : realTimeMonitorData.getSOC();
BigDecimal totalPower = realTimeMonitorData.getChargingDegree() == null ? BigDecimal.ZERO : new BigDecimal(realTimeMonitorData.getChargingDegree());
String dateTime = DateUtils.getDateTime(); String dateTime = DateUtils.getDateTime();
SupEquipChargeStatusInfo supEquipChargeStatusInfo = SupEquipChargeStatusInfo.builder() SupEquipChargeStatusInfo supEquipChargeStatusInfo = SupEquipChargeStatusInfo.builder()
.operatorID(Constants.OPERATORID_JIANG_SU) .operatorID(Constants.OPERATORID_JIANG_SU)
.equipmentOwnerID(ThirdPartyPlatformUtils.extractEquipmentOwnerID(organizationCode)) .equipmentOwnerID("999999999")
.stationID(orderInfo.getStationId()) .stationID(orderInfo.getStationId())
.equipmentID(orderInfo.getPileSn()) .equipmentID(orderInfo.getPileSn())
.connectorID(orderInfo.getPileConnectorCode()) .connectorID(orderInfo.getPileConnectorCode())
@@ -710,10 +703,10 @@ public class SiChuanPlatformServiceImpl implements ThirdPartyPlatformService {
.soc(new BigDecimal(soc).setScale(1, RoundingMode.HALF_UP)) .soc(new BigDecimal(soc).setScale(1, RoundingMode.HALF_UP))
.startTime(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, orderInfo.getChargeStartTime())) .startTime(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, orderInfo.getChargeStartTime()))
.endTime(dateTime) .endTime(dateTime)
.totalPower(new BigDecimal(realTimeMonitorData.getChargingDegree()).setScale(4, BigDecimal.ROUND_HALF_UP)) .totalPower(totalPower.setScale(4, RoundingMode.HALF_UP))
.build(); .build();
supEquipChargeStatusInfo.setEquipmentOwnerID(ThirdPartyPlatformUtils.extractEquipmentOwnerID(stationInfo.getOrganizationCode())); supEquipChargeStatusInfo.setEquipmentOwnerID("999999999");
String url = urlAddress + "supervise_notification_equip_charge_status"; String url = urlAddress + "supervise_notification_equip_charge_status";
// 调用平台接口 // 调用平台接口
@@ -734,135 +727,191 @@ public class SiChuanPlatformServiceImpl implements ThirdPartyPlatformService {
*/ */
@Override @Override
public String notificationOperationStatsInfo(String stationId) { public String notificationOperationStatsInfo(String stationId) {
SupStationStatsInfo.EquipmentStatsInfo equipmentStatsInfo = new SupStationStatsInfo.EquipmentStatsInfo(); // 1. 获取统计时间范围前一日的00:00:00至23:59:59
List<SupStationStatsInfo.EquipmentStatsInfo> equipmentStatsInfoList = new ArrayList<>(); LocalDate yesterday = LocalDate.now().minusDays(1);
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
LocalDateTime startOfYesterday = yesterday.atStartOfDay();
LocalDateTime endOfYesterday = yesterday.atTime(23, 59, 59);
String startTime = startOfYesterday.format(formatter);
String endTime = endOfYesterday.format(formatter);
SupStationStatsInfo.EquipmentStatsInfo.ConnectorStatsInfo connectorStatsInfo = null; // 2. 查询站点下时间段的订单
List<SupStationStatsInfo.EquipmentStatsInfo.ConnectorStatsInfo> connectorStatsInfoList = new ArrayList<>(); List<SupStationStatsVO> orderBasicInfos;
try {
// 根据站点id查询订单记录 (新建Service方法) orderBasicInfos = orderBasicInfoService.queryOrderListByStationIdAndTime(stationId, startTime, endTime);
List<SupStationStatsVO> orderVOS = orderBasicInfoService.queryOrderListByStationId(stationId); if (CollectionUtils.isEmpty(orderBasicInfos)) {
// 根据订单信息汇总出站点充电数据 log.info("站点{}没有查询到前一日的订单信息", stationId);
BigDecimal stationTotalElectricity = BigDecimal.ZERO; // 充电站累计用电量 return null;
int stationChargeTime = Constants.zero; // 充电站累计充电次数 }
for (SupStationStatsVO orderVO : orderVOS) { } catch (Exception e) {
// 充电站累计用电量 log.error("查询站点{}订单信息失败", stationId, e);
BigDecimal totalPower = (orderVO.getTotalPower() != null) ? orderVO.getTotalPower() : BigDecimal.ZERO; return "查询订单失败: " + e.getMessage();
int chargingTime = (orderVO.getChargingTime() != null) ? orderVO.getChargingTime() : Constants.zero;
stationTotalElectricity = stationTotalElectricity.add(totalPower);
// 充电站累计充电时长(分钟)
stationChargeTime += chargingTime;
} }
// 根据枪口排序,分组,将充电时长和充电量累加 // 3. 统计站点充电数据
Map<String, SupStationStatsVO> collect = orderVOS.stream() BigDecimal stationTotalElectricity = BigDecimal.ZERO;
.sorted(Comparator.comparing(SupStationStatsVO::getPileConnectorCode)) int stationTotalChargeTime = 0;
.filter(vo -> vo.getChargingTime() != null && vo.getTotalPower() != null) String startChargeTime = null;
.collect(Collectors.toMap(SupStationStatsVO::getPileConnectorCode, Function.identity(), String endChargeTime = null;
(a, b) -> {
a.setChargingTime(a.getChargingTime() + b.getChargingTime());
a.setTotalPower(a.getTotalPower().add(b.getTotalPower()));
return a;
}));
TreeMap<String, SupStationStatsVO> sortedMap = new TreeMap<>(collect);
for (SupStationStatsVO orderVO : orderBasicInfos) {
// 处理用电量
BigDecimal power = orderVO.getTotalPower();
if (power != null) {
stationTotalElectricity = stationTotalElectricity.add(power);
}
// 处理充电时长
String start = orderVO.getStartTime();
String end = orderVO.getEndTime();
if (start != null && end != null) {
try {
long chargeTime = DateUtils.intervalTime(start, end);
stationTotalChargeTime += (int) chargeTime;
// 更新统计开始和结束时间
if (startChargeTime == null || start.compareTo(startChargeTime) < 0) {
startChargeTime = start;
}
if (endChargeTime == null || end.compareTo(endChargeTime) > 0) {
endChargeTime = end;
}
} catch (Exception e) {
log.error("计算订单{}充电时长失败", orderVO.getOrderCode(), e);
}
}
}
// 如果未获取到统计开始或结束时间,使用默认值
if (startChargeTime == null) {
startChargeTime = startTime;
log.warn("站点{}未获取到有效订单开始时间,使用默认开始时间: {}", stationId, startTime);
}
if (endChargeTime == null) {
endChargeTime = endTime;
log.warn("站点{}未获取到有效订单结束时间,使用默认结束时间: {}", stationId, endTime);
}
// 4. 按枪口排序,分组,将充电时长和充电量累加
Map<String, List<SupStationStatsVO>> collect = orderBasicInfos.stream()
.filter(vo -> vo.getChargingTime() != null)
.collect(Collectors.groupingBy(SupStationStatsVO::getPileConnectorCode));
TreeMap<String, List<SupStationStatsVO>> sortedMap = new TreeMap<>(collect);
List<SupStationStatsInfo.EquipmentStatsInfo> equipmentStatsInfoList = new ArrayList<>();
// 初始化相关数据 // 初始化相关数据
String pileSn = ""; String pileSn = "";
BigDecimal pileTotalPower = BigDecimal.ZERO; BigDecimal pileTotalPower = BigDecimal.ZERO;
int pileChargeTime = Constants.zero; int pileChargeTime = 0;
// key : pileConnectorCode
// value: SupStationStatsVO for (Map.Entry<String, List<SupStationStatsVO>> entry : sortedMap.entrySet()) {
for (Map.Entry<String, SupStationStatsVO> entry : sortedMap.entrySet()) {
String pileConnectorCode = entry.getKey(); String pileConnectorCode = entry.getKey();
SupStationStatsVO vo = entry.getValue(); List<SupStationStatsVO> voList = entry.getValue();
connectorStatsInfo = new SupStationStatsInfo.EquipmentStatsInfo.ConnectorStatsInfo(); SupStationStatsInfo.EquipmentStatsInfo.ConnectorStatsInfo connectorStatsInfo = null;
List<SupStationStatsInfo.EquipmentStatsInfo.ConnectorStatsInfo> connectorStatsInfoList = new ArrayList<>();
// 先封装枪口数据 for (SupStationStatsVO vo : voList) {
connectorStatsInfo.setConnectorId(pileConnectorCode); connectorStatsInfo = new SupStationStatsInfo.EquipmentStatsInfo.ConnectorStatsInfo();
connectorStatsInfo.setEquipmentClassification(1); // 先封装枪口数据
connectorStatsInfo.setConnectorElectricity(((vo.getTotalPower() != null) ? vo.getTotalPower() : BigDecimal.ZERO).setScale(4, RoundingMode.HALF_UP)); connectorStatsInfo.setConnectorId(pileConnectorCode);
connectorStatsInfo.setConnectorTotalChargeTime((vo.getChargingTime() != null) ? vo.getChargingTime() : Constants.zero); connectorStatsInfo.setEquipmentClassification(1);
connectorStatsInfo.setConnectorTotalChargeNum(orderVOS.size());
connectorStatsInfo.setConnectorTotalWarningNum(0);
// 对比这次循环到的桩编号和上次的桩编号如果是同一台桩将数据进行汇总如果不是新建桩数据并将之前的累计数据清0 BigDecimal power = vo.getTotalPower();
String newPileSn = vo.getPileSn(); if (power != null) {
if (!StringUtils.equals(pileSn, newPileSn)) { connectorStatsInfo.setConnectorElectricity(power.setScale(4, RoundingMode.HALF_UP));
pileSn = newPileSn; }
pileTotalPower = BigDecimal.ZERO;
pileChargeTime = Constants.zero;
equipmentStatsInfo = new SupStationStatsInfo.EquipmentStatsInfo(); String newPileSn = vo.getPileSn();
connectorStatsInfoList = new ArrayList<>(); 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);
}
pileSn = newPileSn;
pileTotalPower = BigDecimal.ZERO;
pileChargeTime = 0;
connectorStatsInfoList = new ArrayList<>();
}
Integer chargingTime = vo.getChargingTime();
if (chargingTime != null) {
pileChargeTime += chargingTime;
}
power = vo.getTotalPower();
if (power != null) {
pileTotalPower = pileTotalPower.add(power);
}
connectorStatsInfo.setConnectorTotalChargeTime(chargingTime != null? chargingTime : 0);
connectorStatsInfo.setConnectorTotalChargeNum(voList.size());
connectorStatsInfo.setConnectorTotalWarningNum(0);
connectorStatsInfoList.add(connectorStatsInfo);
}
if (!pileSn.isEmpty()) {
SupStationStatsInfo.EquipmentStatsInfo equipmentStatsInfo = new SupStationStatsInfo.EquipmentStatsInfo();
equipmentStatsInfo.setEquipmentId(pileSn); equipmentStatsInfo.setEquipmentId(pileSn);
equipmentStatsInfo.setEquipmentClassification(1); equipmentStatsInfo.setEquipmentClassification(1);
equipmentStatsInfo.setEquipmentElectricity(((vo.getTotalPower() != null) ? vo.getTotalPower() : BigDecimal.ZERO).setScale(4, RoundingMode.HALF_UP)); equipmentStatsInfo.setEquipmentElectricity(pileTotalPower.setScale(4, RoundingMode.HALF_UP));
equipmentStatsInfo.setEquipmentTotalChargeTime((vo.getChargingTime() != null) ? vo.getChargingTime() : Constants.zero); equipmentStatsInfo.setEquipmentTotalChargeTime(pileChargeTime);
equipmentStatsInfo.setEquipmentTotalChargeNum(orderVOS.size()); equipmentStatsInfo.setEquipmentTotalChargeNum(voList.size());
equipmentStatsInfo.setEquipmentTotalWarningNum(0); equipmentStatsInfo.setEquipmentTotalWarningNum(0);
pileTotalPower = pileTotalPower.add((vo.getTotalPower() != null) ? vo.getTotalPower() : BigDecimal.ZERO);
pileChargeTime += (vo.getChargingTime() != null) ? vo.getChargingTime() : Constants.zero;
connectorStatsInfoList.add(connectorStatsInfo);
equipmentStatsInfo.setConnectorStatsInfos(connectorStatsInfoList); equipmentStatsInfo.setConnectorStatsInfos(connectorStatsInfoList);
equipmentStatsInfo.setSupconnectorStatsInfos(connectorStatsInfoList); equipmentStatsInfo.setSupconnectorStatsInfos(connectorStatsInfoList);
equipmentStatsInfoList.add(equipmentStatsInfo); equipmentStatsInfoList.add(equipmentStatsInfo);
} else {
// 同一台桩,枪口号不同,累加桩数据,将枪口数据新建
pileTotalPower = pileTotalPower.add((vo.getTotalPower() != null) ? vo.getTotalPower() : BigDecimal.ZERO);
pileChargeTime += (vo.getChargingTime() != null) ? vo.getChargingTime() : Constants.zero;
equipmentStatsInfo.setEquipmentElectricity(pileTotalPower); // 第一次判断时一定不会进入到这里,所以不用判断 equipmentStatsInfo 是否为 null
equipmentStatsInfo.setEquipmentTotalChargeTime(pileChargeTime);
connectorStatsInfoList.add(connectorStatsInfo);
equipmentStatsInfo.setConnectorStatsInfos(connectorStatsInfoList);
equipmentStatsInfoList.add(equipmentStatsInfo);
} }
} }
PileStationVO stationInfo = pileStationInfoService.getStationInfo(stationId); // 5. 获取站点和商户信息
PileMerchantInfoVO pileMerchantInfoVO = pileMerchantInfoService.queryMerchantInfoByStationId(String.valueOf(stationInfo.getId())); PileStationVO stationInfo;
String organizationCode = pileMerchantInfoVO.getOrganizationCode(); PileMerchantInfoVO pileMerchantInfoVO;
try {
stationInfo = pileStationInfoService.getStationInfo(stationId);
pileMerchantInfoVO = pileMerchantInfoService.queryMerchantInfoByStationId(String.valueOf(stationInfo.getId()));
} catch (Exception e) {
log.error("查询站点{}或商户信息失败", stationId, e);
return "查询站点/商户信息失败: " + e.getMessage();
}
// 创建对象 // 6. 构建请求对象
String startTime = DateUtils.getYesterdayStr();
String endTime = DateUtils.getYesterdayStr();
SupStationStatsInfo supStationStatsInfo = SupStationStatsInfo.builder() SupStationStatsInfo supStationStatsInfo = SupStationStatsInfo.builder()
.stationId(stationId) .stationId(stationId)
.operatorId(Constants.OPERATORID_JIANG_SU) .operatorId(Constants.OPERATORID_JIANG_SU)
.equipmentOwnerId(ThirdPartyPlatformUtils.extractEquipmentOwnerID(organizationCode)) .equipmentOwnerId("999999999")
.stationClassification(1) .stationClassification(1)
.startTime(startTime) .startTime(startChargeTime)
.endTime(endTime) .endTime(endChargeTime)
.stationElectricity(stationTotalElectricity) .stationElectricity(stationTotalElectricity)
.stationTotalChargeEnergy(stationTotalElectricity) .stationTotalChargeEnergy(stationTotalElectricity)
.stationTotalOtherEnergy(new BigDecimal(Constants.zero).setScale(4, RoundingMode.HALF_UP)) //累计其它电量 .stationTotalOtherEnergy(new BigDecimal(0).setScale(4, RoundingMode.HALF_UP))
.stationTotalSwapChargeNum(Constants.zero) .stationTotalSwapChargeNum(0)
.stationTotalChargeNum(orderVOS.size()) .stationTotalChargeNum(orderBasicInfos.size())
.stationTotalChargeTime(stationChargeTime) .stationTotalChargeTime(stationTotalChargeTime)
.stationTotalSwapTime(Constants.zero) .stationTotalSwapTime(0)
.stationTotalWarningNum(0) .stationTotalWarningNum(0)
.equipmentStatsInfos(equipmentStatsInfoList) .equipmentStatsInfos(equipmentStatsInfoList)
.supEquipmentStatsInfos(equipmentStatsInfoList) .supEquipmentStatsInfos(equipmentStatsInfoList)
.build(); .build();
// 7. 构建请求JSON
JSONObject json = new JSONObject(); JSONObject json = new JSONObject();
List<SupStationStatsInfo> supStationStatsInfoList = new ArrayList<>(); json.put("StationStatsInfos", Collections.singletonList(supStationStatsInfo));
supStationStatsInfoList.add(supStationStatsInfo);
json.put("StationStatsInfos", supStationStatsInfoList);
String jsonString = JSON.toJSONString(json); String jsonString = JSON.toJSONString(json);
// 发送推送请求 // 8. 发送推送请求
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getSiChuanSecretInfo(); ThirdPartySecretInfoVO thirdPartySecretInfoVO = getSiChuanSecretInfo();
String operatorId = Constants.OPERATORID_JIANG_SU; String operatorId = Constants.OPERATORID_JIANG_SU;
String operatorSecret = thirdPartySecretInfoVO.getTheirOperatorSecret(); String operatorSecret = thirdPartySecretInfoVO.getTheirOperatorSecret();
String signSecret = thirdPartySecretInfoVO.getTheirSigSecret(); String signSecret = thirdPartySecretInfoVO.getTheirSigSecret();
String dataSecret = thirdPartySecretInfoVO.getTheirDataSecret(); String dataSecret = thirdPartySecretInfoVO.getTheirDataSecret();
@@ -980,11 +1029,7 @@ public class SiChuanPlatformServiceImpl implements ThirdPartyPlatformService {
supStationPowerInfo.setOperatorId(Constants.OPERATORID_JIANG_SU); supStationPowerInfo.setOperatorId(Constants.OPERATORID_JIANG_SU);
// 查询运营商基本信息 // 查询运营商基本信息
PileMerchantInfoVO pileMerchantInfoVO = pileMerchantInfoService.queryMerchantInfoByStationId(stationId); supStationPowerInfo.setEquipmentOwnerID("999999999");
String organizationCode = pileMerchantInfoVO.getOrganizationCode();
if (StringUtils.isNotBlank(organizationCode) && organizationCode.length() == 18) {
supStationPowerInfo.setEquipmentOwnerID(ThirdPartyPlatformUtils.extractEquipmentOwnerID(organizationCode));
}
supStationPowerInfo.setStationId(stationId); supStationPowerInfo.setStationId(stationId);
supStationPowerInfo.setStationClassification(Constants.one); supStationPowerInfo.setStationClassification(Constants.one);
supStationPowerInfo.setDataTime(dateTimeNow); supStationPowerInfo.setDataTime(dateTimeNow);
@@ -1102,40 +1147,33 @@ public class SiChuanPlatformServiceImpl implements ThirdPartyPlatformService {
* @return * @return
*/ */
private ChargeOrderInfo transformChargeOrderInfo(OrderBasicInfo orderBasicInfo , OrderDetail orderDetail) { private ChargeOrderInfo transformChargeOrderInfo(OrderBasicInfo orderBasicInfo , OrderDetail orderDetail) {
PileStationVO stationInfo = pileStationInfoService.getStationInfo(orderBasicInfo.getStationId()); //空指针
PileMerchantInfoVO pileMerchantInfoVO = pileMerchantInfoService.queryMerchantInfoByStationId(String.valueOf(stationInfo.getId())); String chargeStartTime = orderBasicInfo.getChargeStartTime() == null ? "" : DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS , orderBasicInfo.getChargeStartTime());
String organizationCode = pileMerchantInfoVO.getOrganizationCode(); String chargeEndTime = orderBasicInfo.getChargeEndTime() == null ? "" : DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, orderBasicInfo.getChargeEndTime());
BigDecimal totalPower = orderDetail.getTotalElectricityAmount() == null ? BigDecimal.ZERO : orderDetail.getTotalElectricityAmount();
BigDecimal totalMoney = orderDetail.getTotalOrderAmount() == null ? BigDecimal.ZERO : orderDetail.getTotalOrderAmount();
BigDecimal totalServiceMoney = orderDetail.getTotalServiceAmount() == null ? BigDecimal.ZERO : orderDetail.getTotalServiceAmount();
BigDecimal totalElecMoney = orderDetail.getTotalElectricityAmount() == null ? BigDecimal.ZERO : orderDetail.getTotalElectricityAmount();
String reason = orderBasicInfo.getReason() == null ? "" : orderBasicInfo.getReason();
ChargeOrderInfo chargeOrderInfo = ChargeOrderInfo.builder() ChargeOrderInfo chargeOrderInfo = ChargeOrderInfo.builder()
.operatorID(Constants.OPERATORID_JIANG_SU) .operatorID(Constants.OPERATORID_JIANG_SU)
.equipmentOwnerID(ThirdPartyPlatformUtils.extractEquipmentOwnerID(organizationCode)) .equipmentOwnerID("999999999") //表示为个人
.stationID(orderBasicInfo.getStationId()) .stationID(orderBasicInfo.getStationId())
.equipmentID(orderBasicInfo.getPileSn()) .equipmentID(orderBasicInfo.getPileSn())
.orderNo(orderBasicInfo.getOrderCode()) .orderNo(orderBasicInfo.getOrderCode())
.connectorID(orderBasicInfo.getPileConnectorCode()) .connectorID(orderBasicInfo.getPileConnectorCode())
.equipmentClassification(1) .equipmentClassification(1)
.startTime(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, orderBasicInfo.getChargeStartTime())) .startTime(chargeStartTime)
.endTime(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, orderBasicInfo.getChargeEndTime())) .endTime(chargeEndTime)
.totalPower(orderDetail.getTotalUsedElectricity().setScale(4, RoundingMode.HALF_UP)) .totalPower(totalPower.setScale(4, RoundingMode.HALF_UP))
.pushTimeStamp(DateUtils.getDateTime()) .pushTimeStamp(DateUtils.getDateTime())
.totalElecMoney(orderDetail.getTotalElectricityAmount().setScale(4, RoundingMode.HALF_UP)) .totalElecMoney(totalElecMoney.setScale(4, RoundingMode.HALF_UP))
.totalServiceMoney(orderDetail.getTotalServiceAmount().setScale(4, RoundingMode.HALF_UP)) .totalServiceMoney(totalServiceMoney.setScale(4, RoundingMode.HALF_UP))
.totalMoney(orderDetail.getTotalOrderAmount()) .totalMoney(totalMoney.setScale(4, RoundingMode.HALF_UP))
.stopReason(2) .stopReason(2)
.stopDesc(orderBasicInfo.getReason()) .stopDesc(reason)
.build(); .build();
if (orderBasicInfo.getPlateNumber() != null) {
chargeOrderInfo.setLicensePlate(orderBasicInfo.getPlateNumber());
}
if (orderBasicInfo.getVinCode() != null) {
chargeOrderInfo.setVin(orderBasicInfo.getVinCode());
}
if (orderBasicInfo.getStartSoc() != null) {
chargeOrderInfo.setStartSOC(orderBasicInfo.getStartSoc());
}
if (orderBasicInfo.getEndSoc() != null) {
chargeOrderInfo.setEndSOC(orderBasicInfo.getEndSoc());
}
return chargeOrderInfo; return chargeOrderInfo;
} }
@@ -1175,19 +1213,6 @@ public class SiChuanPlatformServiceImpl implements ThirdPartyPlatformService {
} }
equipmentInfo.setEquipmentType(Integer.valueOf(pileDetailInfoVO.getSpeedType())); equipmentInfo.setEquipmentType(Integer.valueOf(pileDetailInfoVO.getSpeedType()));
equipmentInfo.setEquipmentPower(new BigDecimal(pileDetailInfoVO.getRatedPower()).setScale(1, BigDecimal.ROUND_HALF_UP)); equipmentInfo.setEquipmentPower(new BigDecimal(pileDetailInfoVO.getRatedPower()).setScale(1, BigDecimal.ROUND_HALF_UP));
String pileStatus = pileDetailInfoVO.getPileStatus();
if (StringUtils.equals(PileStatusEnum.ON_LINE.getValue(), pileStatus)) {
// 1-在线
pileStatus = LianLianPileStatusEnum.NORMAL.getCode();
} else if (StringUtils.equals(PileStatusEnum.OFF_LINE.getValue(), pileStatus)) {
// 2-离线
pileStatus = LianLianPileStatusEnum.CLOSE_OFFLINE.getCode();
} else if (StringUtils.equals(PileStatusEnum.FAULT.getValue(), pileStatus)) {
// 3-故障
pileStatus = LianLianPileStatusEnum.UNDER_MAINTENANCE.getCode();
}
equipmentInfo.setPower(new BigDecimal(pileDetailInfoVO.getRatedPower()).setScale(4, RoundingMode.HALF_UP)); equipmentInfo.setPower(new BigDecimal(pileDetailInfoVO.getRatedPower()).setScale(4, RoundingMode.HALF_UP));
// 枪口列表 // 枪口列表
@@ -1239,15 +1264,6 @@ public class SiChuanPlatformServiceImpl implements ThirdPartyPlatformService {
connectorInfo.setAuxPower(3); // 3-兼容12V和24V connectorInfo.setAuxPower(3); // 3-兼容12V和24V
connectorInfo.setOpreateStatus(50); // 50-正常使用 connectorInfo.setOpreateStatus(50); // 50-正常使用
/* if (!StringUtils.equals(pileDetailInfoVO.getConnectorNum(), "1")) {
// 如果不是单枪,则枪口功率需要除以枪口数量
String ratedPowerStr = pileDetailInfoVO.getRatedPower();
BigDecimal ratedPower = new BigDecimal(ratedPowerStr);
connectorInfo.setPower(ratedPower.divide(new BigDecimal(pileDetailInfoVO.getConnectorNum()), 1, BigDecimal.ROUND_HALF_UP));
}else {
connectorInfo.setPower(new BigDecimal(pileDetailInfoVO.getRatedPower()).setScale(1, BigDecimal.ROUND_HALF_UP));
}*/
resultList.add(connectorInfo); resultList.add(connectorInfo);
} }
return resultList; return resultList;