From 5d9204137c32e7dfccf75bc123791af6379d3c76 Mon Sep 17 00:00:00 2001 From: Lemon Date: Thu, 20 Feb 2025 11:39:07 +0800 Subject: [PATCH] =?UTF-8?q?update=20=20=E5=AE=81=E5=A4=8F=E4=BA=A4?= =?UTF-8?q?=E6=8A=95=E5=B9=B3=E5=8F=B0Service?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/thirdparty/NXJTController.java | 182 ++++++------- .../service/ThirdPartyPlatformService.java | 14 +- .../NingXiaJiaoTouPlatformServiceImpl.java | 245 ++++++++++++++++++ 3 files changed, 339 insertions(+), 102 deletions(-) diff --git a/jsowell-admin/src/main/java/com/jsowell/api/thirdparty/NXJTController.java b/jsowell-admin/src/main/java/com/jsowell/api/thirdparty/NXJTController.java index 2325edb6d..8b0ad773b 100644 --- a/jsowell-admin/src/main/java/com/jsowell/api/thirdparty/NXJTController.java +++ b/jsowell-admin/src/main/java/com/jsowell/api/thirdparty/NXJTController.java @@ -4,16 +4,21 @@ import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSONObject; import com.jsowell.common.annotation.Anonymous; import com.jsowell.common.core.controller.BaseController; +import com.jsowell.common.enums.thirdparty.ThirdPartyReturnCodeEnum; +import com.jsowell.common.enums.thirdparty.ThirdPlatformTypeEnum; import com.jsowell.common.util.JWTUtils; +import com.jsowell.pile.dto.QueryStationInfoDTO; import com.jsowell.pile.dto.ningxiajiaotou.NXJTQueryOrdersInfoDTO; import com.jsowell.pile.dto.ningxiajiaotou.NXJTQueryStationInfoDTO; import com.jsowell.thirdparty.lianlian.common.CommonResult; import com.jsowell.pile.thirdparty.CommonParamsDTO; import com.jsowell.thirdparty.lianlian.service.LianLianService; +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.ningxiajiaotou.service.NXJTService; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; @@ -33,13 +38,15 @@ import java.util.Map; @Anonymous @RestController @RequestMapping("/nxjt") -public class NXJTController extends BaseController { +public class NXJTController extends ThirdPartyBaseController { + + private final String platformName = "宁夏交投平台"; + + private final String platformType = ThirdPlatformTypeEnum.NING_XIA_JIAO_TOU.getTypeCode(); @Autowired - private NXJTService nxjtService; - - @Autowired - private LianLianService lianLianService; + @Qualifier("ningXiaJiaoTouPlatformServiceImpl") + private ThirdPartyPlatformService platformLogic; /** * 获取token接口 @@ -47,13 +54,12 @@ public class NXJTController extends BaseController { */ @PostMapping("/v1/query_token") public CommonResult queryToken(@RequestBody CommonParamsDTO dto) { - logger.info("宁夏交投平台请求令牌 params:{}", JSON.toJSONString(dto)); try { - Map map = nxjtService.generateToken(dto); - logger.info("宁夏交投平台请求令牌 result:{}", JSON.toJSONString(map)); - return CommonResult.success(0, "请求令牌成功!", map.get("Data"), map.get("Sig")); - } catch (UnsupportedEncodingException e) { - logger.error("获取token接口 异常"); + Map map = platformLogic.queryToken(dto); + logger.info("{}-请求令牌, params:{}, result:{}", platformName, JSON.toJSONString(dto), JSON.toJSONString(map)); + return CommonResult.success(Integer.parseInt(map.get("Ret")), map.get("Msg"), map.get("Data"), map.get("Sig")); + } catch (Exception e) { + logger.error("{}-获取token接口, 异常, params:{}", platformName, JSON.toJSONString(dto), e); return CommonResult.failed("获取token发生异常"); } } @@ -66,36 +72,30 @@ public class NXJTController extends BaseController { */ @PostMapping("/v1/query_stations_info") public CommonResult queryStationsInfo(HttpServletRequest request, @RequestBody CommonParamsDTO dto) { - logger.info("宁夏交投平台查询充电站信息 params:{}", JSON.toJSONString(dto)); + logger.info("{}-查询充电站信息 params:{}", platformName, JSON.toJSONString(dto)); try { // 校验令牌 - String token = request.getHeader("Authorization"); - if (!JWTUtils.checkThirdPartyToken(token)) { + if (!verifyToken(request.getHeader("Authorization"))) { // 校验失败 - return CommonResult.failed("令牌校验错误"); + return CommonResult.failed(ThirdPartyReturnCodeEnum.TOKEN_ERROR); } + dto.setPlatformType(platformType); + // 校验签名 - Map resultMap = lianLianService.checkoutSign(dto); - if (resultMap == null) { + if (!verifySignature(dto)) { // 签名错误 - return CommonResult.failed("签名校验错误"); + return CommonResult.failed(ThirdPartyReturnCodeEnum.SIGN_ERROR); } - String operatorSecret = resultMap.get("OperatorSecret"); - String dataString = resultMap.get("Data"); - String dataSecret = resultMap.get("DataSecret"); - String dataSecretIV = resultMap.get("DataSecretIV"); - // 解密data - byte[] plainText = Cryptos.aesDecrypt(Encodes.decodeBase64(dataString), dataSecret.getBytes(), dataSecretIV.getBytes()); - String dataStr = new String(plainText, StandardCharsets.UTF_8); - // 转换成相应对象 - NXJTQueryStationInfoDTO nxjtQueryStationInfoDTO = JSONObject.parseObject(dataStr, NXJTQueryStationInfoDTO.class); - nxjtQueryStationInfoDTO.setOperatorId(dto.getOperatorID()); - Map map = nxjtService.queryStationsInfo(nxjtQueryStationInfoDTO); - // return CommonResult.success(map); - return CommonResult.success(0, "查询充电站信息成功!", map.get("Data"), map.get("Sig")); + + // 解析入参 + NXJTQueryStationInfoDTO nxjtQueryStationInfoDTO = parseParamsDTO(dto, NXJTQueryStationInfoDTO.class); + + // 执行逻辑 + Map map = platformLogic.NXJTQueryStationsInfo(nxjtQueryStationInfoDTO); + + return CommonResult.success(Integer.parseInt(map.get("Ret")), map.get("Msg"), map.get("Data"), map.get("Sig")); } catch (Exception e) { - logger.info("宁夏交投平台查询充电站信息 error:", e); - e.printStackTrace(); + logger.info("{}-查询充电站信息 error:", platformName, e); } return CommonResult.failed("查询充电站信息发生异常"); } @@ -109,38 +109,32 @@ public class NXJTController extends BaseController { */ @PostMapping("/v1/query_free_pile_number") public CommonResult queryFreePileNumber(HttpServletRequest request, @RequestBody CommonParamsDTO dto) { - logger.info("宁夏交投平台查询充电站中空闲桩数量 params:{}", JSON.toJSONString(dto)); + logger.info("{}-查询充电站中空闲桩数量 params:{}", platformName, JSON.toJSONString(dto)); try { // 校验令牌 - String token = request.getHeader("Authorization"); - if (!JWTUtils.checkThirdPartyToken(token)) { + if (!verifyToken(request.getHeader("Authorization"))) { // 校验失败 - return CommonResult.failed("令牌校验错误"); + return CommonResult.failed(ThirdPartyReturnCodeEnum.TOKEN_ERROR); } + dto.setPlatformType(platformType); + // 校验签名 - Map resultMap = lianLianService.checkoutSign(dto); - if (resultMap == null) { + if (!verifySignature(dto)) { // 签名错误 - return CommonResult.failed("签名校验错误"); + return CommonResult.failed(ThirdPartyReturnCodeEnum.SIGN_ERROR); } - String operatorSecret = resultMap.get("OperatorSecret"); - String dataString = resultMap.get("Data"); - String dataSecret = resultMap.get("DataSecret"); - String dataSecretIV = resultMap.get("DataSecretIV"); - // 解密data - byte[] plainText = Cryptos.aesDecrypt(Encodes.decodeBase64(dataString), dataSecret.getBytes(), dataSecretIV.getBytes()); - String dataStr = new String(plainText, StandardCharsets.UTF_8); - // 转换成相应对象 - NXJTQueryStationInfoDTO nxjtQueryStationInfoDTO = JSONObject.parseObject(dataStr, NXJTQueryStationInfoDTO.class); - nxjtQueryStationInfoDTO.setOperatorId(dto.getOperatorID()); - Map map = nxjtService.queryFreePileNumber(nxjtQueryStationInfoDTO); - // return CommonResult.success(map); - return CommonResult.success(0, "查询充电站中空闲桩数量信息成功!", map.get("Data"), map.get("Sig")); + + // 解析入参 + NXJTQueryStationInfoDTO nxjtQueryStationInfoDTO = parseParamsDTO(dto, NXJTQueryStationInfoDTO.class); + + // 执行逻辑 + Map map = platformLogic.queryFreePileNumber(nxjtQueryStationInfoDTO); + + return CommonResult.success(Integer.parseInt(map.get("Ret")), map.get("Msg"), map.get("Data"), map.get("Sig")); } catch (Exception e) { - logger.info("宁夏交投平台查询充电站中空闲桩数量 error:", e); - e.printStackTrace(); + logger.info("{}-查询充电站中空闲桩数量 error:", platformName, e); } - return CommonResult.failed("查询充电站中空闲桩数量信息发生异常"); + return CommonResult.failed("查询充电站中空闲桩数量发生异常"); } /** @@ -151,36 +145,30 @@ public class NXJTController extends BaseController { */ @PostMapping("/v1/query_orders_info_by_Plate_number") public CommonResult queryOrdersInfoByPlateNumber(HttpServletRequest request, @RequestBody CommonParamsDTO dto) { - logger.info("宁夏交投平台查询某车牌号消费记录 params:{}", JSON.toJSONString(dto)); + logger.info("{}-查询某车牌号消费记录 params:{}", platformName, JSON.toJSONString(dto)); try { // 校验令牌 - String token = request.getHeader("Authorization"); - if (!JWTUtils.checkThirdPartyToken(token)) { + if (!verifyToken(request.getHeader("Authorization"))) { // 校验失败 - return CommonResult.failed("令牌校验错误"); + return CommonResult.failed(ThirdPartyReturnCodeEnum.TOKEN_ERROR); } + dto.setPlatformType(platformType); + // 校验签名 - Map resultMap = lianLianService.checkoutSign(dto); - if (resultMap == null) { + if (!verifySignature(dto)) { // 签名错误 - return CommonResult.failed("签名校验错误"); + return CommonResult.failed(ThirdPartyReturnCodeEnum.SIGN_ERROR); } - String operatorSecret = resultMap.get("OperatorSecret"); - String dataString = resultMap.get("Data"); - String dataSecret = resultMap.get("DataSecret"); - String dataSecretIV = resultMap.get("DataSecretIV"); - // 解密data - byte[] plainText = Cryptos.aesDecrypt(Encodes.decodeBase64(dataString), dataSecret.getBytes(), dataSecretIV.getBytes()); - String dataStr = new String(plainText, StandardCharsets.UTF_8); - // 转换成相应对象 - NXJTQueryOrdersInfoDTO nxjtQueryOrdersInfoDTO = JSONObject.parseObject(dataStr, NXJTQueryOrdersInfoDTO.class); - nxjtQueryOrdersInfoDTO.setOperatorId(dto.getOperatorID()); - Map map = nxjtService.queryOrdersInfoByPlateNumber(nxjtQueryOrdersInfoDTO); - // return CommonResult.success(map); - return CommonResult.success(0, "查询充电站中空闲桩数量信息成功!", map.get("Data"), map.get("Sig")); + + // 解析入参 + NXJTQueryOrdersInfoDTO nxjtQueryOrdersInfoDTO = parseParamsDTO(dto, NXJTQueryOrdersInfoDTO.class); + + // 执行逻辑 + Map map = platformLogic.queryOrdersInfoByPlateNumber(nxjtQueryOrdersInfoDTO); + + return CommonResult.success(Integer.parseInt(map.get("Ret")), map.get("Msg"), map.get("Data"), map.get("Sig")); } catch (Exception e) { - logger.info("宁夏交投平台查询某车牌号消费记录 error:", e); - e.printStackTrace(); + logger.info("{}-查询某车牌号消费记录 error:", platformName, e); } return CommonResult.failed("查询某车牌号消费记录发生异常"); } @@ -194,36 +182,30 @@ public class NXJTController extends BaseController { */ @PostMapping("/v1/query_orders_info") public CommonResult queryOrdersInfo(HttpServletRequest request, @RequestBody CommonParamsDTO dto) { - logger.info("宁夏交投平台查询某段时间内消费记录 params:{}", JSON.toJSONString(dto)); + logger.info("{}-查询某段时间内消费记录 params:{}", platformName, JSON.toJSONString(dto)); try { // 校验令牌 - String token = request.getHeader("Authorization"); - if (!JWTUtils.checkThirdPartyToken(token)) { + if (!verifyToken(request.getHeader("Authorization"))) { // 校验失败 - return CommonResult.failed("令牌校验错误"); + return CommonResult.failed(ThirdPartyReturnCodeEnum.TOKEN_ERROR); } + dto.setPlatformType(platformType); + // 校验签名 - Map resultMap = lianLianService.checkoutSign(dto); - if (resultMap == null) { + if (!verifySignature(dto)) { // 签名错误 - return CommonResult.failed("签名校验错误"); + return CommonResult.failed(ThirdPartyReturnCodeEnum.SIGN_ERROR); } - String operatorSecret = resultMap.get("OperatorSecret"); - String dataString = resultMap.get("Data"); - String dataSecret = resultMap.get("DataSecret"); - String dataSecretIV = resultMap.get("DataSecretIV"); - // 解密data - byte[] plainText = Cryptos.aesDecrypt(Encodes.decodeBase64(dataString), dataSecret.getBytes(), dataSecretIV.getBytes()); - String dataStr = new String(plainText, StandardCharsets.UTF_8); - // 转换成相应对象 - NXJTQueryOrdersInfoDTO nxjtQueryOrdersInfoDTO = JSONObject.parseObject(dataStr, NXJTQueryOrdersInfoDTO.class); - nxjtQueryOrdersInfoDTO.setOperatorId(dto.getOperatorID()); - Map map = nxjtService.queryOrdersInfo(nxjtQueryOrdersInfoDTO); - // return CommonResult.success(map); - return CommonResult.success(0, "查询充电站中空闲桩数量信息成功!", map.get("Data"), map.get("Sig")); + + // 解析入参 + NXJTQueryOrdersInfoDTO nxjtQueryOrdersInfoDTO = parseParamsDTO(dto, NXJTQueryOrdersInfoDTO.class); + + // 执行逻辑 + Map map = platformLogic.queryOrdersInfo(nxjtQueryOrdersInfoDTO); + + return CommonResult.success(Integer.parseInt(map.get("Ret")), map.get("Msg"), map.get("Data"), map.get("Sig")); } catch (Exception e) { - logger.info("宁夏交投平台查询某段时间内消费记录 error:", e); - e.printStackTrace(); + logger.info("{}-查询某段时间内消费记录 error:", platformName, e); } return CommonResult.failed("查询某段时间内消费记录发生异常"); } diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/ThirdPartyPlatformService.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/ThirdPartyPlatformService.java index 51e76a294..8b1551d17 100644 --- a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/ThirdPartyPlatformService.java +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/ThirdPartyPlatformService.java @@ -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 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 queryOrdersInfoByPlateNumber(NXJTQueryStationInfoDTO dto) { + default Map 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 queryOrdersInfo(NXJTQueryStationInfoDTO dto) { + default Map queryOrdersInfo(NXJTQueryOrdersInfoDTO dto) { throw new UnsupportedOperationException("This method is not yet implemented"); } diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/NingXiaJiaoTouPlatformServiceImpl.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/NingXiaJiaoTouPlatformServiceImpl.java index 05afdcd14..010dd1cfc 100644 --- a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/NingXiaJiaoTouPlatformServiceImpl.java +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/NingXiaJiaoTouPlatformServiceImpl.java @@ -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 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 resultMap = ThirdPartyPlatformUtils.generateResultMapV2(vo, thirdPartySecretInfoVO.getOurDataSecret() + , thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getOurSigSecret()); + return resultMap; + } + + /** + * 查询站点信息 query_stations_info + * @param dto + * @return + */ + @Override + public Map 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 stationInfos = pileStationInfoService.NXJTQueryStationsInfo(dto); + PageInfo pageInfo = new PageInfo<>(stationInfos); + + Map 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 resultMap = ThirdPartyPlatformUtils.generateResultMapV2(map, thirdPartySecretInfoVO.getOurDataSecret(), + thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret()); + + return resultMap; + } + + /** + * 查询充电站中空闲桩数量 + * @param dto + * @return + */ + @Override + public Map queryFreePileNumber(NXJTQueryStationInfoDTO dto) { + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getNingXiaJiaoTouSecretInfo(); + + long stationId = Long.parseLong(dto.getStationId()); + List connectorList = pileConnectorInfoService.getUniAppConnectorList(stationId); + // 先根据pileSn分组,获取设备总数 + List pileSnList = connectorList.stream() + .map(ConnectorInfoVO::getPileSn) + .collect(Collectors.toList()); + // 根据枪口编号批量查询枪口状态 + Map 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 map = new LinkedHashMap<>(); + map.put("pileNum", pileNumber); + map.put("freePileNum", freePileNumber); + + // 加密 + Map resultMap = ThirdPartyPlatformUtils.generateResultMapV2(map, thirdPartySecretInfoVO.getOurDataSecret(), + thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret()); + + return resultMap; + } + + /** + * 查询订单信息 + * @param dto + * @return + */ + @Override + public Map queryOrdersInfoByPlateNumber(NXJTQueryOrdersInfoDTO dto) { + List 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 orderVOList = orderBasicInfoService.getOrderInfoByNXJT(dto); + PageInfo pageInfo = new PageInfo<>(orderVOList); + List 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 map = new LinkedHashMap<>(); + map.put("pageNo", pageInfo.getPageNum()); + map.put("pageCount", pageInfo.getPages()); + map.put("itemSize", resultList.size()); + map.put("orderInfos", resultList); + + // 加密 + Map resultMap = ThirdPartyPlatformUtils.generateResultMapV2(map, thirdPartySecretInfoVO.getOurDataSecret(), + thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret()); + + return resultMap; + } + + /** + * 查询指定时间内的订单信息 + * @param dto + * @return + */ + @Override + public Map 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; + } }