diff --git a/jsowell-admin/src/main/java/com/jsowell/service/PileService.java b/jsowell-admin/src/main/java/com/jsowell/service/PileService.java index 28848ed1f..2f115bdcc 100644 --- a/jsowell-admin/src/main/java/com/jsowell/service/PileService.java +++ b/jsowell-admin/src/main/java/com/jsowell/service/PileService.java @@ -157,67 +157,73 @@ public class PileService { * 前端扫码跳转接口 */ public AppletPileDetailVO getPileDetailByPileSn(String param) throws Exception{ - log.info("查询充电枪口详情-getPileDetailByPileSn, param:{}", param); - if (StringUtils.isBlank(param)) { - throw new BusinessException(ReturnCodeEnum.CODE_PARAM_NOT_NULL_ERROR); - } - String pileSn = YKCUtils.getPileSn(param); - log.info("查询充电枪口详情-getPileDetailByPileSn, pileSn:{}", pileSn); - // 查询充电桩信息 - PileInfoVO pileInfoVO = pileBasicInfoService.selectPileInfoBySn(pileSn); - log.info("查询充电枪口详情-pileInfoVO:{}", JSON.toJSONString(pileInfoVO)); - if (pileInfoVO == null) { - return null; + AppletPileDetailVO vo = null; + try { + log.info("查询充电枪口详情-getPileDetailByPileSn, param:{}", param); + if (StringUtils.isBlank(param)) { + throw new BusinessException(ReturnCodeEnum.CODE_PARAM_NOT_NULL_ERROR); + } + String pileSn = YKCUtils.getPileSn(param); + log.info("查询充电枪口详情-getPileDetailByPileSn, pileSn:{}", pileSn); + // 查询充电桩信息 + PileInfoVO pileInfoVO = pileBasicInfoService.selectPileInfoBySn(pileSn); + log.info("查询充电枪口详情-pileInfoVO:{}", JSON.toJSONString(pileInfoVO)); + if (pileInfoVO == null) { + return null; + } + + // 判断桩是否在线 + boolean onLineStatus = pileConnectorInfoService.checkPileOffLine(pileInfoVO.getPileSn()); + log.info("查询充电枪口详情-判断桩是否在线:{}, onLineStatus:{}", pileInfoVO.getPileSn(), onLineStatus); + if (onLineStatus) { + // true为离线 + throw new BusinessException(ReturnCodeEnum.CODE_PILE_CONNECTOR_STATUS_OFF_LINE); + } + + // 查询站点信息 + PileStationVO stationInfo = pileStationInfoService.getStationInfo(pileInfoVO.getStationId()); + log.info("查询充电枪口详情-getStationInfo:{}, onLineStatus:{}", pileInfoVO.getStationId(), JSON.toJSONString(stationInfo)); + if (stationInfo == null || StringUtils.equals(stationInfo.getOpenFlag(), Constants.ZERO)) { + throw new BusinessException(ReturnCodeEnum.CODE_STATION_IS_NOT_OPEN); + } + + // 查询充电桩下枪口信息 + CompletableFuture> connectorInfoListFuture = CompletableFuture.supplyAsync(() -> pileConnectorInfoService.selectConnectorInfoList(pileSn)); + + // 查计费模板信息 + CompletableFuture> billingPriceFuture = CompletableFuture.supplyAsync(() -> pileBillingTemplateService.queryBillingPrice(pileInfoVO.getStationId())); + + // 查询运营商信息 + CompletableFuture merchantInfoVOFuture = CompletableFuture.supplyAsync(() -> pileMerchantInfoService.getMerchantInfoVO(pileInfoVO.getMerchantId())); + + CompletableFuture all = CompletableFuture.allOf(connectorInfoListFuture, merchantInfoVOFuture, billingPriceFuture); + // .join()和.get()都会阻塞并获取线程的执行情况 + // .join()会抛出未经检查的异常,不会强制开发者处理异常 .get()会抛出检查异常,需要开发者处理 + all.join(); + all.get(); + List connectorInfoList = connectorInfoListFuture.get(); + // List connectorInfoList = pileConnectorInfoService.selectConnectorInfoList(pileSn); + log.info("查询充电枪口详情-connectorInfoList:{}", JSON.toJSONString(connectorInfoList)); + // PileStationVO pileStationVO = pileStationVOFuture.get(); + MerchantInfoVO merchantInfoVO = merchantInfoVOFuture.get(); + // List billingPriceVOS= pileBillingTemplateService.queryBillingPrice(pileInfoVO.getStationId()); + log.info("查询充电枪口详情-merchantInfoVO:{}", JSON.toJSONString(merchantInfoVO)); + List billingPriceVOS = billingPriceFuture.get(); + // MerchantInfoVO merchantInfoVO = pileMerchantInfoService.getMerchantInfoVO(pileInfoVO.getMerchantId()); + log.info("查询充电枪口详情-billingPriceVOS:{}", JSON.toJSONString(billingPriceVOS)); + + + vo = AppletPileDetailVO.builder() + .pileInfo(pileInfoVO) + .connectorInfoList(connectorInfoList) + .merchantInfo(merchantInfoVO) + .stationInfo(stationInfo) + .billingPriceList(billingPriceVOS) + .build(); + } catch (Exception e) { + log.error("查询充电枪详情error", e); } - // 判断桩是否在线 - boolean onLineStatus = pileConnectorInfoService.checkPileOffLine(pileInfoVO.getPileSn()); - log.info("查询充电枪口详情-判断桩是否在线:{}, onLineStatus:{}", pileInfoVO.getPileSn(), onLineStatus); - if (onLineStatus) { - // true为离线 - throw new BusinessException(ReturnCodeEnum.CODE_PILE_CONNECTOR_STATUS_OFF_LINE); - } - - // 查询站点信息 - PileStationVO stationInfo = pileStationInfoService.getStationInfo(pileInfoVO.getStationId()); - log.info("查询充电枪口详情-getStationInfo:{}, onLineStatus:{}", pileInfoVO.getStationId(), JSON.toJSONString(stationInfo)); - if (stationInfo == null || StringUtils.equals(stationInfo.getOpenFlag(), Constants.ZERO)) { - throw new BusinessException(ReturnCodeEnum.CODE_STATION_IS_NOT_OPEN); - } - - // 查询充电桩下枪口信息 - CompletableFuture> connectorInfoListFuture = CompletableFuture.supplyAsync(() -> pileConnectorInfoService.selectConnectorInfoList(pileSn)); - - // 查计费模板信息 - CompletableFuture> billingPriceFuture = CompletableFuture.supplyAsync(() -> pileBillingTemplateService.queryBillingPrice(pileInfoVO.getStationId())); - - // 查询运营商信息 - CompletableFuture merchantInfoVOFuture = CompletableFuture.supplyAsync(() -> pileMerchantInfoService.getMerchantInfoVO(pileInfoVO.getMerchantId())); - - CompletableFuture all = CompletableFuture.allOf(connectorInfoListFuture, merchantInfoVOFuture, billingPriceFuture); - // .join()和.get()都会阻塞并获取线程的执行情况 - // .join()会抛出未经检查的异常,不会强制开发者处理异常 .get()会抛出检查异常,需要开发者处理 - all.join(); - all.get(); - List connectorInfoList = connectorInfoListFuture.get(); - // List connectorInfoList = pileConnectorInfoService.selectConnectorInfoList(pileSn); - log.info("查询充电枪口详情-connectorInfoList:{}", JSON.toJSONString(connectorInfoList)); - // PileStationVO pileStationVO = pileStationVOFuture.get(); - MerchantInfoVO merchantInfoVO = merchantInfoVOFuture.get(); - // List billingPriceVOS= pileBillingTemplateService.queryBillingPrice(pileInfoVO.getStationId()); - log.info("查询充电枪口详情-merchantInfoVO:{}", JSON.toJSONString(merchantInfoVO)); - List billingPriceVOS = billingPriceFuture.get(); - // MerchantInfoVO merchantInfoVO = pileMerchantInfoService.getMerchantInfoVO(pileInfoVO.getMerchantId()); - log.info("查询充电枪口详情-billingPriceVOS:{}", JSON.toJSONString(billingPriceVOS)); - - - AppletPileDetailVO vo = AppletPileDetailVO.builder() - .pileInfo(pileInfoVO) - .connectorInfoList(connectorInfoList) - .merchantInfo(merchantInfoVO) - .stationInfo(stationInfo) - .billingPriceList(billingPriceVOS) - .build(); return vo; }