新增 宁夏平台 推送充换电站实时功率接口

This commit is contained in:
Lemon
2024-06-17 08:46:55 +08:00
parent 53d83bf1af
commit 4b288507cd
8 changed files with 415 additions and 3 deletions

View File

@@ -671,8 +671,10 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils {
// public static String date2HexStr(Date date) {
// return Cp56Time2aUtil.date2HexStr(date);
// }
public static void main(String[] args) {
String yesterdayStr = getYesterdayStr();
System.out.println(yesterdayStr);
}
/**
* 获取两个时间的间隔时间
*

View File

@@ -5,6 +5,7 @@ import com.jsowell.pile.domain.OrderDetail;
import com.jsowell.pile.dto.*;
import com.jsowell.pile.dto.nanrui.NRQueryOrderDTO;
import com.jsowell.pile.dto.ningxiajiaotou.NXJTQueryOrdersInfoDTO;
import com.jsowell.pile.vo.SupStationStatsVO;
import com.jsowell.pile.vo.base.MerchantOrderInfoVO;
import com.jsowell.pile.vo.lianlian.AccumulativeInfoVO;
import com.jsowell.pile.vo.nanrui.NROrderInfoVO;
@@ -358,4 +359,11 @@ public interface OrderBasicInfoMapper {
* @return
*/
OrderVO getChargeOrderInfoByOrderCode(String orderCode);
/**
* 通过站点id查询订单信息
* @param stationId
* @return
*/
List<SupStationStatsVO> queryOrderListByStationId(String stationId);
}

View File

@@ -12,6 +12,7 @@ import com.jsowell.pile.domain.SettleOrderReport;
import com.jsowell.pile.dto.*;
import com.jsowell.pile.dto.nanrui.NRQueryOrderDTO;
import com.jsowell.pile.dto.ningxiajiaotou.NXJTQueryOrdersInfoDTO;
import com.jsowell.pile.vo.SupStationStatsVO;
import com.jsowell.pile.vo.base.MerchantOrderInfoVO;
import com.jsowell.pile.vo.base.OrderAmountDetailVO;
import com.jsowell.pile.vo.base.OrderPeriodAmountVO;
@@ -445,4 +446,11 @@ public interface OrderBasicInfoService{
* @return
*/
OrderVO getChargeOrderInfoByOrderCode(String orderCode);
/**
* 通过站点id查询订单信息
* @param stationId
* @return
*/
List<SupStationStatsVO> queryOrderListByStationId(String stationId);
}

View File

@@ -50,6 +50,7 @@ import com.jsowell.pile.transaction.dto.ClearingBillTransactionDTO;
import com.jsowell.pile.transaction.dto.OrderTransactionDTO;
import com.jsowell.pile.transaction.service.TransactionService;
import com.jsowell.pile.util.UserUtils;
import com.jsowell.pile.vo.SupStationStatsVO;
import com.jsowell.pile.vo.base.PileInfoVO;
import com.jsowell.pile.vo.base.*;
import com.jsowell.pile.vo.lianlian.AccumulativeInfoVO;
@@ -3697,5 +3698,20 @@ public class OrderBasicInfoServiceImpl implements OrderBasicInfoService {
return orderBasicInfoMapper.queryXDTOrderList(merchantId, stationId, startDate, endDate);
}
/**
* 通过站点id查询订单信息
* @param stationId
* @return
*/
public List<SupStationStatsVO> queryOrderListByStationId(String stationId) {
List<SupStationStatsVO> orderVOS = orderBasicInfoMapper.queryOrderListByStationId(stationId);
for (SupStationStatsVO orderVO : orderVOS) {
// 计算每笔订单充电时长(分钟)
long intervalTime = DateUtils.intervalTime(orderVO.getStartTime(), orderVO.getEndTime());
orderVO.setChargingTime(Integer.parseInt(String.valueOf(intervalTime)));
}
return orderVOS;
}
}

View File

