mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-22 03:55:17 +08:00
update 宁夏交投平台Service
This commit is contained in:
@@ -13,6 +13,7 @@ import com.jsowell.common.util.StringUtils;
|
||||
import com.jsowell.common.util.bean.BeanUtils;
|
||||
import com.jsowell.pile.dto.*;
|
||||
import com.jsowell.pile.dto.nanrui.PushAlarmInfoDTO;
|
||||
import com.jsowell.pile.dto.ningxiajiaotou.NXJTQueryOrdersInfoDTO;
|
||||
import com.jsowell.pile.dto.ningxiajiaotou.NXJTQueryStationInfoDTO;
|
||||
import com.jsowell.pile.thirdparty.CommonParamsDTO;
|
||||
import com.jsowell.pile.vo.ThirdPartySecretInfoVO;
|
||||
@@ -93,6 +94,15 @@ public interface ThirdPartyPlatformService extends InitializingBean {
|
||||
throw new UnsupportedOperationException("This method is not yet implemented");
|
||||
}
|
||||
|
||||
/**
|
||||
* 宁夏交投平台查询充电站信息
|
||||
* @param dto
|
||||
* @return
|
||||
*/
|
||||
default Map<String, String> NXJTQueryStationsInfo(NXJTQueryStationInfoDTO dto){
|
||||
throw new UnsupportedOperationException("This method is not yet implemented");
|
||||
}
|
||||
|
||||
/**
|
||||
* 设备接口状态查询 query_station_status
|
||||
*
|
||||
@@ -177,7 +187,7 @@ public interface ThirdPartyPlatformService extends InitializingBean {
|
||||
*
|
||||
* @throws UnsupportedOperationException 未实现异常
|
||||
*/
|
||||
default Map<String, String> queryOrdersInfoByPlateNumber(NXJTQueryStationInfoDTO dto) {
|
||||
default Map<String, String> queryOrdersInfoByPlateNumber(NXJTQueryOrdersInfoDTO dto) {
|
||||
throw new UnsupportedOperationException("This method is not yet implemented");
|
||||
}
|
||||
|
||||
@@ -186,7 +196,7 @@ public interface ThirdPartyPlatformService extends InitializingBean {
|
||||
*
|
||||
* @throws UnsupportedOperationException 未实现异常
|
||||
*/
|
||||
default Map<String, String> queryOrdersInfo(NXJTQueryStationInfoDTO dto) {
|
||||
default Map<String, String> queryOrdersInfo(NXJTQueryOrdersInfoDTO dto) {
|
||||
throw new UnsupportedOperationException("This method is not yet implemented");
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,45 @@
|
||||
package com.jsowell.thirdparty.platform.service.impl;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.google.common.collect.Maps;
|
||||
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.DateUtils;
|
||||
import com.jsowell.common.util.JWTUtils;
|
||||
import com.jsowell.common.util.PageUtils;
|
||||
import com.jsowell.common.util.StringUtils;
|
||||
import com.jsowell.pile.domain.ThirdPartyPlatformConfig;
|
||||
import com.jsowell.pile.dto.QueryStationInfoDTO;
|
||||
import com.jsowell.pile.dto.ningxiajiaotou.NXJTQueryOrdersInfoDTO;
|
||||
import com.jsowell.pile.dto.ningxiajiaotou.NXJTQueryStationInfoDTO;
|
||||
import com.jsowell.pile.service.OrderBasicInfoService;
|
||||
import com.jsowell.pile.service.PileConnectorInfoService;
|
||||
import com.jsowell.pile.service.PileStationInfoService;
|
||||
import com.jsowell.pile.thirdparty.CommonParamsDTO;
|
||||
import com.jsowell.pile.vo.ThirdPartySecretInfoVO;
|
||||
import com.jsowell.pile.vo.base.ConnectorInfoVO;
|
||||
import com.jsowell.pile.vo.ningxiajiaotou.NXJTOrderVO;
|
||||
import com.jsowell.pile.vo.ningxiajiaotou.NXJTStationInfoVO;
|
||||
import com.jsowell.pile.vo.uniapp.customer.OrderVO;
|
||||
import com.jsowell.thirdparty.lianlian.vo.AccessTokenVO;
|
||||
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.Encodes;
|
||||
import com.jsowell.thirdparty.platform.util.GBSignUtils;
|
||||
import com.jsowell.thirdparty.platform.util.ThirdPartyPlatformUtils;
|
||||
import com.jsowell.thirdparty.service.ThirdpartySecretInfoService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 宁夏交投平台
|
||||
*
|
||||
@@ -16,10 +51,220 @@ public class NingXiaJiaoTouPlatformServiceImpl implements ThirdPartyPlatformServ
|
||||
// 平台类型
|
||||
private final String thirdPlatformType = ThirdPlatformTypeEnum.NING_XIA_JIAO_TOU.getTypeCode();
|
||||
|
||||
@Autowired
|
||||
private ThirdpartySecretInfoService thirdpartySecretInfoService;
|
||||
|
||||
@Autowired
|
||||
private PileStationInfoService pileStationInfoService;
|
||||
|
||||
@Autowired
|
||||
private PileConnectorInfoService pileConnectorInfoService;
|
||||
|
||||
@Autowired
|
||||
private OrderBasicInfoService orderBasicInfoService;
|
||||
|
||||
@Autowired
|
||||
private RedisCache redisCache;
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
ThirdPartyPlatformFactory.register(thirdPlatformType, this);
|
||||
}
|
||||
|
||||
@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 = getNingXiaJiaoTouSecretInfo();
|
||||
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
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Map<String, String> NXJTQueryStationsInfo(NXJTQueryStationInfoDTO dto) {
|
||||
int pageNo = dto.getPageNo() == null ? 1 : dto.getPageNo();
|
||||
int pageSize = dto.getPageSize() == null ? 10 : dto.getPageSize();
|
||||
|
||||
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getNingXiaJiaoTouSecretInfo();
|
||||
|
||||
// 分页
|
||||
PageUtils.startPage(pageNo, pageSize);
|
||||
List<NXJTStationInfoVO> stationInfos = pileStationInfoService.NXJTQueryStationsInfo(dto);
|
||||
PageInfo<NXJTStationInfoVO> pageInfo = new PageInfo<>(stationInfos);
|
||||
|
||||
Map<String, Object> map = new LinkedHashMap<>();
|
||||
map.put("pageNo", pageInfo.getPageNum());
|
||||
map.put("pageCount", pageInfo.getPages());
|
||||
map.put("itemSize", pageInfo.getList().size());
|
||||
map.put("stationInfos", pageInfo.getList());
|
||||
|
||||
// 加密
|
||||
Map<String, String> resultMap = ThirdPartyPlatformUtils.generateResultMapV2(map, thirdPartySecretInfoVO.getOurDataSecret(),
|
||||
thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret());
|
||||
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询充电站中空闲桩数量
|
||||
* @param dto
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Map<String, String> queryFreePileNumber(NXJTQueryStationInfoDTO dto) {
|
||||
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getNingXiaJiaoTouSecretInfo();
|
||||
|
||||
long stationId = Long.parseLong(dto.getStationId());
|
||||
List<ConnectorInfoVO> connectorList = pileConnectorInfoService.getUniAppConnectorList(stationId);
|
||||
// 先根据pileSn分组,获取设备总数
|
||||
List<String> pileSnList = connectorList.stream()
|
||||
.map(ConnectorInfoVO::getPileSn)
|
||||
.collect(Collectors.toList());
|
||||
// 根据枪口编号批量查询枪口状态
|
||||
Map<String, Integer> pileTypeNum = pileConnectorInfoService.getPileTypeNum(stationId);
|
||||
// Integer fastTotal = pileTypeNum.get("fastTotal");// 快充总数
|
||||
Integer fastFree = pileTypeNum.get("fastFree"); // 快充空闲
|
||||
// Integer slowTotal = pileTypeNum.get("slowTotal");// 慢充总数
|
||||
Integer slowFree = pileTypeNum.get("slowFree");// 慢充空闲
|
||||
|
||||
int freePileNumber = fastFree + slowFree; // 总空闲数量 = 快充空闲 + 慢充空闲
|
||||
int pileNumber = pileSnList.size(); // 总设备数 就是桩号集合的长度
|
||||
|
||||
// 拼装参数
|
||||
Map<String, Object> map = new LinkedHashMap<>();
|
||||
map.put("pileNum", pileNumber);
|
||||
map.put("freePileNum", freePileNumber);
|
||||
|
||||
// 加密
|
||||
Map<String, String> resultMap = ThirdPartyPlatformUtils.generateResultMapV2(map, thirdPartySecretInfoVO.getOurDataSecret(),
|
||||
thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret());
|
||||
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询订单信息
|
||||
* @param dto
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Map<String, String> queryOrdersInfoByPlateNumber(NXJTQueryOrdersInfoDTO dto) {
|
||||
List<NXJTOrderVO> resultList = new ArrayList<>();
|
||||
int pageNo = dto.getPageNo() == null ? 1 : dto.getPageNo();
|
||||
int pageSize = dto.getPageSize() == null ? 10 : dto.getPageSize();
|
||||
|
||||
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getNingXiaJiaoTouSecretInfo();
|
||||
|
||||
// 如果开始时间、结束时间为空,则默认为一个月内
|
||||
if (StringUtils.isBlank(dto.getStartTime()) && StringUtils.isBlank(dto.getEndTime())) {
|
||||
dto.setStartTime(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, DateUtils.addMonths(new Date(), -1)));
|
||||
dto.setEndTime(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, new Date()));
|
||||
}
|
||||
// 分页
|
||||
PageUtils.startPage(pageNo, pageSize);
|
||||
// 根据车牌号查询消费情况
|
||||
List<OrderVO> orderVOList = orderBasicInfoService.getOrderInfoByNXJT(dto);
|
||||
PageInfo<OrderVO> pageInfo = new PageInfo<>(orderVOList);
|
||||
List<OrderVO> list = pageInfo.getList();
|
||||
NXJTOrderVO vo;
|
||||
for (OrderVO orderVO : list) {
|
||||
// 拼装成对接平台所需格式
|
||||
vo = new NXJTOrderVO();
|
||||
vo.setLicensePlateNumber(orderVO.getLicensePlateNumber());
|
||||
vo.setOrderAmount(orderVO.getOrderAmount());
|
||||
vo.setChargeTime(orderVO.getStartTime());
|
||||
vo.setStationName(orderVO.getStationName());
|
||||
vo.setLicensePlateNumberColor(1);
|
||||
|
||||
resultList.add(vo);
|
||||
}
|
||||
Map<String, Object> map = new LinkedHashMap<>();
|
||||
map.put("pageNo", pageInfo.getPageNum());
|
||||
map.put("pageCount", pageInfo.getPages());
|
||||
map.put("itemSize", resultList.size());
|
||||
map.put("orderInfos", resultList);
|
||||
|
||||
// 加密
|
||||
Map<String, String> resultMap = ThirdPartyPlatformUtils.generateResultMapV2(map, thirdPartySecretInfoVO.getOurDataSecret(),
|
||||
thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret());
|
||||
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询指定时间内的订单信息
|
||||
* @param dto
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Map<String, String> queryOrdersInfo(NXJTQueryOrdersInfoDTO dto) {
|
||||
// 由于调用的查询方法、拼装的参数均相同,因此直接调用上面方法
|
||||
// 两个方法仅入参不同
|
||||
return queryOrdersInfoByPlateNumber(dto);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取宁夏交投平台密钥信息
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private ThirdPartySecretInfoVO getNingXiaJiaoTouSecretInfo() {
|
||||
ThirdPartySecretInfoVO thirdPartySecretInfoVO = thirdpartySecretInfoService.queryByThirdPlatformType(thirdPlatformType);
|
||||
if (thirdPartySecretInfoVO == null) {
|
||||
throw new BusinessException(ReturnCodeEnum.CODE_SELECT_INFO_IS_NULL);
|
||||
}
|
||||
thirdPartySecretInfoVO.setOurOperatorId(Constants.OPERATORID_JIANG_SU);
|
||||
return thirdPartySecretInfoVO;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user