Bladeren bron

设备模型历史记录、实时功率电流接口开发

qiangxuan 7 maanden geleden
bovenliggende
commit
3c365f793e

+ 26 - 1
zgztBus/jeecg-module-lesm/src/main/java/org/jeecg/modules/fpgLeanModel/controller/FpgLeanModelController.java

@@ -11,8 +11,11 @@ import org.jeecg.common.api.vo.Result;
 import org.jeecg.common.aspect.annotation.AutoLog;
 import org.jeecg.common.system.base.controller.JeecgController;
 import org.jeecg.common.system.query.QueryGenerator;
+import org.jeecg.common.util.oConvertUtils;
+import org.jeecg.modules.fpgLeanModel.entity.DeviceStatiscsModelMongodb;
 import org.jeecg.modules.fpgLeanModel.entity.FpgLeanModel;
 import org.jeecg.modules.fpgLeanModel.entity.FpgLeanModelResult;
+import org.jeecg.modules.fpgLeanModel.entity.LeanModelDeviceHistoryInfo;
 import org.jeecg.modules.fpgLeanModel.service.IFpgLeanModelService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
@@ -21,8 +24,9 @@ import org.springframework.web.servlet.ModelAndView;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import java.util.Arrays;
+import java.util.List;
 
- /**
+/**
  * @Description: 峰平谷模型
  * @Author: jeecg-boot
  * @Date:   2024-10-31
@@ -170,4 +174,25 @@ public class FpgLeanModelController extends JeecgController<FpgLeanModel, IFpgLe
 		 return Result.OK(fpgLeanModelResult);
 	 }
 
+	 @ApiOperation(value="设备模型历史记录-通过区域ID设备ID查询", notes="设备模型历史记录-通过区域ID设备ID查询")
+	 @GetMapping(value = "/getDeviceHistoryInfo")
+	 public Result<IPage<LeanModelDeviceHistoryInfo>> getDeviceHistoryInfo(
+			 @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
+			 @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
+			 @RequestParam(name = "deviceRegionId", required = false) String deviceRegionId,
+			 @RequestParam(name="deviceInformationId") String deviceInformationId) {
+		 IPage<LeanModelDeviceHistoryInfo> pageList = fpgLeanModelService.getDeviceHistoryInfo(deviceRegionId, deviceInformationId, pageSize, pageNo);
+		 return Result.OK(pageList);
+	 }
+
+
+	 @ApiOperation(value="实时功率和电流-通过设备id查询", notes="实时功率和电流-通过设备id查询")
+	 @GetMapping(value = "/queryRealTimeDataById")
+	 public Result<List<DeviceStatiscsModelMongodb>> queryRealTimeDataById(@RequestParam(name="deviceInformationId") String deviceInformationId) {
+		 List<DeviceStatiscsModelMongodb> deviceStatiscsModelMongodbList = fpgLeanModelService.queryRealTimeDataById(deviceInformationId);
+		 if(oConvertUtils.listIsEmpty(deviceStatiscsModelMongodbList)) {
+			 return Result.error("未找到对应数据");
+		 }
+		 return Result.OK(deviceStatiscsModelMongodbList);
+	 }
 }

+ 5 - 2
zgztBus/jeecg-module-lesm/src/main/java/org/jeecg/modules/deviceLesm/entity/FpgStatiscsModelMongodb.java → zgztBus/jeecg-module-lesm/src/main/java/org/jeecg/modules/fpgLeanModel/entity/DeviceStatiscsModelMongodb.java

@@ -1,4 +1,4 @@
-package org.jeecg.modules.deviceLesm.entity;
+package org.jeecg.modules.fpgLeanModel.entity;
 
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
@@ -13,7 +13,7 @@ import java.util.Date;
  * @Version: V1.0
  */
 @Data