@@ -0,0 +1,30 @@
package com.jsowell.pile.vo;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.math.BigDecimal;
/**
* TODO
*
* @author Lemon
* @Date 2024/6/15 15:41:41
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class SupStationStatsVO {
private String orderCode;
private String organizationCode;
private String stationId;
private String pileSn;
private String pileConnectorCode;
private String StartTime;
private String EndTime;
private BigDecimal totalPower;
private Integer chargingTime;
}

View File

@@ -2882,4 +2882,25 @@
and order_status = '0'
and order_basic_info.reserved_start_time <![CDATA[ <= ]]> #{dateTime,jdbcType=TIMESTAMP}
</select>
<select id="queryOrderListByStationId" 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.charge_start_time <![CDATA[ >= ]]> DATE_SUB( CURDATE(), INTERVAL 1 DAY )
AND t1.charge_start_time <![CDATA[ < ]]> CURDATE()
</select>
</mapper>

View File

@@ -0,0 +1,200 @@
package com.jsowell.thirdparty.platform.domain;
import com.alibaba.fastjson2.annotation.JSONField;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.math.BigDecimal;
import java.util.List;
/**
* 充换电站用能统计信息
*
* @author Lemon
* @Date 2024/6/12 15:14:07
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class SupStationStatsInfo {
@JSONField(name = "StationID")
private String stationId;
@JSONField(name = "OperatorID")
private String operatorId;
@JSONField(name = "EquipmentOwnerID")
private String equipmentOwnerId;
/**
* 站点分类
* 1充电站
* 2换电站
* 3充换电一体站
*/
@JSONField(name = "StationClassification")
private Integer stationClassification;
/**
* 统计开始时间
*/
@JSONField(name = "StartTime")
private String startTime;
/**
* 统计结束时间
*/
@JSONField(name = "EndTime")
private String endTime;
/**
* 充换电站累计用电量
*/
@JSONField(name = "StationElectricity")
private BigDecimal stationElectricity;
/**
* 充换电站累计充电量
*/
@JSONField(name = "StationTotalChargeEnergy")
private BigDecimal stationTotalChargeEnergy;
/**
* 充换电站累计其他电量
*/
@JSONField(name = "StationTotalOtherEnergy")
private BigDecimal stationTotalOtherEnergy;
/**
* 充换电站累计换电次数
*/
@JSONField(name = "StationTotalSwapChargeNum")
private Integer stationTotalSwapChargeNum;
/**
* 充换电站累计充电次数
*/
@JSONField(name = "StationTotalChargeNum")
private Integer stationTotalChargeNum;
/**
* 充换电站累计充电时长
*/
@JSONField(name = "StationTotalChargeTime")
private Integer stationTotalChargeTime;
/**
* 充换电站累计换电时长
*/
@JSONField(name = "StationTotalSwapTime")
private Integer stationTotalSwapTime;
/**
* 充换电站累计告警数量
*/
@JSONField(name = "StationTotalWarningNum")
private Integer stationTotalWarningNum;
/**
* 充电设备运行统计信息列表
*/
@JSONField(name = "EquipmentStatsInfos")
private List<EquipmentStatsInfo> equipmentStatsInfos;
@Data
public static class EquipmentStatsInfo{
/**
* 充电设备编码
*/
@JSONField(name = "EquipmentID")
private String equipmentId;
/**
* 设备分类
* 1车辆充电设备
* 2换电站内的电池箱充电设备
*/
@JSONField(name = "EquipmentClassification")
private Integer equipmentClassification;
/**
* 充电设备累计电量
*/
@JSONField(name = "EquipmentElectricity")
private BigDecimal equipmentElectricity;
/**
* 充电设备累计充电时长
*/
@JSONField(name = "EquipmentTotalChargeTime")
private Integer equipmentTotalChargeTime;
/**
* 充电设备累计充电次数
*/
@JSONField(name = "EquipmentTotalChargeNum")
private Integer equipmentTotalChargeNum;
/**
* 充电设备累计告警数量
*/
@JSONField(name = "EquipmentTotalWarningNum")
private Integer equipmentTotalWarningNum;
/**
* 充电设备接口运行统计信息列表
*/
@JSONField(name = "ConnectorStatsInfos")
private List<ConnectorStatsInfo> connectorStatsInfos;
@Data
public static class ConnectorStatsInfo{
/**
* 充电设备接口编码
* 1车辆充电设备
* 2换电站内的电池箱充电设备
*/
@JSONField(name = "ConnectorID")
private String connectorId;
/**
* 设备分类
*/
@JSONField(name = "EquipmentClassification")
private Integer equipmentClassification;
/**
* 充电设备接口累计电量
*/
@JSONField(name = "ConnectorElectricity")
private BigDecimal connectorElectricity;
/**
* 充电设备接口累计充电时长
*/
@JSONField(name = "ConnectorTotalChargeTime")
private Integer connectorTotalChargeTime;
/**
* 充电设备接口累计充电次数
*/
@JSONField(name = "ConnectorTotalChargeNum")
private Integer connectorTotalChargeNum;
/**
* 充电设备接口累计告警数量
*/
@JSONField(name = "ConnectorTotalWarningNum")
private Integer connectorTotalWarningNum;
}
}
}

