新增 青海平台相关代码

This commit is contained in:
Lemon
2024-04-09 10:16:48 +08:00
parent a8e2996f43
commit 6f5e3b950c
5 changed files with 266 additions and 1 deletions

View File

@@ -0,0 +1,113 @@
package com.jsowell.thirdparty.platform.qinghai.service;
import com.alibaba.fastjson2.JSONObject;
import com.google.common.collect.Maps;
import com.jsowell.common.enums.thirdparty.ThirdPlatformTypeEnum;
import com.jsowell.common.util.PageUtils;
import com.jsowell.common.util.StringUtils;
import com.jsowell.pile.domain.ThirdPartyPlatformConfig;
import com.jsowell.pile.domain.ThirdPartyStationRelation;
import com.jsowell.pile.dto.QueryStationInfoDTO;
import com.jsowell.pile.service.PileStationInfoService;
import com.jsowell.pile.service.ThirdPartyPlatformConfigService;
import com.jsowell.pile.service.ThirdPartyStationRelationService;
import com.jsowell.pile.vo.base.ThirdPartyStationInfoVO;
import com.jsowell.thirdparty.platform.ThirdPartyPlatformService;
import com.jsowell.thirdparty.platform.util.Cryptos;
import com.jsowell.thirdparty.platform.util.Encodes;
import com.jsowell.thirdparty.platform.util.GBSignUtils;
import org.apache.commons.collections4.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* 青海平台 Service
*
* @author Lemon
* @Date 2024/4/8 15:12:35
*/
@Service
public class QingHaiPlatformServiceImpl implements ThirdPartyPlatformService {
@Resource
private ThirdPartyStationRelationService thirdPartyStationRelationService;
@Autowired
private PileStationInfoService pileStationInfoService;
@Autowired
private ThirdPartyPlatformConfigService thirdPartyPlatformConfigService;
Logger logger = LoggerFactory.getLogger(QingHaiPlatformServiceImpl.class);
// 平台类型
private final String platformType = ThirdPlatformTypeEnum.QING_HAI_PLATFORM.getTypeCode();
/**
* 查询站点信息 query_stations_info
* @param dto 查询站点信息dto
* @return
*/
@Override
public Map<String, String> queryStationsInfo(QueryStationInfoDTO dto) {
// 查询出要查询的充电站id并set进 dto 的stationIds
if (StringUtils.isNotBlank(dto.getThirdPlatformType())) {
List<ThirdPartyStationRelation> xdtList = thirdPartyStationRelationService.selectThirdPartyStationRelationList(dto.getThirdPlatformType());
if (CollectionUtils.isNotEmpty(xdtList)) {
List<String> stationList = xdtList.stream()
.map(x -> String.valueOf(x.getStationId()))
.collect(Collectors.toList());
dto.setStationIds(stationList);
}
}
int pageNo = dto.getPageNo() == null ? 1 : dto.getPageNo();
int pageSize = dto.getPageSize() == null ? 10 : dto.getPageSize();
PageUtils.startPage(pageNo, pageSize);
// 查询站点信息数据
List<ThirdPartyStationInfoVO> stationInfos = pileStationInfoService.getStationInfosByThirdParty(dto);
if (CollectionUtils.isEmpty(stationInfos)) {
// 未查到数据
return null;
}
return null;
}
/**
* 将需要发送至对接平台的的返回参数加密返回
* @param jsonObject
* @return
*/
private Map<String, String> getResultMap(JSONObject jsonObject) {
String operatorId = ThirdPlatformTypeEnum.QING_HAI_PLATFORM.getOperatorId();
ThirdPartyPlatformConfig platformConfig = thirdPartyPlatformConfigService.getInfoByOperatorId(operatorId);
if (platformConfig == null) {
return null;
}
Map<String, String> resultMap = Maps.newLinkedHashMap();
// 加密数据
byte[] encryptText = Cryptos.aesEncrypt(jsonObject.toJSONString().getBytes(),
platformConfig.getDataSecret().getBytes(), platformConfig.getDataSecretIv().getBytes());
String encryptData = Encodes.encodeBase64(encryptText);
resultMap.put("Data", encryptData);
// 生成sig
String resultSign = GBSignUtils.sign(resultMap, platformConfig.getSignSecret());
resultMap.put("Sig", resultSign);
return resultMap;
}
}