From 9df8374c79a1baa38aa903373fac5649e5007836 Mon Sep 17 00:00:00 2001 From: 潘志宝 <979469083@qq.com> Date: 星期四, 14 十一月 2024 18:10:44 +0800 Subject: [PATCH] 增加缓存 --- iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/point/DataPointApiImpl.java | 4 ++-- iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/controller/admin/ApiDataController.java | 4 ++-- iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/service/impl/DaPointServiceImpl.java | 21 ++++++++++++++++----- iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/api/point/dto/ApiPointValueDTO.java | 4 ++-- 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/api/point/dto/ApiPointValueDTO.java b/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/api/point/dto/ApiPointValueDTO.java index fc12d2d..4a62783 100644 --- a/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/api/point/dto/ApiPointValueDTO.java +++ b/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/api/point/dto/ApiPointValueDTO.java @@ -16,7 +16,7 @@ private static final long serialVersionUID = 1L; @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") - private Date dataTime; + private Date t; - private double dataValue; + private double v; } \ No newline at end of file diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/controller/admin/ApiDataController.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/controller/admin/ApiDataController.java index d5a4c21..3ed05e1 100644 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/controller/admin/ApiDataController.java +++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/controller/admin/ApiDataController.java @@ -151,8 +151,8 @@ queryDto.setPointNo(item.getPointNo()); List<ApiPointValueDTO> list = dataPointApi.queryPointHistoryValue(queryDto); List<Object[]> sData = list.stream().map(dataItem -> { - Object[] valueArray = new Object[]{DateUtils.format(dataItem.getDataTime(), DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND), - getFormatValue(item.getDataType(), dataItem.getDataValue())}; + Object[] valueArray = new Object[]{DateUtils.format(dataItem.getT(), DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND), + getFormatValue(item.getDataType(), dataItem.getV())}; return valueArray; }).collect(Collectors.toList()); seriesItem.setData(sData); diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/point/DataPointApiImpl.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/point/DataPointApiImpl.java index 64cc9a6..dd9b84a 100644 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/point/DataPointApiImpl.java +++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/point/DataPointApiImpl.java @@ -88,8 +88,8 @@ List<ApiPointValueDTO> pointValueList = new ArrayList<>(); for (int i = 0; list.size() - i >= 1; i++) { ApiPointValueDTO pointValue = new ApiPointValueDTO(); - pointValue.setDataValue(Double.parseDouble(list.get(i).get(InfluxDBServiceImpl.VALUE).toString())); - pointValue.setDataTime(DateUtils.parse(list.get(i).get(InfluxDBServiceImpl.TIME).toString(), DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)); + pointValue.setV(Double.parseDouble(list.get(i).get(InfluxDBServiceImpl.VALUE).toString())); + pointValue.setT(DateUtils.parse(list.get(i).get(InfluxDBServiceImpl.TIME).toString(), DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)); pointValueList.add(pointValue); } return pointValueList; diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/service/impl/DaPointServiceImpl.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/service/impl/DaPointServiceImpl.java index 42ea9ae..3310495 100644 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/service/impl/DaPointServiceImpl.java +++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/service/impl/DaPointServiceImpl.java @@ -26,13 +26,13 @@ import com.iailab.module.data.point.vo.DaPointPageReqVO; import com.iailab.module.data.point.vo.PointImportExcelVO; import com.iailab.module.data.point.vo.PointImportRespVO; -import com.iailab.module.infra.api.config.ConfigApi; import org.apache.commons.lang3.ObjectUtils; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; import javax.annotation.Resource; import java.util.*; +import java.util.concurrent.ConcurrentHashMap; import static com.iailab.framework.common.exception.util.ServiceExceptionUtil.exception; import static com.iailab.module.data.enums.ErrorCodeConstants.POINT_EXISTS; @@ -59,10 +59,9 @@ private DaPointDao daPointDao; @Resource - private ConfigApi configApi; - - @Resource private ChannelSourceService channelSourceService; + + private static Map<String, DaPointDTO> pointNoMap = new ConcurrentHashMap<>(); @Override public PageResult<DaPointDTO> queryPage(DaPointPageReqVO reqVO) { @@ -149,6 +148,9 @@ daPointEntity.setIsEnable(CommonConstant.IS_ENABLE); daPointEntity.setCreateTime(new Date()); daPointDao.insert(daPointEntity); + + // 清空缓存 + pointNoMap.clear(); } @Override @@ -171,6 +173,8 @@ default: break; } + // 清空缓存 + pointNoMap.clear(); } @Override @@ -179,6 +183,8 @@ daPointDao.deleteBatchIds(Arrays.asList(id)); daMeasurePointService.deleteByPoint(id); daMathPointService.deleteByPoint(id); + // 清空缓存 + pointNoMap.clear(); } @Override @@ -277,10 +283,15 @@ @Override public DaPointDTO getByNo(String pointNo) { + if (pointNoMap.containsKey(pointNo)) { + return pointNoMap.get(pointNo); + } QueryWrapper<DaPointEntity> wrapper = new QueryWrapper<>(); wrapper.eq("point_no", pointNo); DaPointEntity entity = daPointDao.selectOne(wrapper); - return ConvertUtils.sourceToTarget(entity, DaPointDTO.class); + DaPointDTO dto = ConvertUtils.sourceToTarget(entity, DaPointDTO.class); + pointNoMap.put(pointNo, dto); + return dto; } @Override -- Gitblit v1.9.3