View File

@@ -28,11 +28,13 @@ 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;
import com.jsowell.pile.vo.base.ThirdPartyStationInfoVO;
import com.jsowell.pile.vo.uniapp.BillingPriceVO;
import com.jsowell.pile.vo.uniapp.OrderVO;
import com.jsowell.pile.vo.web.PileConnectorInfoVO;
import com.jsowell.thirdparty.lianlian.domain.ConnectorChargeStatusInfo;
import com.jsowell.thirdparty.lianlian.domain.ConnectorStatusInfo;
@@ -51,7 +53,9 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
@Service
@@ -653,7 +657,130 @@ public class NinaXiaPlatformServiceImpl implements ThirdPartyPlatformService {
*/
@Override
public String notificationOperationStatsInfo(String stationId) {
return ThirdPartyPlatformService.super.notificationOperationStatsInfo(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();
stationTotalElectricity = stationTotalElectricity.add(totalPower);
// 充电站累计充电时长(分钟)
stationChargeTime+= orderVO.getChargingTime();
}
// 根据枪口排序,分组,将充电时长和充电量累加
Map<String, SupStationStatsVO> collect = orderVOS.stream()
.sorted(Comparator.comparing(SupStationStatsVO::getPileConnectorCode))
.collect(Collectors.toMap(SupStationStatsVO::getPileConnectorCode, Function.identity(),
(a, b) -> {
a.setChargingTime(a.getChargingTime() + b.getChargingTime());
a.setTotalPower(a.getTotalPower().add(b.getTotalPower()));
return a;
}));
// 初始化相关数据
String pileSn = "";
BigDecimal pileTotalPower = BigDecimal.ZERO;
int pileChargeTime = Constants.zero;
for (Map.Entry<String, SupStationStatsVO> entry: collect.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();
equipmentStatsInfo.setEquipmentId(newPileSn);
equipmentStatsInfo.setEquipmentClassification(1);
equipmentStatsInfo.setEquipmentElectricity(vo.getTotalPower());
equipmentStatsInfo.setEquipmentTotalChargeTime(vo.getChargingTime());
// TODO equipmentStatsInfo.setEquipmentTotalChargeNum();
pileTotalPower = pileTotalPower.add(vo.getTotalPower());
pileChargeTime += vo.getChargingTime();
}else {
// 同一台桩,累加数据
pileTotalPower = pileTotalPower.add(vo.getTotalPower());
pileChargeTime += vo.getChargingTime();
equipmentStatsInfo.setEquipmentElectricity(pileTotalPower); // 第一次判断时一定不会进入到这里,所以不用判断 equipmentStatsInfo 是否为 null
equipmentStatsInfo.setEquipmentTotalChargeTime(pileChargeTime);
}
equipmentStatsInfoList.add(equipmentStatsInfo);
connectorStatsInfoList.add(connectorStatsInfo);
}
equipmentStatsInfo.setConnectorStatsInfos(connectorStatsInfoList);
// 创建对象
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();
// 发送推送请求
ThirdPartySecretInfoVO ningXiaSecretInfo = getNingXiaPlatformSecretInfo();
String operatorId = ningXiaSecretInfo.getOurOperatorId();
String operatorSecret = ningXiaSecretInfo.getTheirOperatorSecret();
String signSecret = ningXiaSecretInfo.getTheirSigSecret();
String dataSecret = ningXiaSecretInfo.getTheirDataSecret();
String dataSecretIv = ningXiaSecretInfo.getTheirDataSecretIv();
String urlAddress = ningXiaSecretInfo.getTheirUrlPrefix();
String url = urlAddress + "supervise_notification_operation_stats_info";
// 获取令牌
String token = getToken(urlAddress, operatorId, operatorSecret, dataSecretIv, signSecret, dataSecret);
if (StringUtils.isBlank(token)) {
return null;
}
// 调用平台接口
JSONObject json = new JSONObject();
json.put("StationStatsInfos", supStationStatsInfo);
String jsonString = JSON.toJSONString(json);
String result = HttpRequestUtil.sendPost(token, jsonString, url, dataSecret, dataSecretIv, operatorId, signSecret);
return result;
}
/**