mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-21 11:35:12 +08:00
新增 甘肃省平台相关Service
This commit is contained in:
@@ -0,0 +1,230 @@
|
||||
package com.jsowell.thirdparty.platform.service.impl;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.jsowell.common.constant.Constants;
|
||||
import com.jsowell.common.core.redis.RedisCache;
|
||||
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.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.ThirdPartyStationInfoVO;
|
||||
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.ThirdPartyPlatformUtils;
|
||||
import com.jsowell.thirdparty.service.ThirdpartySecretInfoService;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* 甘肃省平台
|
||||
*
|
||||
* @author Lemon
|
||||
* @Date 2024/11/5 13:31:06
|
||||
*/
|
||||
public class GanSuPlatformServiceImpl implements ThirdPartyPlatformService {
|
||||
|
||||
@Autowired
|
||||
private ThirdpartySecretInfoService thirdpartySecretInfoService;
|
||||
|
||||
@Autowired
|
||||
private PileBasicInfoService pileBasicInfoService;
|
||||
|
||||
@Autowired
|
||||
private PileMerchantInfoService pileMerchantInfoService;
|
||||
|
||||
@Autowired
|
||||
private PileConnectorInfoService pileConnectorInfoService;
|
||||
|
||||
@Autowired
|
||||
private OrderBasicInfoService orderBasicInfoService;
|
||||
|
||||
@Autowired
|
||||
private PileStationInfoService pileStationInfoService;
|
||||
|
||||
@Autowired
|
||||
private RedisCache redisCache;
|
||||
|
||||
// 平台类型
|
||||
private final String thirdPlatformType = ThirdPlatformTypeEnum.GAN_SU_PLATFORM.getTypeCode();
|
||||
|
||||
@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:密钥错误; 3~99:自定义
|
||||
int failReason = 0;
|
||||
|
||||
String operatorId = dto.getOperatorID();
|
||||
// token缓存key值
|
||||
String redisKey = operatorId + "_token:";
|
||||
// 通过operatorId 查出 operatorSecret
|
||||
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getGanSuSecretInfo();
|
||||
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.getOurSigSecret());
|
||||
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();
|
||||
|
||||
PageUtils.startPage(pageNo, pageSize);
|
||||
List<ThirdPartyStationInfoVO> stationInfos = pileStationInfoService.getStationInfosByThirdParty(dto);
|
||||
if (CollectionUtils.isEmpty(stationInfos)) {
|
||||
// 未查到数据
|
||||
return null;
|
||||
}
|
||||
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getGanSuSecretInfo();
|
||||
|
||||
PageInfo<ThirdPartyStationInfoVO> pageInfo = new PageInfo<>(stationInfos);
|
||||
List<SupStationInfo> resultList = new ArrayList<>();
|
||||
for (ThirdPartyStationInfoVO pileStationInfo : pageInfo.getList()) {
|
||||
String stationId = String.valueOf(pileStationInfo.getId());
|
||||
SupStationInfo stationInfo = SupStationInfo.builder()
|
||||
.stationID(stationId)
|
||||
.operatorID(Constants.OPERATORID_JIANG_SU)
|
||||
.stationName(pileStationInfo.getStationName())
|
||||
.countryCode(pileStationInfo.getCountryCode())
|
||||
.address(pileStationInfo.getAddress())
|
||||
.stationType(Integer.parseInt(pileStationInfo.getStationType()))
|
||||
.stationStatus(Integer.parseInt(pileStationInfo.getStationStatus()))
|
||||
.stationLng(new BigDecimal(pileStationInfo.getStationLng()))
|
||||
.stationLat(new BigDecimal(pileStationInfo.getStationLat()))
|
||||
.construction(Integer.parseInt(pileStationInfo.getConstruction()))
|
||||
.parkNums(Integer.parseInt(pileStationInfo.getParkNums()))
|
||||
// todo .electricityFee()
|
||||
// todo .serviceFee()
|
||||
|
||||
.build();
|
||||
// busineHours
|
||||
String busineHours = getBusineHours();
|
||||
stationInfo.setBusineHours(busineHours);
|
||||
|
||||
// areaCode
|
||||
String[] split = StringUtils.split(pileStationInfo.getAreaCode(), ",");
|
||||
// 只取最后一部分 330213
|
||||
String subAreaCode = split[split.length - 1];
|
||||
stationInfo.setAreaCode(subAreaCode);
|
||||
|
||||
// EquipmentOwnerID
|
||||
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);
|
||||
}
|
||||
|
||||
List<EquipmentInfo> pileList = pileBasicInfoService.getPileListForLianLian(stationId);
|
||||
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", pageInfo.getTotal());
|
||||
map.put("StationInfos", resultList);
|
||||
return ThirdPartyPlatformUtils.generateResultMap(map, thirdPartySecretInfoVO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取甘肃平台密钥
|
||||
* @return
|
||||
*/
|
||||
private ThirdPartySecretInfoVO getGanSuSecretInfo() {
|
||||
String thirdPartyType = ThirdPlatformTypeEnum.GAN_SU_PLATFORM.getTypeCode();
|
||||
ThirdPartySecretInfoVO thirdPartySecretInfoVO = thirdpartySecretInfoService.queryByThirdPlatformType(thirdPartyType);
|
||||
if (thirdPartySecretInfoVO == null) {
|
||||
throw new BusinessException(ReturnCodeEnum.CODE_SELECT_INFO_IS_NULL);
|
||||
}
|
||||
thirdPartySecretInfoVO.setOurOperatorId(Constants.OPERATORID_JIANG_SU);
|
||||
return thirdPartySecretInfoVO;
|
||||
}
|
||||
|
||||
private String getBusineHours() {
|
||||
Map<String, String> map = new LinkedHashMap<>();
|
||||
map.put("1", "[\"00:00-24:00\"]");
|
||||
map.put("2", "[\"00:00-24:00\"]");
|
||||
map.put("3", "[\"00:00-24:00\"]");
|
||||
map.put("4", "[\"00:00-24:00\"]");
|
||||
map.put("5", "[\"00:00-24:00\"]");
|
||||
map.put("6", "[\"00:00-24:00\"]");
|
||||
map.put("7", "[\"00:00-24:00\"]");
|
||||
|
||||
return map.toString();
|
||||
}
|
||||
}
|
||||
@@ -233,10 +233,8 @@ public class SuZhouPlatformServiceImpl implements ThirdPartyPlatformService {
|
||||
return null;
|
||||
}
|
||||
// ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorId());
|
||||
ThirdPartySecretInfoVO thirdPartySecretInfoVO = thirdpartySecretInfoService.queryByThirdPlatformType(thirdPlatformType);
|
||||
if (thirdPartySecretInfoVO == null) {
|
||||
return null;
|
||||
}
|
||||
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getSuZhouSecretInfo();
|
||||
|
||||
PageInfo<ThirdPartyStationInfoVO> pageInfo = new PageInfo<>(stationInfos);
|
||||
List<SupStationInfo> resultList = new ArrayList<>();
|
||||
for (ThirdPartyStationInfoVO pileStationInfo : pageInfo.getList()) {
|
||||
|
||||
Reference in New Issue
Block a user