mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-20 11:05:18 +08:00
update
This commit is contained in:
@@ -1,25 +1,46 @@
|
||||
package com.jsowell.thirdparty.hainan.service;
|
||||
|
||||
import cn.hutool.core.util.PageUtil;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.jsowell.common.constant.Constants;
|
||||
import com.jsowell.common.core.domain.ykc.RealTimeMonitorData;
|
||||
import com.jsowell.common.enums.thirdparty.ThirdPlatformTypeEnum;
|
||||
import com.jsowell.common.enums.ykc.PileConnectorDataBaseStatusEnum;
|
||||
import com.jsowell.common.util.DateUtils;
|
||||
import com.jsowell.common.util.PageUtils;
|
||||
import com.jsowell.common.util.StringUtils;
|
||||
import com.jsowell.pile.domain.OrderBasicInfo;
|
||||
import com.jsowell.pile.domain.OrderDetail;
|
||||
import com.jsowell.pile.domain.ThirdPartyPlatformConfig;
|
||||
import com.jsowell.pile.domain.ThirdPartyStationRelation;
|
||||
import com.jsowell.pile.dto.QueryStationInfoDTO;
|
||||
import com.jsowell.pile.vo.base.ConnectorInfoVO;
|
||||
import com.jsowell.pile.vo.base.ThirdPartyStationInfoVO;
|
||||
import com.jsowell.pile.vo.uniapp.BillingPriceVO;
|
||||
import com.jsowell.thirdparty.hainan.domain.HNStationInfo;
|
||||
import com.jsowell.pile.vo.base.ThirdPartyStationRelationVO;
|
||||
import com.jsowell.pile.vo.lianlian.AccumulativeInfoVO;
|
||||
import com.jsowell.pile.vo.web.PileStationVO;
|
||||
import com.jsowell.thirdparty.lianlian.domain.*;
|
||||
import com.jsowell.thirdparty.lianlian.util.Cryptos;
|
||||
import com.jsowell.thirdparty.lianlian.util.Encodes;
|
||||
import com.jsowell.thirdparty.lianlian.util.GBSignUtils;
|
||||
import com.jsowell.thirdparty.lianlian.util.HttpRequestUtil;
|
||||
import com.jsowell.thirdparty.platform.AbsInterfaceWithPlatformLogic;
|
||||
import com.jsowell.thirdparty.platform.InterfaceWithPlatformLogicFactory;
|
||||
import com.jsowell.thirdparty.zhongdianlian.domain.ZDLEquipmentInfo;
|
||||
import com.jsowell.thirdparty.zhongdianlian.domain.ZDLStationInfo;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* TODO
|
||||
@@ -38,7 +59,7 @@ public class HaiNanChargeService extends AbsInterfaceWithPlatformLogic {
|
||||
* 6.2 查询充电站信息
|
||||
*/
|
||||
public Map<String, String> queryStationsInfo(QueryStationInfoDTO dto) {
|
||||
List<HNStationInfo> resultList = new ArrayList<>();
|
||||
List<ZDLStationInfo> resultList = new ArrayList<>();
|
||||
int pageNo = dto.getPageNo() == null ? 1 : dto.getPageNo();
|
||||
int pageSize = dto.getPageSize() == null ? 10 : dto.getPageSize();
|
||||
|
||||
@@ -54,7 +75,7 @@ public class HaiNanChargeService extends AbsInterfaceWithPlatformLogic {
|
||||
}
|
||||
PageInfo<ThirdPartyStationInfoVO> pageInfo = new PageInfo<>(stationInfos);
|
||||
for (ThirdPartyStationInfoVO pileStationInfo : pageInfo.getList()) {
|
||||
HNStationInfo stationInfo = new HNStationInfo();
|
||||
ZDLStationInfo stationInfo = new ZDLStationInfo();
|
||||
stationInfo.setStationId(String.valueOf(pileStationInfo.getId()));
|
||||
stationInfo.setOperatorId(Constants.OPERATORID_JIANG_SU); // 组织机构代码
|
||||
String organizationCode = pileStationInfo.getOrganizationCode();
|
||||
@@ -88,29 +109,31 @@ public class HaiNanChargeService extends AbsInterfaceWithPlatformLogic {
|
||||
if (StringUtils.isNotBlank(pileStationInfo.getPictures())) {
|
||||
stationInfo.setPictures(Lists.newArrayList(pileStationInfo.getPictures().split(",")));
|
||||
}
|
||||
// 查询计费模板详情
|
||||
List<BillingPriceVO> billingPriceVOList = pileBillingTemplateService.queryBillingPrice(String.valueOf(pileStationInfo.getId()));
|
||||
if (CollectionUtils.isEmpty(billingPriceVOList)) {
|
||||
return null;
|
||||
|
||||
List<ZDLEquipmentInfo> pileList = getPileList(pileStationInfo);
|
||||
if (CollectionUtils.isNotEmpty(pileList)) {
|
||||
stationInfo.setEquipmentInfos(pileList); // 充电设备信息列表
|
||||
}
|
||||
for (BillingPriceVO billingPriceVO : billingPriceVOList) {
|
||||
|
||||
}
|
||||
|
||||
// 电费描述
|
||||
// 服务费描述
|
||||
|
||||
// TODO 获取桩列表
|
||||
// List<ZDLEquipmentInfo> pileList = getPileList(pileStationInfo);
|
||||
// if (CollectionUtils.isNotEmpty(pileList)) {
|
||||
// stationInfo.setEquipmentInfos(pileList); // 充电设备信息列表
|
||||
// }
|
||||
|
||||
resultList.add(stationInfo);
|
||||
}
|
||||
Map<String, Object> map = new LinkedHashMap<>();
|
||||
map.put("PageNo", pageInfo.getPageNum());
|
||||
map.put("PageCount", pageInfo.getPages());
|
||||
map.put("ItemSize", resultList.size());
|
||||
map.put("StationInfos", resultList);
|
||||
|
||||
// 加密
|
||||
Map<String, String> resultMap = Maps.newLinkedHashMap();
|
||||
// 加密数据
|
||||
byte[] encryptText = Cryptos.aesEncrypt(JSONObject.toJSONString(map).getBytes(),
|
||||
configInfo.getDataSecret().getBytes(), configInfo.getDataSecretIv().getBytes());
|
||||
String encryptData = Encodes.encodeBase64(encryptText);
|
||||
|
||||
return null;
|
||||
resultMap.put("Data", encryptData);
|
||||
// 生成sig
|
||||
String resultSign = GBSignUtils.sign(resultMap, configInfo.getSignSecret());
|
||||
resultMap.put("Sig", resultSign);
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -121,7 +144,33 @@ public class HaiNanChargeService extends AbsInterfaceWithPlatformLogic {
|
||||
*/
|
||||
@Override
|
||||
public String notificationStationStatus(String pileConnectorCode, String status) {
|
||||
return null;
|
||||
// 查出该桩所属哪个站点
|
||||
PileStationVO stationVO = pileStationInfoService.getStationInfoByPileConnectorCode(pileConnectorCode);
|
||||
// 通过站点id查询相关配置信息
|
||||
ThirdPartyStationRelationVO relationInfo = thirdPartyStationRelationService.selectRelationInfo(stationVO.getId());
|
||||
if (relationInfo == null) {
|
||||
return null;
|
||||
}
|
||||
String operatorId = relationInfo.getOperatorId();
|
||||
String operatorSecret = relationInfo.getOperatorSecret();
|
||||
String signSecret = relationInfo.getSignSecret();
|
||||
String dataSecret = relationInfo.getDataSecret();
|
||||
String dataSecretIv = relationInfo.getDataSecretIv();
|
||||
String urlAddress = relationInfo.getUrlAddress();
|
||||
|
||||
String url = urlAddress + "notification_stationStatus";
|
||||
ConnectorStatusInfo info = ConnectorStatusInfo.builder()
|
||||
.connectorID(pileConnectorCode)
|
||||
.status(Integer.parseInt(status))
|
||||
.build();
|
||||
// 调用联联平台接口
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("ConnectorStatusInfo", info);
|
||||
String jsonString = JSONObject.toJSONString(json);
|
||||
// 获取令牌
|
||||
String token = getToken(urlAddress, operatorId, operatorSecret, dataSecretIv, signSecret, dataSecret);
|
||||
String result = HttpRequestUtil.sendPost(token, jsonString, url, dataSecret, dataSecretIv, operatorId, signSecret);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -131,7 +180,45 @@ public class HaiNanChargeService extends AbsInterfaceWithPlatformLogic {
|
||||
*/
|
||||
@Override
|
||||
public String pushChargeOrderInfo(String orderCode) {
|
||||
return null;
|
||||
// 获取数据
|
||||
OrderBasicInfo orderBasicInfo = orderBasicInfoService.getOrderInfoByOrderCode(orderCode);
|
||||
OrderDetail orderDetail = orderBasicInfoService.getOrderDetailByOrderCode(orderCode);
|
||||
|
||||
// 通过站点id查询相关配置信息
|
||||
ThirdPartyStationRelation relation = new ThirdPartyStationRelation();
|
||||
relation.setStationId(Long.parseLong(orderBasicInfo.getStationId()));
|
||||
ThirdPartyStationRelationVO relationInfo = thirdPartyStationRelationService.selectRelationInfo(relation);
|
||||
if (relationInfo == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 向三方平台推送
|
||||
String operatorId = relationInfo.getOperatorId();
|
||||
String operatorSecret = relationInfo.getOperatorSecret();
|
||||
String signSecret = relationInfo.getSignSecret();
|
||||
String dataSecret = relationInfo.getDataSecret();
|
||||
String dataSecretIv = relationInfo.getDataSecretIv();
|
||||
String urlAddress = relationInfo.getUrlAddress();
|
||||
String thirdPartyType = relationInfo.getThirdPartyType();
|
||||
|
||||
String url = urlAddress + "notification_charge_order_info";
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("StartChargeSeq", orderCode);
|
||||
json.put("ConnectorID", orderBasicInfo.getPileConnectorCode());
|
||||
json.put("StartTime", DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, orderBasicInfo.getChargeStartTime()));
|
||||
json.put("EndTime", DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, orderBasicInfo.getChargeEndTime()));
|
||||
json.put("TotalPower", orderDetail.getTotalUsedElectricity().setScale(2, RoundingMode.HALF_UP));
|
||||
json.put("TotalElecMoney", orderDetail.getTotalElectricityAmount().setScale(2, RoundingMode.HALF_UP));
|
||||
json.put("TotalSeviceMoney", orderDetail.getTotalServiceAmount().setScale(2, RoundingMode.HALF_UP));
|
||||
json.put("TotalMoney", orderDetail.getTotalOrderAmount().setScale(2, RoundingMode.HALF_UP));
|
||||
json.put("StopReason", 2); // 2:BMS 停止充电
|
||||
|
||||
String jsonString = JSONObject.toJSONString(json);
|
||||
|
||||
// 获取令牌
|
||||
String token = getToken(urlAddress, operatorId, operatorSecret, dataSecretIv, signSecret, dataSecret);
|
||||
String result = HttpRequestUtil.sendPost(token, jsonString, url, dataSecret, dataSecretIv, operatorId, signSecret);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -141,7 +228,88 @@ public class HaiNanChargeService extends AbsInterfaceWithPlatformLogic {
|
||||
*/
|
||||
@Override
|
||||
public Map<String, String> queryStationStatus(QueryStationInfoDTO dto) {
|
||||
return null;
|
||||
List<String> stationIds = dto.getStationIds();
|
||||
List<StationStatusInfo> StationStatusInfos = new ArrayList<>();
|
||||
List<Object> ConnectorStatusInfos = new ArrayList<>();
|
||||
ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorId());
|
||||
if (configInfo == null) {
|
||||
return null;
|
||||
}
|
||||
ConnectorStatusInfo connectorStatusInfo;
|
||||
for (String stationId : stationIds) {
|
||||
StationStatusInfo stationStatusInfo= new StationStatusInfo();
|
||||
stationStatusInfo.setStationId(stationId);
|
||||
// 根据站点id查询
|
||||
List<ConnectorInfoVO> list = pileConnectorInfoService.getConnectorListForLianLian(Long.parseLong(stationId));
|
||||
for (ConnectorInfoVO connectorInfoVO : list) {
|
||||
|
||||
String connectorStatus = connectorInfoVO.getConnectorStatus();
|
||||
if (StringUtils.equals(connectorStatus, PileConnectorDataBaseStatusEnum.OCCUPIED_CHARGING.getValue())) {
|
||||
// 充电中
|
||||
ConnectorChargeStatusInfo info = new ConnectorChargeStatusInfo();
|
||||
OrderBasicInfo orderBasicInfo = orderBasicInfoService.queryChargingByPileConnectorCode(connectorInfoVO.getPileConnectorCode());
|
||||
if (orderBasicInfo == null) {
|
||||
continue;
|
||||
}
|
||||
List<RealTimeMonitorData> chargingRealTimeData = orderBasicInfoService.getChargingRealTimeData(orderBasicInfo.getTransactionCode());
|
||||
if(CollectionUtils.isNotEmpty(chargingRealTimeData)) {
|
||||
RealTimeMonitorData realTimeMonitorData = chargingRealTimeData.get(0);
|
||||
|
||||
info.setStartChargeSeq(orderBasicInfo.getOrderCode());
|
||||
info.setConnectorID(orderBasicInfo.getPileConnectorCode());
|
||||
info.setConnectorStatus(Integer.valueOf(connectorInfoVO.getConnectorStatus()));
|
||||
info.setCurrentA(new BigDecimal(realTimeMonitorData.getOutputCurrent()));
|
||||
info.setVoltageA(new BigDecimal(realTimeMonitorData.getOutputVoltage()));
|
||||
info.setSoc(new BigDecimal(realTimeMonitorData.getSOC()));
|
||||
info.setStartTime(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, orderBasicInfo.getChargeStartTime()));
|
||||
info.setEndTime(DateUtils.getDateTime()); // 本次采样时间
|
||||
info.setTotalPower(new BigDecimal(realTimeMonitorData.getChargingDegree())); // 累计充电量
|
||||
// info.setElecMoney(); // 累计电费
|
||||
// info.setSeviceMoney(); // 累计服务费
|
||||
info.setTotalMoney(new BigDecimal(realTimeMonitorData.getChargingAmount()));
|
||||
|
||||
ConnectorStatusInfos.add(info);
|
||||
}
|
||||
} else {
|
||||
// 其他
|
||||
connectorStatusInfo = new ConnectorStatusInfo();
|
||||
connectorStatusInfo.setConnectorID(connectorInfoVO.getPileConnectorCode());
|
||||
connectorStatusInfo.setStatus(Integer.parseInt(connectorInfoVO.getConnectorStatus()));
|
||||
|
||||
ConnectorStatusInfos.add(connectorStatusInfo);
|
||||
}
|
||||
}
|
||||
stationStatusInfo.setConnectorStatusInfos(ConnectorStatusInfos);
|
||||
StationStatusInfos.add(stationStatusInfo);
|
||||
}
|
||||
// 将 StationStatusInfos 分页
|
||||
int pageNum = 1;
|
||||
int pageSize = 10;
|
||||
List<StationStatusInfo> collect = StationStatusInfos.stream()
|
||||
.skip((pageNum - 1) * pageSize)
|
||||
.limit(pageSize)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
int total = StationStatusInfos.size();
|
||||
int pages = PageUtil.totalPage(total, pageSize);
|
||||
|
||||
Map<String, Object> map = new LinkedHashMap<>();
|
||||
map.put("Total", total);
|
||||
map.put("StationStatusInfos", collect);
|
||||
|
||||
// 加密
|
||||
Map<String, String> resultMap = Maps.newLinkedHashMap();
|
||||
// 加密数据
|
||||
byte[] encryptText = Cryptos.aesEncrypt(JSONObject.toJSONString(map).getBytes(),
|
||||
configInfo.getDataSecret().getBytes(), configInfo.getDataSecretIv().getBytes());
|
||||
String encryptData = Encodes.encodeBase64(encryptText);
|
||||
|
||||
resultMap.put("Data", encryptData);
|
||||
// 生成sig
|
||||
String resultSign = GBSignUtils.sign(resultMap, configInfo.getSignSecret());
|
||||
resultMap.put("Sig", resultSign);
|
||||
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -151,19 +319,95 @@ public class HaiNanChargeService extends AbsInterfaceWithPlatformLogic {
|
||||
*/
|
||||
@Override
|
||||
public Map<String, String> queryStationStats(QueryStationInfoDTO dto) {
|
||||
return null;
|
||||
// 查询信息
|
||||
ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorId());
|
||||
if (configInfo == null) {
|
||||
return null;
|
||||
}
|
||||
// 根据站点id 查出这段时间的充电量
|
||||
List<AccumulativeInfoVO> list = orderBasicInfoService.getAccumulativeInfoForLianLian(dto);
|
||||
if (CollectionUtils.isEmpty(list)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 根据充电桩编号分组 key=充电桩编号
|
||||
Map<String, List<AccumulativeInfoVO>> pileMap = list.stream()
|
||||
.collect(Collectors.groupingBy(AccumulativeInfoVO::getPileSn));
|
||||
|
||||
// 存放所有充电桩设备
|
||||
List<EquipmentStatsInfo> equipmentStatsInfoList = Lists.newArrayList();
|
||||
// 站点用电量
|
||||
BigDecimal stationElectricity = BigDecimal.ZERO;
|
||||
// 用于记录枪口用电量 在循环每个枪口的时候初始化
|
||||
BigDecimal pileElec;
|
||||
for (String pileSn : pileMap.keySet()) {
|
||||
// 该充电桩下 所有枪口的用电数据
|
||||
List<AccumulativeInfoVO> accumulativeInfoVOS = pileMap.get(pileSn);
|
||||
if (CollectionUtils.isEmpty(accumulativeInfoVOS)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// 存放充电桩用电量
|
||||
pileElec = BigDecimal.ZERO;
|
||||
|
||||
// key=枪口编号 value 该枪口的用电数据
|
||||
Map<String, List<AccumulativeInfoVO>> collect = accumulativeInfoVOS.stream()
|
||||
.collect(Collectors.groupingBy(AccumulativeInfoVO::getPileConnectorCode));
|
||||
|
||||
List<ConnectorStatsInfo> connectorStatsInfos = Lists.newArrayList();
|
||||
for (Map.Entry<String, List<AccumulativeInfoVO>> entry : collect.entrySet()) {
|
||||
String pileConnectorCode = entry.getKey();
|
||||
List<AccumulativeInfoVO> value = entry.getValue();
|
||||
// 枪口用电量求和
|
||||
BigDecimal connectorElec = value.stream()
|
||||
.map(AccumulativeInfoVO::getConnectorElectricity)
|
||||
.map(BigDecimal::new)
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
|
||||
connectorStatsInfos.add(
|
||||
ConnectorStatsInfo.builder()
|
||||
.connectorID(pileConnectorCode)
|
||||
.connectorElectricity(connectorElec)
|
||||
.build()
|
||||
);
|
||||
// 充电桩电量为枪口用电量累计
|
||||
pileElec = pileElec.add(connectorElec);
|
||||
}
|
||||
|
||||
EquipmentStatsInfo build = EquipmentStatsInfo.builder()
|
||||
.equipmentID(pileSn)
|
||||
.equipmentElectricity(pileElec)
|
||||
.connectorStatsInfos(connectorStatsInfos)
|
||||
.build();
|
||||
equipmentStatsInfoList.add(build);
|
||||
|
||||
// 所有充电桩用电量之和
|
||||
stationElectricity = stationElectricity.add(pileElec);
|
||||
}
|
||||
|
||||
StationStatsInfo stationStatsInfo = StationStatsInfo.builder()
|
||||
.stationID(dto.getStationID())
|
||||
.startTime(dto.getStartTime())
|
||||
.endTime(dto.getEndTime())
|
||||
.stationElectricity(stationElectricity)
|
||||
.equipmentStatsInfos(equipmentStatsInfoList) // 设备列表
|
||||
.build();
|
||||
|
||||
Map<String, Object> map = new LinkedHashMap<>();
|
||||
map.put("StationStats", stationStatsInfo);
|
||||
|
||||
// 拼装结果集
|
||||
// 加密
|
||||
Map<String, String> resultMap = Maps.newLinkedHashMap();
|
||||
// 加密数据
|
||||
byte[] encryptText = Cryptos.aesEncrypt(JSONObject.toJSONString(map).getBytes(),
|
||||
configInfo.getDataSecret().getBytes(), configInfo.getDataSecretIv().getBytes());
|
||||
String encryptData = Encodes.encodeBase64(encryptText);
|
||||
|
||||
resultMap.put("Data", encryptData);
|
||||
// 生成sig
|
||||
String resultSign = GBSignUtils.sign(resultMap, configInfo.getSignSecret());
|
||||
resultMap.put("Sig", resultSign);
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 身份认证
|
||||
*
|
||||
* @param dto
|
||||
*/
|
||||
// @Override
|
||||
// public Map<String, String> generateToken(CommonParamsDTO dto) {
|
||||
// return null;
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
@@ -577,12 +577,7 @@ public class LianLianServiceImpl implements LianLianService {
|
||||
Map<String, Object> map = new LinkedHashMap<>();
|
||||
map.put("Total", total);
|
||||
map.put("StationStatusInfos", collect);
|
||||
// LianLianPageResponse response = LianLianPageResponse.builder()
|
||||
// .PageCount(pages)
|
||||
// .PageNo(pageNum)
|
||||
// .list(collect)
|
||||
// .ItemSize(total)
|
||||
// .build();
|
||||
|
||||
// 加密
|
||||
Map<String, String> resultMap = Maps.newLinkedHashMap();
|
||||
// 加密数据
|
||||
@@ -1480,8 +1475,6 @@ public class LianLianServiceImpl implements LianLianService {
|
||||
|
||||
String jsonString = JSONObject.toJSONString(json);
|
||||
|
||||
|
||||
|
||||
// 获取令牌
|
||||
String token = "";
|
||||
String result = "";
|
||||
|
||||
@@ -105,7 +105,25 @@ public class HttpRequestUtil {
|
||||
* @return
|
||||
*/
|
||||
public static String sendPost(String token, String data, String url, String dataSecret,
|
||||
String dataSecretIV, String operatorId, String sigSecret){
|
||||
String dataSecretIV, String operatorId, String sigSecret) {
|
||||
return HttpRequestUtil.sendPost(token, data, url, dataSecret, dataSecretIV, operatorId, sigSecret, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送请求
|
||||
*
|
||||
* @param token 令牌
|
||||
* @param data 要传输的JsonString格式数据
|
||||
* @param url 请求地址
|
||||
* @param dataSecret 消息密钥
|
||||
* @param dataSecretIV 消息密钥初始化向量
|
||||
* @param operatorId 运营商id
|
||||
* @param sigSecret 签名密钥
|
||||
* @return
|
||||
*/
|
||||
public static String sendPost(String token, String data, String url, String dataSecret,
|
||||
String dataSecretIV, String operatorId, String sigSecret,
|
||||
String thirdPlatformType) {
|
||||
String type = ThirdPartyOperatorIdEnum.getTypeByOperatorId(operatorId);
|
||||
String label = ThirdPlatformTypeEnum.getLabelByCode(type);
|
||||
if(StringUtils.isBlank(label)) {
|
||||
@@ -123,6 +141,12 @@ public class HttpRequestUtil {
|
||||
params.put("Data", encryptData);
|
||||
params.put("TimeStamp", DateUtils.parseDateToStr(DateUtils.YYYYMMDDHHMMSS, new Date()));
|
||||
params.put("Seq", "001");
|
||||
|
||||
// 此处是与其他获取令牌方法唯一不同之处,甬城泊车获取令牌需要添加此字段
|
||||
if (ThirdPlatformTypeEnum.YONG_CHENG_BO_CHE.getCode().equals(thirdPlatformType)) {
|
||||
params.put("Portname", "wcc-pro");
|
||||
}
|
||||
|
||||
String sign = GBSignUtils.sign(params, sigSecret);
|
||||
params.put("Sig", sign);
|
||||
|
||||
|
||||
@@ -1,32 +1,44 @@
|
||||
package com.jsowell.thirdparty.platform;
|
||||
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.jsowell.common.util.DateUtils;
|
||||
import com.jsowell.common.util.JWTUtils;
|
||||
import com.jsowell.common.util.StringUtils;
|
||||
import com.jsowell.pile.domain.PileBasicInfo;
|
||||
import com.jsowell.pile.domain.PileConnectorInfo;
|
||||
import com.jsowell.pile.domain.PileStationInfo;
|
||||
import com.jsowell.pile.domain.ThirdPartyPlatformConfig;
|
||||
import com.jsowell.pile.dto.QueryStationInfoDTO;
|
||||
import com.jsowell.pile.service.PileBillingTemplateService;
|
||||
import com.jsowell.pile.service.PileStationInfoService;
|
||||
import com.jsowell.pile.service.ThirdPartyPlatformConfigService;
|
||||
import com.jsowell.pile.service.*;
|
||||
import com.jsowell.pile.vo.web.PileModelInfoVO;
|
||||
import com.jsowell.thirdparty.lianlian.dto.CommonParamsDTO;
|
||||
import com.jsowell.thirdparty.lianlian.util.Cryptos;
|
||||
import com.jsowell.thirdparty.lianlian.util.Encodes;
|
||||
import com.jsowell.thirdparty.lianlian.util.GBSignUtils;
|
||||
import com.jsowell.thirdparty.lianlian.vo.AccessTokenVO;
|
||||
import com.jsowell.thirdparty.lianlian.vo.LianLianResultVO;
|
||||
import com.jsowell.thirdparty.zhongdianlian.domain.ZDLConnectorInfo;
|
||||
import com.jsowell.thirdparty.zhongdianlian.domain.ZDLEquipmentInfo;
|
||||
import com.jsowell.thirdparty.zhongdianlian.service.ZDLService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 对接第三方平台抽象类
|
||||
*/
|
||||
public abstract class AbsInterfaceWithPlatformLogic implements InitializingBean {
|
||||
protected final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
@Autowired
|
||||
protected PileStationInfoService pileStationInfoService;
|
||||
|
||||
@@ -36,6 +48,21 @@ public abstract class AbsInterfaceWithPlatformLogic implements InitializingBean
|
||||
@Autowired
|
||||
protected PileBillingTemplateService pileBillingTemplateService;
|
||||
|
||||
@Autowired
|
||||
protected PileBasicInfoService pileBasicInfoService;
|
||||
|
||||
@Autowired
|
||||
protected PileConnectorInfoService pileConnectorInfoService;
|
||||
|
||||
@Autowired
|
||||
protected PileModelInfoService pileModelInfoService;
|
||||
|
||||
@Autowired
|
||||
protected OrderBasicInfoService orderBasicInfoService;
|
||||
|
||||
@Autowired
|
||||
protected ThirdPartyStationRelationService thirdPartyStationRelationService;
|
||||
|
||||
@Autowired
|
||||
protected ZDLService zdlService;
|
||||
|
||||
@@ -64,10 +91,70 @@ public abstract class AbsInterfaceWithPlatformLogic implements InitializingBean
|
||||
*/
|
||||
public abstract Map<String, String> queryStationStats(QueryStationInfoDTO dto);
|
||||
|
||||
////////////////////////////////////// 以下是公用方法 ////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* 从联联平台获取令牌
|
||||
*
|
||||
* @param operatorId
|
||||
* @param operatorSecret
|
||||
* @return
|
||||
*/
|
||||
protected String getToken(String urlAddress, String operatorId, String operatorSecret,
|
||||
String dataSecretIv, String signSecret, String dataSecret) {
|
||||
String token = "";
|
||||
try {
|
||||
// 请求地址
|
||||
String requestUrl = urlAddress + "query_token";
|
||||
|
||||
// 请求data
|
||||
Map<String, String> data = new HashMap<>();
|
||||
data.put("OperatorID", operatorId);
|
||||
data.put("OperatorSecret", operatorSecret);
|
||||
data.put("DataSecretIV", dataSecretIv);
|
||||
String dataJson = JSONUtil.toJsonStr(data);
|
||||
|
||||
// 加密
|
||||
byte[] encryptText = Cryptos.aesEncrypt(dataJson.getBytes(StandardCharsets.UTF_8),
|
||||
dataSecret.getBytes(), dataSecretIv.getBytes());
|
||||
String strData = Encodes.encodeBase64(encryptText);
|
||||
|
||||
Map<String, String> request = new LinkedHashMap<>();
|
||||
request.put("OperatorID", operatorId);
|
||||
request.put("Data", strData);
|
||||
request.put("TimeStamp", DateUtils.parseDateToStr(DateUtils.YYYYMMDDHHMMSS, new Date()));
|
||||
request.put("Seq", "0001");
|
||||
|
||||
// 生成签名
|
||||
String sig = GBSignUtils.sign(request, signSecret);
|
||||
request.put("Sig", sig);
|
||||
|
||||
String tokenRequest = JSONUtil.toJsonStr(request);
|
||||
|
||||
String response = HttpUtil.post(requestUrl, tokenRequest);
|
||||
LianLianResultVO result = JSON.parseObject(response, LianLianResultVO.class);
|
||||
// logger.info("获取令牌 result:{}", result);
|
||||
|
||||
if (result.getRet() == 0) {
|
||||
// 解密data
|
||||
byte[] plainText = Cryptos.aesDecrypt(Encodes.decodeBase64((String) result.getData()),
|
||||
dataSecret.getBytes(), dataSecretIv.getBytes());
|
||||
String dataStr = new String(plainText, StandardCharsets.UTF_8);
|
||||
Map<String, String> resultMap = (Map<String, String>) JSON.parse(dataStr);
|
||||
token = resultMap.get("AccessToken");
|
||||
// logger.info("token: {}", token);
|
||||
}
|
||||
logger.info("获取令牌 result:{}, token: {}", result, token);
|
||||
} catch (Exception e) {
|
||||
return token;
|
||||
}
|
||||
return token;
|
||||
}
|
||||
|
||||
/**
|
||||
* 身份认证
|
||||
*/
|
||||
public Map<String, String> generateToken(CommonParamsDTO dto) {
|
||||
protected Map<String, String> generateToken(CommonParamsDTO dto) {
|
||||
String operatorID = dto.getOperatorID();
|
||||
// 通过operatorID 查出 operatorSecret
|
||||
ThirdPartyPlatformConfig platformConfig = thirdPartyPlatformConfigService.getInfoByOperatorId(operatorID);
|
||||
@@ -125,7 +212,7 @@ public abstract class AbsInterfaceWithPlatformLogic implements InitializingBean
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
public Map<String, String> checkoutSign(CommonParamsDTO dto){
|
||||
protected Map<String, String> checkoutSign(CommonParamsDTO dto){
|
||||
String operatorID = dto.getOperatorID();
|
||||
// 通过operatorID 查出 operatorSecret
|
||||
ThirdPartyPlatformConfig platformConfig = thirdPartyPlatformConfigService.getInfoByOperatorId(operatorID);
|
||||
@@ -162,4 +249,75 @@ public abstract class AbsInterfaceWithPlatformLogic implements InitializingBean
|
||||
resultMap.put("DataSecretIV", platformConfig.getDataSecretIv());
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取桩列表信息
|
||||
*
|
||||
* @param pileStationInfo
|
||||
* @return
|
||||
*/
|
||||
protected List<ZDLEquipmentInfo> getPileList(PileStationInfo pileStationInfo) {
|
||||
List<ZDLEquipmentInfo> resultList = new ArrayList<>();
|
||||
// 通过站点id查询桩基本信息
|
||||
List<PileBasicInfo> list = pileBasicInfoService.getPileListByStationId(String.valueOf(pileStationInfo.getId()));
|
||||
// 封装成中电联平台对象
|
||||
for (PileBasicInfo pileBasicInfo : list) {
|
||||
ZDLEquipmentInfo equipmentInfo = new ZDLEquipmentInfo();
|
||||
String pileSn = pileBasicInfo.getSn();
|
||||
|
||||
equipmentInfo.setEquipmentId(pileSn);
|
||||
|
||||
PileModelInfoVO modelInfo = pileModelInfoService.getPileModelInfoByPileSn(pileSn);
|
||||
equipmentInfo.setEquipmentType(Integer.parseInt(modelInfo.getSpeedType()));
|
||||
equipmentInfo.setPower(new BigDecimal(modelInfo.getRatedPower()).setScale(1, BigDecimal.ROUND_HALF_UP));
|
||||
|
||||
List<ZDLConnectorInfo> connectorList = getConnectorList(pileBasicInfo);
|
||||
equipmentInfo.setConnectorInfos(connectorList);
|
||||
|
||||
resultList.add(equipmentInfo);
|
||||
}
|
||||
return resultList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取枪口列表
|
||||
*
|
||||
* @param pileBasicInfo
|
||||
* @return
|
||||
*/
|
||||
protected List<ZDLConnectorInfo> getConnectorList(PileBasicInfo pileBasicInfo) {
|
||||
List<ZDLConnectorInfo> resultList = new ArrayList<>();
|
||||
|
||||
List<PileConnectorInfo> list = pileConnectorInfoService.selectPileConnectorInfoList(pileBasicInfo.getSn());
|
||||
for (PileConnectorInfo pileConnectorInfo : list) {
|
||||
ZDLConnectorInfo connectorInfo = new ZDLConnectorInfo();
|
||||
|
||||
connectorInfo.setConnectorId(pileConnectorInfo.getPileConnectorCode());
|
||||
String pileSn = pileConnectorInfo.getPileSn();
|
||||
PileModelInfoVO modelInfo = pileModelInfoService.getPileModelInfoByPileSn(pileSn);
|
||||
int connectorType = StringUtils.equals("1", modelInfo.getSpeedType()) ? 4 : 3;
|
||||
|
||||
connectorInfo.setConnectorType(connectorType);
|
||||
// 车位号
|
||||
if (StringUtils.isNotBlank(pileConnectorInfo.getParkNo())) {
|
||||
connectorInfo.setParkNo(pileConnectorInfo.getParkNo());
|
||||
}
|
||||
connectorInfo.setVoltageUpperLimits(Integer.valueOf(modelInfo.getRatedVoltage()));
|
||||
connectorInfo.setVoltageLowerLimits(Integer.valueOf(modelInfo.getRatedVoltage()));
|
||||
connectorInfo.setCurrent(Integer.valueOf(modelInfo.getRatedCurrent()));
|
||||
connectorInfo.setNationalStandard(2);
|
||||
// if (!StringUtils.equals(modelInfo.getConnectorNum(), "1")) {
|
||||
// // 如果不是单枪,则枪口功率需要除以枪口数量
|
||||
// String ratedPowerStr = modelInfo.getRatedPower();
|
||||
// BigDecimal ratedPower = new BigDecimal(ratedPowerStr);
|
||||
// connectorInfo.setPower(ratedPower.divide(new BigDecimal(modelInfo.getConnectorNum()), 1, BigDecimal.ROUND_HALF_UP));
|
||||
// }else {
|
||||
// }
|
||||
connectorInfo.setPower(new BigDecimal(modelInfo.getRatedPower()).setScale(1, BigDecimal.ROUND_HALF_UP));
|
||||
|
||||
resultList.add(connectorInfo);
|
||||
}
|
||||
|
||||
return resultList;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user