Merge branch 'dev-zza' into dev

This commit is contained in:
Lemon
2025-02-13 10:14:55 +08:00
4 changed files with 406 additions and 0 deletions

View File

@@ -1259,6 +1259,7 @@ public class PileBasicInfoServiceImpl implements PileBasicInfoService {
equipmentInfo.setNewNationalStandard(1);
equipmentInfo.setVinFlag(1);
equipmentInfo.setEquipmentName(pileSn);
equipmentInfo.setEquipmentApplication(1);
equipmentInfo.setEquipmentInvestment(new BigDecimal("0.0"));
equipmentInfo.setProductSN(pileSn);
equipmentInfo.setOpenDate(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, pileDetailInfoVO.getCreateTime()));

View File

@@ -94,6 +94,17 @@ public class EquipmentInfo {
@JSONField(name = "EquipmentStatus")
private Integer equipmentStatus;
/**
* 充电设备用途
* 1公用
* 2专用
* 3个人分时共享
* 4限制类公用
* 9其他
*/
@JSONField(name = "EquipmentApplication")
private Integer equipmentApplication;
/**
* 额定功率(单位kW) Y
*/

View File

@@ -32,6 +32,10 @@ public class SupStationInfo extends StationInfo {
@JSONField(name = "AreaCodeCountryside")
private String areaCodeCountryside;
@JSONField(name = "TownCode")
private String townCode;
/**
* 站点分类
* 1充电站

View File

@@ -1,16 +1,52 @@
package com.jsowell.thirdparty.platform.service.impl;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.github.pagehelper.PageInfo;
import com.google.common.collect.Lists;
import com.jsowell.common.constant.Constants;
import com.jsowell.common.core.redis.RedisCache;
import com.jsowell.common.enums.thirdparty.BusinessInformationExchangeEnum;
import com.jsowell.common.enums.thirdparty.ThirdPlatformTypeEnum;
import com.jsowell.common.enums.ykc.ReturnCodeEnum;
import com.jsowell.common.exception.BusinessException;
import com.jsowell.common.util.JWTUtils;
import com.jsowell.common.util.PageUtils;
import com.jsowell.common.util.StringUtils;
import com.jsowell.pile.domain.AreaCodeInfo;
import com.jsowell.pile.dto.PushRealTimeInfoDTO;
import com.jsowell.pile.dto.QueryStationInfoDTO;
import com.jsowell.pile.service.*;
import com.jsowell.pile.thirdparty.CommonParamsDTO;
import com.jsowell.pile.thirdparty.EquipmentInfo;
import com.jsowell.pile.vo.ThirdPartySecretInfoVO;
import com.jsowell.pile.vo.base.ConnectorInfoVO;
import com.jsowell.pile.vo.base.ThirdPartyStationInfoVO;
import com.jsowell.pile.vo.lianlian.AccumulativeInfoVO;
import com.jsowell.pile.vo.uniapp.customer.BillingPriceVO;
import com.jsowell.thirdparty.lianlian.domain.*;
import com.jsowell.thirdparty.lianlian.vo.AccessTokenVO;
import com.jsowell.thirdparty.platform.domain.SupStationInfo;
import com.jsowell.thirdparty.platform.factory.ThirdPartyPlatformFactory;
import com.jsowell.thirdparty.platform.service.ThirdPartyPlatformService;
import com.jsowell.thirdparty.platform.util.Cryptos;
import com.jsowell.thirdparty.platform.util.HttpRequestUtil;
import com.jsowell.thirdparty.platform.util.ThirdPartyPlatformUtils;
import com.jsowell.thirdparty.service.ThirdpartySecretInfoService;
import com.yi.business.geo.GeoCodeInfo;
import com.yi.business.geo.TermRelationTreeCoordinate;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
/**
* 河南省平台Service
*
@@ -25,11 +61,365 @@ public class HeNanPlatformServiceImpl implements ThirdPartyPlatformService {
@Autowired
private ThirdpartySecretInfoService thirdpartySecretInfoService;
@Autowired
private RedisCache redisCache;
@Autowired
private PileStationInfoService pileStationInfoService;
@Autowired
private PileBasicInfoService pileBasicInfoService;
@Autowired
private IAreaCodeInfoService areaCodeInfoService;
@Autowired
private PileBillingTemplateService pileBillingTemplateService;
@Autowired
private OrderBasicInfoService orderBasicInfoService;
@Autowired
private PileConnectorInfoService pileConnectorInfoService;
@Override
public void afterPropertiesSet() throws Exception {
ThirdPartyPlatformFactory.register(thirdPlatformType, this);
}
/**
* 查询令牌 query_token
* @param dto
* @return
*/
@Override
public Map<String, String> queryToken(CommonParamsDTO dto) {
AccessTokenVO vo = new AccessTokenVO();
// 0:成功1:失败
int succStat = 0;
// 0:无1:无此对接平台2:密钥错误; 399:自定义
int failReason = 0;
String operatorId = dto.getOperatorID();
// token缓存key值
String redisKey = operatorId + "_token:";
// 通过operatorId 查出 operatorSecret
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getHeNanSecretInfo();
if (thirdPartySecretInfoVO == null) {
failReason = 1;
succStat = 1;
} else {
String ourOperatorSecret = thirdPartySecretInfoVO.getOurOperatorSecret();
String dataSecret = thirdPartySecretInfoVO.getOurDataSecret();
String dataSecretIv = thirdPartySecretInfoVO.getOurDataSecretIv();
// 解密data 获取参数中的OperatorSecret
String decrypt = Cryptos.decrypt(dto.getData(), dataSecret, dataSecretIv);
String inputOperatorSecret = null;
if (StringUtils.isNotBlank(decrypt)) {
inputOperatorSecret = JSON.parseObject(decrypt).getString("OperatorSecret");
}
// 对比密钥
if (!StringUtils.equals(ourOperatorSecret, inputOperatorSecret)) {
failReason = 1;
succStat = 1;
} else {
// 先查缓存中是否有已生成的token
String token = redisCache.getCacheObject(redisKey);
int expiredTime = (int) redisCache.getExpire(redisKey);
if (StringUtils.isBlank(token)) {
// 生成token
token = JWTUtils.createToken(operatorId, ourOperatorSecret, JWTUtils.ttlMillis);
expiredTime = (int) (JWTUtils.ttlMillis / 1000);
}
vo.setAccessToken(token);
vo.setTokenAvailableTime(expiredTime);
// 设置缓存
redisCache.setCacheObject(redisKey, token, expiredTime, TimeUnit.SECONDS);
}
}
// 组装返回参数
vo.setOperatorID(operatorId);
vo.setFailReason(failReason);
vo.setSuccStat(succStat);
Map<String, String> resultMap = ThirdPartyPlatformUtils.generateResultMapV2(vo, thirdPartySecretInfoVO.getOurDataSecret(),
thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret());
return resultMap;
}
/**
* 查询站点信息 query_stations_info
* @param dto 查询站点信息dto
* @return
*/
@Override
public Map<String, String> queryStationsInfo(QueryStationInfoDTO dto) {
int pageNo = dto.getPageNo() == null ? 1 : dto.getPageNo();
int pageSize = dto.getPageSize() == null ? 10 : dto.getPageSize();
dto.setThirdPlatformType(thirdPlatformType);
PageUtils.startPage(pageNo, pageSize);
List<ThirdPartyStationInfoVO> stationInfos = pileStationInfoService.selectStationInfosByThirdParty(dto);
if (CollectionUtils.isEmpty(stationInfos)) {
// 未查到数据
return null;
}
// ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorId());
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getHeNanSecretInfo();
PageInfo<ThirdPartyStationInfoVO> pageInfo = new PageInfo<>(stationInfos);
List<SupStationInfo> resultList = new ArrayList<>();
for (ThirdPartyStationInfoVO pileStationInfo : pageInfo.getList()) {
SupStationInfo stationInfo = new SupStationInfo();
stationInfo.setStationID(String.valueOf(pileStationInfo.getId()));
stationInfo.setOperatorID(Constants.OPERATORID_JIANG_SU); // 组织机构代码
String organizationCode = pileStationInfo.getOrganizationCode();
if (StringUtils.isNotBlank(organizationCode) && organizationCode.length() == 18) {
String equipmentOwnerId = StringUtils.substring(organizationCode, organizationCode.length() - 10, organizationCode.length() - 1);
stationInfo.setEquipmentOwnerID(equipmentOwnerId);
}else {
stationInfo.setEquipmentOwnerID(Constants.OPERATORID_JIANG_SU);
}
stationInfo.setStationName(pileStationInfo.getStationName());
stationInfo.setCountryCode(pileStationInfo.getCountryCode());
String areaCode = pileStationInfo.getAreaCode(); // 330000,330200,330213
// 根据逗号分组
String[] split = StringUtils.split(areaCode, ",");
// 只取最后一部分 330213
String subAreaCode = split[split.length - 1];
stationInfo.setAreaCode(subAreaCode);
stationInfo.setAddress(pileStationInfo.getAddress());
stationInfo.setServiceTel(pileStationInfo.getStationTel());
stationInfo.setStationType(Integer.parseInt(pileStationInfo.getStationType()));
stationInfo.setStationStatus(Integer.parseInt(pileStationInfo.getStationStatus()));
stationInfo.setParkNums(Integer.parseInt(pileStationInfo.getParkNums()));
stationInfo.setStationLng(new BigDecimal(pileStationInfo.getStationLng()));
stationInfo.setStationLat(new BigDecimal(pileStationInfo.getStationLat()));
stationInfo.setConstruction(Integer.parseInt(pileStationInfo.getConstruction()));
// 停车费率描述
if (StringUtils.isNotBlank(pileStationInfo.getParkFeeDescribe())) {
stationInfo.setParkFee(pileStationInfo.getParkFeeDescribe());
}
// 站点图片
if (StringUtils.isNotBlank(pileStationInfo.getPictures())) {
stationInfo.setPictures(Lists.newArrayList(pileStationInfo.getPictures().split(",")));
}
StringBuilder electricityFee = new StringBuilder();
StringBuilder serviceFee = new StringBuilder();
// 查询计费模板
List<BillingPriceVO> priceList = pileBillingTemplateService.queryBillingPrice(String.valueOf(pileStationInfo.getId()));
for (BillingPriceVO billingPriceVO : priceList) {
electricityFee.append(billingPriceVO.getStartTime())
.append("-").append(billingPriceVO.getEndTime())
.append(":").append(billingPriceVO.getElectricityPrice())
.append(";");
serviceFee.append(billingPriceVO.getStartTime())
.append("-").append(billingPriceVO.getEndTime())
.append(":").append(billingPriceVO.getServicePrice())
.append(";");
}
// townCode
GeoCodeInfo geoCode = TermRelationTreeCoordinate.completeGeoCode(pileStationInfo.getAddress());
if (geoCode == null) {
// String areaCodeCountryside = geoCode.getCounty_code();
stationInfo.setTownCode("123456789101");
} else {
AreaCodeInfo areaCodeInfo = new AreaCodeInfo();
if (StringUtils.isNotBlank(geoCode.getTownName())) {
String townName = geoCode.getTownName();
areaCodeInfo.setName(townName);
} else {
String countyName = geoCode.getCountyName();
areaCodeInfo.setName(countyName);
}
List<AreaCodeInfo> areaCodeInfoList = areaCodeInfoService.selectAreaCodeInfoList(areaCodeInfo);
stationInfo.setTownCode(String.valueOf(areaCodeInfoList.get(0).getAreaCode()));
}
stationInfo.setSupportOrder(0);
List<EquipmentInfo> pileList = pileBasicInfoService.getPileListForLianLian(String.valueOf(pileStationInfo.getId()));
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 = ThirdPartyPlatformUtils.generateResultMapV2(map, thirdPartySecretInfoVO.getOurDataSecret(),
thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret());
return resultMap;
}
/**
* 设备状态变化推送 notification_stationStatus
* @param stationId 站点id
* @param pileConnectorCode 充电桩枪口编号
* @param status
* @param secretInfoVO
* @return
*/
@Override
public String notificationStationStatus(String stationId, String pileConnectorCode, String status, ThirdPartySecretInfoVO secretInfoVO) {
// 查询相关配置信息
ThirdPartySecretInfoVO ganSuSecretInfo = getHeNanSecretInfo();
String operatorId = Constants.OPERATORID_JIANG_SU;
String operatorSecret = ganSuSecretInfo.getTheirOperatorSecret();
String signSecret = ganSuSecretInfo.getTheirSigSecret();
String dataSecret = ganSuSecretInfo.getTheirDataSecret();
String dataSecretIv = ganSuSecretInfo.getTheirDataSecretIv();
String urlAddress = ganSuSecretInfo.getTheirUrlPrefix();
String url = urlAddress + BusinessInformationExchangeEnum.NOTIFICATION_STATION_STATUS.getValue();
ConnectorStatusInfo info = ConnectorStatusInfo.builder()
.connectorID(pileConnectorCode)
.status(Integer.parseInt(status))
.build();
// 调用联联平台接口
JSONObject json = new JSONObject();
json.put("ConnectorStatusInfo", info);
String jsonString = JSON.toJSONString(json);
// 获取令牌
String token = getToken(urlAddress, operatorId, operatorSecret, dataSecretIv, signSecret, dataSecret);
String result = HttpRequestUtil.sendPost(token, jsonString, url, dataSecret, dataSecretIv, operatorId, signSecret);
return result;
}
/**
* 设备接口状态查询 query_station_status
* @param dto 查询站点信息dto
* @return
*/
@Override
public Map<String, String> queryStationStatus(QueryStationInfoDTO dto) {
List<String> stationIds = dto.getStationIds();
List<StationStatusInfo> stationStatusInfos = new ArrayList<>();
List<Object> connectorStatusInfos = new ArrayList<>();
// 查询密钥信息
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getHeNanSecretInfo();
// 根据站点idList查询枪口列表
List<ConnectorInfoVO> list = pileConnectorInfoService.batchSelectConnectorList(stationIds);
// 根据站点id分组
Map<String, List<ConnectorInfoVO>> collect = list.stream()
.collect(Collectors.groupingBy(ConnectorInfoVO::getStationId));
// 封装参数
for (Map.Entry<String, List<ConnectorInfoVO>> entry : collect.entrySet()) {
String stationId = entry.getKey();
List<ConnectorInfoVO> voList = entry.getValue();
StationStatusInfo stationStatusInfo = new StationStatusInfo();
stationStatusInfo.setStationId(stationId);
ConnectorStatusInfo connectorStatusInfo;
for (ConnectorInfoVO connectorInfoVO : voList) {
connectorStatusInfo = ConnectorStatusInfo.builder()
.connectorID(connectorInfoVO.getPileConnectorCode())
.status(Integer.parseInt(connectorInfoVO.getConnectorStatus()))
.build();
connectorStatusInfos.add(connectorStatusInfo);
}
stationStatusInfo.setConnectorStatusInfos(connectorStatusInfos);
stationStatusInfos.add(stationStatusInfo);
}
Map<String, Object> map = new LinkedHashMap<>();
map.put("StationStatusInfos", stationStatusInfos);
Map<String, String> resultMap = ThirdPartyPlatformUtils.generateResultMapV2(map, thirdPartySecretInfoVO.getOurDataSecret(),
thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret());
return resultMap;
}
/**
* 查询统计信息 query_station_stats
* @param dto 查询站点信息dto
* @return
*/
@Override
public Map<String, String> queryStationStats(QueryStationInfoDTO dto) {
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getHeNanSecretInfo();
// 根据站点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 = ThirdPartyPlatformUtils.generateResultMapV2(map, thirdPartySecretInfoVO.getOurDataSecret(),
thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret());
return resultMap;
}
/**
* 查询河南省平台密钥信息