diff --git a/jsowell-admin/src/main/java/com/jsowell/web/controller/pile/PileBillingTemplateController.java b/jsowell-admin/src/main/java/com/jsowell/web/controller/pile/PileBillingTemplateController.java index b227ddcab..f79142dec 100644 --- a/jsowell-admin/src/main/java/com/jsowell/web/controller/pile/PileBillingTemplateController.java +++ b/jsowell-admin/src/main/java/com/jsowell/web/controller/pile/PileBillingTemplateController.java @@ -134,12 +134,13 @@ public class PileBillingTemplateController extends BaseController { } private void publishBillingTemplate(CreateOrUpdateBillingTemplateDTO dto) { + long l = System.currentTimeMillis(); // 发布计费模板 PublishBillingTemplateDTO publishBillingTemplateDTO = new PublishBillingTemplateDTO(); publishBillingTemplateDTO.setTemplateId(dto.getBillingTemplateId()); publishBillingTemplateDTO.setStationId(dto.getStationId()); - logger.info("新增或者更新后发布计费模板, param:{}", JSON.toJSONString(publishBillingTemplateDTO)); pileRemoteService.publishBillingTemplate(publishBillingTemplateDTO); + logger.info("新增或者更新后发布计费模板, param:{}, 耗时:{}", JSON.toJSONString(publishBillingTemplateDTO), System.currentTimeMillis() - l); } /** diff --git a/jsowell-common/src/main/java/com/jsowell/common/constant/CacheConstants.java b/jsowell-common/src/main/java/com/jsowell/common/constant/CacheConstants.java index 9187b17df..ec0c1f1da 100644 --- a/jsowell-common/src/main/java/com/jsowell/common/constant/CacheConstants.java +++ b/jsowell-common/src/main/java/com/jsowell/common/constant/CacheConstants.java @@ -162,6 +162,11 @@ public class CacheConstants { */ public static final String SELECT_PILE_CONNECTOR_INFO_LIST = "select_pile_connector_info_list:"; + /** + * 充电桩状态前缀 + */ + public static final String PILE_STATUS_KEY = "pile_status:"; + /** * 充电桩枪口状态前缀 */ diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/PileRemoteService.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/PileRemoteService.java index d3bf290c7..f55cfc8ed 100644 --- a/jsowell-pile/src/main/java/com/jsowell/pile/service/PileRemoteService.java +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/PileRemoteService.java @@ -264,7 +264,7 @@ public class PileRemoteService { * 下发充电桩计费模型 */ public void publishPileBillingTemplate(String pileSn, BillingTemplateVO billingTemplateVO) { - + log.info("下发充电桩计费模型, pileSn:{}, threadName:{}", pileSn, Thread.currentThread().getName()); PublishPileBillingTemplateCommand command = PublishPileBillingTemplateCommand.builder() .billingTemplateVO(billingTemplateVO) .pileSn(pileSn) @@ -294,10 +294,11 @@ public class PileRemoteService { if (StringUtils.equals(billingTemplateVO.getDeviceType(), Constants.ONE)) { List pileList = pileBasicInfoService.selectPileListByStationIds(Lists.newArrayList(Long.valueOf(dto.getStationId()))); if (CollectionUtils.isNotEmpty(pileList)) { - for (PileDetailVO pileInfoVO : pileList) { - // 下发计费模板 - publishPileBillingTemplate(pileInfoVO.getPileSn(), billingTemplateVO); - } + // for (PileDetailVO pileInfoVO : pileList) { + // // 下发计费模板 + // publishPileBillingTemplate(pileInfoVO.getPileSn(), billingTemplateVO); + // } + pileList.parallelStream().forEach(pileInfoVO -> publishPileBillingTemplate(pileInfoVO.getPileSn(), billingTemplateVO)); } } 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 5be79fcef..0903a1aad 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 @@ -46,6 +46,7 @@ import org.apache.commons.lang3.RandomStringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; +import org.springframework.util.StopWatch; import java.math.BigDecimal; import java.math.RoundingMode; @@ -493,16 +494,22 @@ public class PileBasicInfoServiceImpl implements PileBasicInfoService { @Override public List selectPileListByStationIds(List stationIdList) { + StopWatch sw = new StopWatch("selectPileListByStationIds"); // 加缓存 + sw.start("根据stationIdList查询桩列表"); List pileInfoVOS = pileBasicInfoMapper.selectPileListByStationIds(stationIdList); if (CollectionUtils.isEmpty(pileInfoVOS)) { return Lists.newArrayList(); } + sw.stop(); + sw.start("获取桩状态"); List pileSnList = pileInfoVOS.stream().map(PileDetailVO::getPileSn).collect(Collectors.toList()); Map pileStatusMap = pileConnectorInfoService.getPileStatus(pileSnList); for (PileDetailVO pileInfoVO : pileInfoVOS) { pileInfoVO.setStatus(pileStatusMap.get(pileInfoVO.getPileSn())); } + sw.stop(); + log.info("selectPileListByStationIds 耗时:{}, 详细:{}", sw.getTotalTimeMillis(), sw.prettyPrint()); return pileInfoVOS; } 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 b48c36d27..eaca49e37 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 @@ -42,7 +42,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; import org.springframework.stereotype.Service; -import org.springframework.util.StopWatch; import java.math.BigDecimal; import java.util.LinkedHashMap; @@ -134,11 +133,10 @@ public class PileConnectorInfoServiceImpl implements PileConnectorInfoService { pileConnectorInfo.setPileSn(pileSn); result = selectPileConnectorInfoList(pileConnectorInfo); if (CollectionUtils.isNotEmpty(result)) { - // 查询数据库不为空,存redis 2分钟 + // 查询数据库不为空,存redis 5分钟 redisCache.setCacheObject(redisKey, result, 5, TimeUnit.MINUTES); } } - // PileConnectorInfo pileConnectorInfo = new PileConnectorInfo(); // pileConnectorInfo.setPileSn(pileSn); // List result = selectPileConnectorInfoList(pileConnectorInfo); @@ -660,11 +658,9 @@ public class PileConnectorInfoServiceImpl implements PileConnectorInfoService { */ @Override public Map getPileStatus(List pileSnList) { - StopWatch watch = new StopWatch("批量获取桩状态"); Map resultMap = Maps.newHashMap(); for (String pileSn : pileSnList) { String pileStatus = ""; - // 标识桩故障或者离线 boolean flag = false; // 判断故障状态 @@ -675,13 +671,11 @@ public class PileConnectorInfoServiceImpl implements PileConnectorInfoService { pileStatus = PileStatusEnum.FAULT.getValue(); flag = true; } - // 判断离线状态 显示优先级 离线>故障 // if (checkPileOffLine(pileSn)) { // pileStatus = PileStatusEnum.OFF_LINE.getValue(); // flag = true; // } - // 2023年1月10日11点32分 改成如果枪口离线,那么充电桩就是离线 if (connectorStatusList.contains(PileConnectorDataBaseStatusEnum.OFF_NETWORK.getValue())) { pileStatus = PileStatusEnum.OFF_LINE.getValue(); @@ -691,17 +685,24 @@ public class PileConnectorInfoServiceImpl implements PileConnectorInfoService { orderBasicInfoService.updateOrderStatusAsAbnormal(pileSn); }, executor); } - // 没有故障或者离线,就是在线状态 if (!flag) { pileStatus = PileStatusEnum.ON_LINE.getValue(); } - resultMap.put(pileSn, pileStatus); } return resultMap; } + /** + * 优化批量获取桩状态 + * @param pileSnList 桩编号列表 + * @return key:桩编号; value:状态 + */ + public Map getPileStatusV2(List pileSnList) { + return null; + } + @Override public PileConnectorInfoVO getPileConnectorInfoByConnectorCode(String pileConnectorCode) { return pileConnectorInfoMapper.getPileConnectorInfoByConnectorCode(pileConnectorCode); @@ -713,6 +714,7 @@ public class PileConnectorInfoServiceImpl implements PileConnectorInfoService { * @param pileSn 桩编号 * @return true离线 */ + @Override public boolean checkPileOffLine(String pileSn) { // 获取桩最后连接时间,最后连接到平台的时间在3分钟之前,判定为离线 String lastConnectionTime = redisCache.getCacheObject(CacheConstants.PILE_LAST_CONNECTION + pileSn); diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/YKCPushCommandServiceImpl.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/YKCPushCommandServiceImpl.java index 981d8b094..f01dff181 100644 --- a/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/YKCPushCommandServiceImpl.java +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/YKCPushCommandServiceImpl.java @@ -424,9 +424,9 @@ public class YKCPushCommandServiceImpl implements YKCPushCommandService { // 发送 if (messageBody != null) { try { - this.supplySend(messageBody, pileSn, YKCFrameTypeCode.BILLING_TEMPLATE_SETTING_CODE); + this.runSend(messageBody, pileSn, YKCFrameTypeCode.BILLING_TEMPLATE_SETTING_CODE); } catch (Exception e) { - log.error("向充电桩发送计费模板error", e); + log.error("向充电桩发送计费模板error: {}", e.getMessage()); } } }