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 1f7fd914b..65fb88c82 100644 --- a/jsowell-admin/src/main/java/com/jsowell/service/PileService.java +++ b/jsowell-admin/src/main/java/com/jsowell/service/PileService.java @@ -156,77 +156,71 @@ public class PileService { /** * 前端扫码跳转接口 */ - public AppletPileDetailVO getPileDetailByPileSn(String param) throws Exception{ + public AppletPileDetailVO getPileDetailByPileSn(String param) throws Exception { 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)); - log.info("查询充电枪口详情-supplyAsync-selectConnectorInfoList:{}", connectorInfoListFuture); - - // 查计费模板信息 - CompletableFuture> billingPriceFuture = CompletableFuture.supplyAsync(() -> pileBillingTemplateService.queryBillingPrice(pileInfoVO.getStationId())); - log.info("查询充电枪口详情-supplyAsync-queryBillingPrice:{}", billingPriceFuture); - - // 查询运营商信息 - CompletableFuture merchantInfoVOFuture = CompletableFuture.supplyAsync(() -> pileMerchantInfoService.getMerchantInfoVO(pileInfoVO.getMerchantId())); - log.info("查询充电枪口详情-supplyAsync-getMerchantInfoVO:{}", merchantInfoVOFuture); - - 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); + 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)); + log.info("查询充电枪口详情-supplyAsync-selectConnectorInfoList:{}", connectorInfoListFuture); + + // 查计费模板信息 + CompletableFuture> billingPriceFuture = CompletableFuture.supplyAsync(() -> pileBillingTemplateService.queryBillingPrice(pileInfoVO.getStationId())); + log.info("查询充电枪口详情-supplyAsync-queryBillingPrice:{}", billingPriceFuture); + + // 查询运营商信息 + CompletableFuture merchantInfoVOFuture = CompletableFuture.supplyAsync(() -> pileMerchantInfoService.getMerchantInfoVO(pileInfoVO.getMerchantId())); + log.info("查询充电枪口详情-supplyAsync-getMerchantInfoVO:{}", merchantInfoVOFuture); + + 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(); return vo; } diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileBasicInfoServiceImpl.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileBasicInfoServiceImpl.java index f827db72a..7f9d44269 100644 --- a/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileBasicInfoServiceImpl.java +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileBasicInfoServiceImpl.java @@ -50,6 +50,7 @@ import java.math.BigDecimal; import java.math.RoundingMode; import java.time.LocalDateTime; import java.util.*; +import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; /** @@ -127,17 +128,17 @@ public class PileBasicInfoServiceImpl implements PileBasicInfoService { @Override public PileBasicInfo selectPileBasicInfoBySN(String pileSn) { // 加缓存 - // String redisKey = CacheConstants.SELECT_PILE_BASIC_INFO_BY_SN + pileSn; - // PileBasicInfo pileBasicInfo = redisCache.getCacheObject(redisKey); - // if (pileBasicInfo == null) { - // // 查数据库 - // pileBasicInfo = pileBasicInfoMapper.selectPileBasicInfoBySn(pileSn); - // if (pileBasicInfo != null) { - // redisCache.setCacheObject(redisKey, pileBasicInfo, 15, TimeUnit.MINUTES); - // } - // } + String redisKey = CacheConstants.SELECT_PILE_BASIC_INFO_BY_SN + pileSn; + PileBasicInfo pileBasicInfo = redisCache.getCacheObject(redisKey); + if (pileBasicInfo == null) { + // 查数据库 + pileBasicInfo = pileBasicInfoMapper.selectPileBasicInfoBySn(pileSn); + if (pileBasicInfo != null) { + redisCache.setCacheObject(redisKey, pileBasicInfo, 15, TimeUnit.MINUTES); + } + } - PileBasicInfo pileBasicInfo = pileBasicInfoMapper.selectPileBasicInfoBySn(pileSn); + // PileBasicInfo pileBasicInfo = pileBasicInfoMapper.selectPileBasicInfoBySn(pileSn); return pileBasicInfo; } diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileBillingTemplateServiceImpl.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileBillingTemplateServiceImpl.java index 9d91d2fee..6cd943426 100644 --- a/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileBillingTemplateServiceImpl.java +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileBillingTemplateServiceImpl.java @@ -606,17 +606,17 @@ public class PileBillingTemplateServiceImpl implements PileBillingTemplateServic @Override public List queryStationBillingTemplateListForUniApp(String stationId) { // 加缓存 - // String redisKey = CacheConstants.QUERY_STATION_BILLING_TEMPLATE_LIST + stationId; - // List voList = redisCache.getCacheList(redisKey); - // if (CollectionUtils.isEmpty(voList)) { - // voList = pileBillingTemplateMapper.queryStationBillingTemplateList(stationId); - // if (CollectionUtils.isNotEmpty(voList)) { - // redisCache.setCacheList(redisKey, voList); - // redisCache.expire(redisKey, 15, TimeUnit.MINUTES); - // } - // } + String redisKey = CacheConstants.QUERY_STATION_BILLING_TEMPLATE_LIST + stationId; + List voList = redisCache.getCacheList(redisKey); + if (CollectionUtils.isEmpty(voList)) { + voList = pileBillingTemplateMapper.queryStationBillingTemplateList(stationId); + if (CollectionUtils.isNotEmpty(voList)) { + redisCache.setCacheList(redisKey, voList); + redisCache.expire(redisKey, 15, TimeUnit.MINUTES); + } + } - List voList = pileBillingTemplateMapper.queryStationBillingTemplateList(stationId); + // List voList = pileBillingTemplateMapper.queryStationBillingTemplateList(stationId); return voList; } diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileConnectorInfoServiceImpl.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileConnectorInfoServiceImpl.java index 6a558edda..53889caea 100644 --- a/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileConnectorInfoServiceImpl.java +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileConnectorInfoServiceImpl.java @@ -48,6 +48,7 @@ import java.util.List; import java.util.Map; import java.util.Objects; import java.util.concurrent.CompletableFuture; +import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; /** @@ -119,22 +120,22 @@ public class PileConnectorInfoServiceImpl implements PileConnectorInfoService { @Override public List selectPileConnectorInfoList(String pileSn) { // 取缓存 - // String redisKey = CacheConstants.SELECT_PILE_CONNECTOR_INFO_LIST + pileSn; - // List result = redisCache.getCacheObject(redisKey); - // if (CollectionUtils.isEmpty(result)) { - // // 缓存为空,查数据库 - // PileConnectorInfo pileConnectorInfo = new PileConnectorInfo(); - // pileConnectorInfo.setPileSn(pileSn); - // result = selectPileConnectorInfoList(pileConnectorInfo); - // if (CollectionUtils.isNotEmpty(result)) { - // // 查询数据库不为空,存redis 2分钟 - // redisCache.setCacheObject(redisKey, result, 5, TimeUnit.MINUTES); - // } - // } + String redisKey = CacheConstants.SELECT_PILE_CONNECTOR_INFO_LIST + pileSn; + List result = redisCache.getCacheObject(redisKey); + if (CollectionUtils.isEmpty(result)) { + // 缓存为空,查数据库 + PileConnectorInfo pileConnectorInfo = new PileConnectorInfo(); + pileConnectorInfo.setPileSn(pileSn); + result = selectPileConnectorInfoList(pileConnectorInfo); + if (CollectionUtils.isNotEmpty(result)) { + // 查询数据库不为空,存redis 2分钟 + redisCache.setCacheObject(redisKey, result, 5, TimeUnit.MINUTES); + } + } - PileConnectorInfo pileConnectorInfo = new PileConnectorInfo(); - pileConnectorInfo.setPileSn(pileSn); - List result = selectPileConnectorInfoList(pileConnectorInfo); + // PileConnectorInfo pileConnectorInfo = new PileConnectorInfo(); + // pileConnectorInfo.setPileSn(pileSn); + // List result = selectPileConnectorInfoList(pileConnectorInfo); return result; } diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileModelInfoServiceImpl.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileModelInfoServiceImpl.java index 675c7fd0f..6940245e0 100644 --- a/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileModelInfoServiceImpl.java +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileModelInfoServiceImpl.java @@ -13,6 +13,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.List; +import java.util.Objects; /** * 充电桩型号信息Service业务层处理 @@ -121,16 +122,16 @@ public class PileModelInfoServiceImpl implements PileModelInfoService { @Override public PileModelInfoVO getPileModelInfoByModelId(Long modelId) { - // String redisKey = CacheConstants.GET_PILE_MODEL_INFO_BY_MODEL_ID + modelId; - // PileModelInfoVO modelInfoVO = redisCache.getCacheObject(redisKey); - // if (Objects.isNull(modelInfoVO)) { - // modelInfoVO = pileModelInfoMapper.getPileModelInfoByModelId(modelId); - // if (Objects.nonNull(modelInfoVO)) { - // redisCache.setCacheObject(redisKey, modelInfoVO, CacheConstants.cache_expire_time_1d); - // } - // } + String redisKey = CacheConstants.GET_PILE_MODEL_INFO_BY_MODEL_ID + modelId; + PileModelInfoVO modelInfoVO = redisCache.getCacheObject(redisKey); + if (Objects.isNull(modelInfoVO)) { + modelInfoVO = pileModelInfoMapper.getPileModelInfoByModelId(modelId); + if (Objects.nonNull(modelInfoVO)) { + redisCache.setCacheObject(redisKey, modelInfoVO, CacheConstants.cache_expire_time_1d); + } + } - PileModelInfoVO modelInfoVO = pileModelInfoMapper.getPileModelInfoByModelId(modelId); + // PileModelInfoVO modelInfoVO = pileModelInfoMapper.getPileModelInfoByModelId(modelId); return modelInfoVO; } diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileStationInfoServiceImpl.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileStationInfoServiceImpl.java index 716bc7ad6..7a8c7d655 100644 --- a/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileStationInfoServiceImpl.java +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileStationInfoServiceImpl.java @@ -53,6 +53,7 @@ import java.text.DecimalFormat; import java.time.LocalDate; import java.time.format.DateTimeFormatter; import java.util.*; +import java.util.concurrent.TimeUnit; import java.util.function.Function; import java.util.stream.Collectors; @@ -108,14 +109,14 @@ public class PileStationInfoServiceImpl implements PileStationInfoService { @Override public PileStationInfo selectPileStationInfoById(Long id) { // 加缓存 - // String redisKey = CacheConstants.SELECT_PILE_STATION_INFO_BY_ID + id; - // PileStationInfo pileStationInfo = redisCache.getCacheObject(redisKey); - // if (pileStationInfo == null) { - // // 查数据库 - // pileStationInfo = pileStationInfoMapper.selectPileStationInfoById(id); - // redisCache.setCacheObject(redisKey, pileStationInfo, 15, TimeUnit.MINUTES); - // } - PileStationInfo pileStationInfo = pileStationInfoMapper.selectPileStationInfoById(id); + String redisKey = CacheConstants.SELECT_PILE_STATION_INFO_BY_ID + id; + PileStationInfo pileStationInfo = redisCache.getCacheObject(redisKey); + if (pileStationInfo == null) { + // 查数据库 + pileStationInfo = pileStationInfoMapper.selectPileStationInfoById(id); + redisCache.setCacheObject(redisKey, pileStationInfo, 15, TimeUnit.MINUTES); + } + // PileStationInfo pileStationInfo = pileStationInfoMapper.selectPileStationInfoById(id); return pileStationInfo; }