-public class FpgStatiscsModelMongodb {
+public class DeviceStatiscsModelMongodb {
 
     @ApiModelProperty(value = "更新日期")
     private Date updateTime;
@@ -38,6 +38,9 @@ public class FpgStatiscsModelMongodb {
     /**运行时长*/
     @ApiModelProperty(value = "运行时长")
     private BigDecimal ingTime;
+    /**运行总电流*/
+    @ApiModelProperty(value = "运行总电流")
+    private BigDecimal selectricCurrent;
     /**运行总功率*/
     @ApiModelProperty(value = "运行总功率")
     private BigDecimal power;

+ 46 - 0
zgztBus/jeecg-module-lesm/src/main/java/org/jeecg/modules/fpgLeanModel/entity/LeanModelDeviceHistoryInfo.java

@@ -0,0 +1,46 @@
+package org.jeecg.modules.fpgLeanModel.entity;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.math.BigDecimal;
+import java.util.Date;
+
+@Data
+public class LeanModelDeviceHistoryInfo {
+    /**采集点ID*/
+    @ApiModelProperty(value = "采集点ID")
+    private String devicePointId;
+    /**区域ID*/
+    @ApiModelProperty(value = "区域ID")
+    private String deviceRegionId;
+    /**设备id*/
+    @ApiModelProperty(value = "设备id")
+    private String deviceInformationId;
+    /**设备启动时间*/
+    @ApiModelProperty(value = "设备启动时间")
+    private String deviceStartTime;
+    /**设备关停时间*/
+    @ApiModelProperty(value = "设备关停时间")
+    private String deviceStopTime;
+    /**运行时长*/
+    @ApiModelProperty(value = "运行总时长")
+    private BigDecimal ingTime;
+    /**运行总功率*/
+    @ApiModelProperty(value = "运行总功率")
+    private BigDecimal power;
+    @ApiModelProperty(value = "日期")
+    private String dates;
+    /**统计单位存储对应时间格式*/
+    @ApiModelProperty(value = "统计单位存储对应时间格式")
+    private String datestr;
+    /**更新日期*/
+    @ApiModelProperty(value = "更新日期")
+    private Date updateTime;
+    /**创建时间*/
+    @ApiModelProperty(value = "创建时间")
+    private Date createTime;
+    /**评级告警数量*/
+    @ApiModelProperty(value = "创建时间")
+    private Long warnSum;
+}

+ 9 - 0
zgztBus/jeecg-module-lesm/src/main/java/org/jeecg/modules/fpgLeanModel/service/IFpgLeanModelService.java

@@ -1,8 +1,13 @@
 package org.jeecg.modules.fpgLeanModel.service;
 
+import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.service.IService;
+import org.jeecg.modules.fpgLeanModel.entity.DeviceStatiscsModelMongodb;
 import org.jeecg.modules.fpgLeanModel.entity.FpgLeanModel;
 import org.jeecg.modules.fpgLeanModel.entity.FpgLeanModelResult;
+import org.jeecg.modules.fpgLeanModel.entity.LeanModelDeviceHistoryInfo;
+
+import java.util.List;
 
 /**
  * @Description: 峰平谷模型
@@ -13,4 +18,8 @@ import org.jeecg.modules.fpgLeanModel.entity.FpgLeanModelResult;
 public interface IFpgLeanModelService extends IService<FpgLeanModel> {
 
     FpgLeanModelResult queryFpgLeanModelById(String id);
+
+    IPage<LeanModelDeviceHistoryInfo> getDeviceHistoryInfo(String deviceRegionId, String deviceInformationId, Integer pageSize, Integer pageNo);
+
+    List<DeviceStatiscsModelMongodb> queryRealTimeDataById(String deviceInformationId);
 }

+ 88 - 2
zgztBus/jeecg-module-lesm/src/main/java/org/jeecg/modules/fpgLeanModel/service/impl/FpgLeanModelServiceImpl.java

@@ -1,19 +1,32 @@
 package org.jeecg.modules.fpgLeanModel.service.impl;
 
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.jeecg.common.util.DateUtils;
 import org.jeecg.common.util.oConvertUtils;
 import org.jeecg.modules.deviceLesm.entity.DeviceInformation;
 import org.jeecg.modules.deviceLesm.mapper.DeviceInformationMapper;
+import org.jeecg.modules.fpgLeanModel.entity.DeviceStatiscsModelMongodb;
 import org.jeecg.modules.fpgLeanModel.entity.FpgLeanModel;
 import org.jeecg.modules.fpgLeanModel.entity.FpgLeanModelResult;
+import org.jeecg.modules.fpgLeanModel.entity.LeanModelDeviceHistoryInfo;
 import org.jeecg.modules.fpgLeanModel.mapper.FpgLeanModelMapper;
 import org.jeecg.modules.fpgLeanModel.service.IFpgLeanModelService;
+import org.jeecg.modules.homePageData.entity.LeanEventWarnInfo;
+import org.jeecg.modules.homePageData.service.ILeanEventWarnInfoService;
+import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Sort;
+import org.springframework.data.mongodb.core.MongoTemplate;
+import org.springframework.data.mongodb.core.index.Index;
+import org.springframework.data.mongodb.core.query.Criteria;
+import org.springframework.data.mongodb.core.query.Query;
 import org.springframework.stereotype.Service;
 
-import java.util.Arrays;
-import java.util.List;
+import java.util.*;
 
 /**
  * @Description: 峰平谷模型
@@ -26,6 +39,13 @@ public class FpgLeanModelServiceImpl extends ServiceImpl<FpgLeanModelMapper, Fpg
 
     @Autowired
     private DeviceInformationMapper deviceInformationMapper;
+
+    @Autowired
+    private MongoTemplate mongoTemplate;
+
+    @Autowired
+    private ILeanEventWarnInfoService leanEventWarnInfoService;
+
     @Override
     public FpgLeanModelResult queryFpgLeanModelById(String id) {
         FpgLeanModelResult fpgLeanModelResult = new FpgLeanModelResult();
@@ -45,4 +65,70 @@ public class FpgLeanModelServiceImpl extends ServiceImpl<FpgLeanModelMapper, Fpg
         fpgLeanModelResult.setDeviceInformationList(deviceInformations);
         return fpgLeanModelResult;
     }
+
+    @Override
+    public IPage<LeanModelDeviceHistoryInfo> getDeviceHistoryInfo(String deviceRegionId, String deviceInformationId, Integer pageSize, Integer pageNo) {
+
+        IPage<LeanModelDeviceHistoryInfo> leanModelDeviceHistoryInfoIPage = new Page<>();
+
+        Query query = new Query()
+                .addCriteria(Criteria.where("deviceRegionId").is(deviceRegionId))
+                .addCriteria(Criteria.where("deviceInformationId").is(deviceInformationId));
+        // 进行分页
+        long total = mongoTemplate.count(query, DeviceStatiscsModelMongodb.class, "total_startstop");
+        query.skip((pageNo - 1) * pageSize).limit(pageSize);
+
+        // 执行查询
+        List<DeviceStatiscsModelMongodb> fpgStatiscsModelDataList = mongoTemplate.find(query, DeviceStatiscsModelMongodb.class, "total_startstop");
+        if (oConvertUtils.listIsEmpty(fpgStatiscsModelDataList)){
+            return leanModelDeviceHistoryInfoIPage;
+        }
+
+        List<LeanModelDeviceHistoryInfo> leanModelDeviceHistoryInfoList = new ArrayList<>();
+        fpgStatiscsModelDataList.forEach(x ->{
+            LeanModelDeviceHistoryInfo leanModelDeviceHistoryInfo = new LeanModelDeviceHistoryInfo();
+            BeanUtils.copyProperties(x, leanModelDeviceHistoryInfo);
+            leanModelDeviceHistoryInfoList.add(leanModelDeviceHistoryInfo);
+        });
+        leanModelDeviceHistoryInfoList.forEach(y ->{
+            LambdaQueryWrapper<LeanEventWarnInfo> queryWrapper = new LambdaQueryWrapper<>();
+            queryWrapper.eq(LeanEventWarnInfo::getDeviceInformationId, y.getDeviceInformationId());
+            queryWrapper.between(LeanEventWarnInfo::getCreateTime, DateUtils.str2Date(y.getDeviceStartTime(), DateUtils.datetimeFormat.get()), DateUtils.str2Date(y.getDeviceStopTime(), DateUtils.datetimeFormat.get()));
+            long leanEventWarnSum = leanEventWarnInfoService.list(queryWrapper).stream().count();
+            y.setWarnSum(leanEventWarnSum);
+        });
+
+        leanModelDeviceHistoryInfoIPage.setRecords(leanModelDeviceHistoryInfoList);
+        leanModelDeviceHistoryInfoIPage.setTotal(total);
+        leanModelDeviceHistoryInfoIPage.setSize(pageSize);
+        return leanModelDeviceHistoryInfoIPage;
+    }
+
+    @Override
+    public List<DeviceStatiscsModelMongodb> queryRealTimeDataById(String deviceInformationId) {
+        Query query = new Query();
+        query.addCriteria(Criteria.where("deviceInformationId").is(deviceInformationId))
+                .with(Sort.by(Sort.Direction.ASC, "createTime"));
+        Date startTime = new Date();
+        // 加8小时
+        Calendar calendar1 = Calendar.getInstance();
+        calendar1.setTime(startTime);
+        calendar1.add(Calendar.HOUR, 8);
+        Date specifiedTimePlus8HoursStartTime = calendar1.getTime();
+
+        Date endTime = new Date();
+        Calendar calendar2 = Calendar.getInstance();
+        calendar2.setTime(endTime);
+        Date specifiedTimePlus8HoursStartEndTime = calendar2.getTime();
+
+        query.addCriteria(Criteria.where("createTime").gte(specifiedTimePlus8HoursStartEndTime).lt(specifiedTimePlus8HoursStartTime));
+        Index index = new Index().on("name", Sort.Direction.ASC).unique();
+        mongoTemplate.indexOps("collectionName").ensureIndex(index);
+        // 执行查询
+        List<DeviceStatiscsModelMongodb> deviceStatiscsModelMongodbList = mongoTemplate.find(query, DeviceStatiscsModelMongodb.class, "leanmodel_run_realtime");
+        if (oConvertUtils.listIsEmpty(deviceStatiscsModelMongodbList)){
+            return null;
+        }
+        return deviceStatiscsModelMongodbList;
+    }
 }

+ 82 - 0
zgztBus/jeecg-module-lesm/src/main/java/org/jeecg/modules/utils/MongoIndexUtil.java

@@ -0,0 +1,82 @@
+package org.jeecg.modules.utils;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Sort;
+import org.springframework.data.mongodb.core.MongoTemplate;
+import org.springframework.data.mongodb.core.index.Index;
+import org.springframework.data.mongodb.core.index.IndexInfo;
+
+import java.util.List;
+
+public class MongoIndexUtil {
+
+    @Autowired
+    private MongoTemplate mongoTemplate;
+
+    /**
+     * 创建联合索引
+     *
+     * @param indexName 索引的名称
+     * @param index_key2 索引的名称
+     * @param collectionName 集合名称
+     * @return
+     */
+    public boolean createInboxIndex(String indexName, String index_key2, String collectionName) {
+        boolean scuess = true;
+        try {
+            Index index = new Index();
+            index.on(indexName, Sort.Direction.ASC).on(index_key2, Sort.Direction.ASC);
+            mongoTemplate.indexOps(collectionName).ensureIndex(index);
+        } catch (Exception ex) {
+            scuess = false;
+        }
+        return scuess;
+    }
+
+
+    /**
+     * 创建单个索引
+     *
+     * @param indexName 索引的名称
+     * @param collectionName 集合名称
+     * @return
+     */
+    public boolean createInboxIndex(String indexName, String collectionName) {
+        boolean scuess = true;
+        try {
+            Index index = new Index();
+            index.on(indexName, Sort.Direction.ASC);
+            mongoTemplate.indexOps(collectionName).ensureIndex(index);
+        } catch (Exception ex) {
+            scuess = false;
+        }
+        return scuess;
+    }
+
+    public boolean isIndexExists(String indexName, String collectionName) {
+        List<IndexInfo> indexInfos = mongoTemplate.indexOps(collectionName).getIndexInfo();
+        for (IndexInfo indexInfo : indexInfos) {
+            if (indexInfo.getName().equals(indexName)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    /**
+     * 删除索引
+     *
+     * @param indexName 索引的名称
+     * @param collectionName 集合名称
+     * @return
+     */
+    public boolean deleteInboxIndex(String indexName, String collectionName) {
+        boolean scuess = true;
+        try {
+            mongoTemplate.indexOps(collectionName).dropIndex(indexName);
+        } catch (Exception ex) {
+            scuess = false;
+        }
+        return scuess;
+    }
+}