瀏覽代碼

峰平谷报表接口开发

qiangxuan 8 月之前
父節點
當前提交
742e423b76

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

@@ -1,5 +1,6 @@
 package org.jeecg.modules.fpgLeanModel.controller;
 
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -195,4 +196,23 @@ public class FpgLeanModelController extends JeecgController<FpgLeanModel, IFpgLe
 		 }
 		 return Result.OK(deviceStatiscsModelMongodbList);
 	 }
+
+
+	@ApiOperation(value="峰平谷模型报表-通过模型编码导出报表", notes="峰平谷模型报表-通过模型编码导出报表")
+	@GetMapping(value = "/exportModelDataByCode")
+	public JSONObject exportModelDataByLeanModelCode(@RequestParam(name="leanModelCode") String leanModelCode) {
+
+		JSONObject result = fpgLeanModelService.queryFpgDataByLeanModelCode(leanModelCode);
+
+		return result;
+	}
+
+	@ApiOperation(value="峰平谷功率报表-通过模型编码导出报表", notes="峰平谷模型报表-通过模型编码导出报表")
+	@GetMapping(value = "/exportModelDataPowerByCode")
+	public JSONObject exportModelPowerDataByLeanModelCode(@RequestParam(name="leanModelCode") String leanModelCode) {
+
+		JSONObject result = fpgLeanModelService.queryFpgPowerDataByLeanModelCode(leanModelCode);
+
+		return result;
+	}
 }

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

@@ -0,0 +1,26 @@
+package org.jeecg.modules.fpgLeanModel.entity;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.math.BigDecimal;
+
+@Data
+public class ModelDataResult {
+
+    @ApiModelProperty(value = "设备名称")
+    private String deviceTitle;
+    /**区域ID*/
+    @ApiModelProperty(value = "区域ID")
+    private String deviceRegionId;
+    /**设备id*/
+    @ApiModelProperty(value = "设备id")
+    private String deviceInformationId;
+    @ApiModelProperty(value = "峰平谷名称")
+    private String key;
+    @ApiModelProperty(value = "值")
+    private BigDecimal value;
+    /**创建时间*/
+    @ApiModelProperty(value = "创建时间")
+    private String createTime;
+}

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

@@ -0,0 +1,116 @@
+package org.jeecg.modules.fpgLeanModel.entity;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.math.BigDecimal;
+
+@Data
+public class ModelReportFormResult {
+    @ApiModelProperty(value = "设备名称")
+    private String deviceTitle;
+    /**采集点ID*/
+    @ApiModelProperty(value = "采集点ID")
+    private String devicePointId;
+    /**区域ID*/
+    @ApiModelProperty(value = "区域ID")
+    private String deviceRegionId;
+    /**设备id*/
+    @ApiModelProperty(value = "设备id")
+    private String deviceInformationId;
+    /**运行时长*/
+    @ApiModelProperty(value = "运行时长")
+    private BigDecimal ingTime;
+    /**运行总电流*/
+    @ApiModelProperty(value = "运行总电流")
+    private BigDecimal selectricCurrent;
+    /**运行总功率*/
+    @ApiModelProperty(value = "运行总功率")
+    private BigDecimal power;
+    /**尖总功率*/
+    @ApiModelProperty(value = "尖总功率")
+    private BigDecimal topsPower;
+    /**峰总功率*/
+    @ApiModelProperty(value = "峰总功率")
+    private BigDecimal peaksPower;
+    /**平总功率*/
+    @ApiModelProperty(value = "平总功率")
+    private BigDecimal flatPower;
+    /**谷总功率*/
+    @ApiModelProperty(value = "谷总功率")
+    private BigDecimal valleysPower;
+    /**尖运行时长*/
+    @ApiModelProperty(value = "尖运行时长")
+    private BigDecimal topsIngTime;
+    /**峰运行时长*/
+    @ApiModelProperty(value = "峰运行时长")
+    private BigDecimal peaksIngTime;
+    /**平运行时长*/
+    @ApiModelProperty(value = "平运行时长")
+    private BigDecimal flatIngTime;
+    /**谷运行时长*/
+    @ApiModelProperty(value = "谷运行时长")
+    private BigDecimal valleysIngTime;
+    /**尖电流*/
+    @ApiModelProperty(value = "尖电流")
+    private BigDecimal topsSelectricCurrent;
+    /**峰电流*/
+    @ApiModelProperty(value = "峰电流")
+    private BigDecimal peaksSelectricCurrent;
+    /**平电流*/
+    @ApiModelProperty(value = "平电流")
+    private BigDecimal flatSelectricCurrent;
+    /**谷电流*/
+    @ApiModelProperty(value = "谷电流")
+    private BigDecimal valleysSelectricCurrent;
+    /**尖占比%*/
+    @ApiModelProperty(value = "尖占比%")
+    private BigDecimal topsProportion;
+    /**峰占比%*/
+    @ApiModelProperty(value = "峰占比%")
+    private BigDecimal peaksProportion;
+    /**平占比%*/
+    @ApiModelProperty(value = "平占比%")
+    private BigDecimal flatProportion;
+    /**谷占比%*/
+    @ApiModelProperty(value = "谷占比%")
+    private BigDecimal valleysProportion;
+    /**占比处理%*/
+    @ApiModelProperty(value = "占比处理")
+    private Integer proportion;
+    /**日期*/
+    @ApiModelProperty(value = "日期")
+    private String dates;
+    /**创建时间*/
+    @ApiModelProperty(value = "创建时间")
+    private String createTime;
+
+    public ModelReportFormResult(String deviceTitle, String devicePointId, String deviceRegionId, String deviceInformationId, BigDecimal ingTime, BigDecimal selectricCurrent, BigDecimal power, BigDecimal topsPower, BigDecimal peaksPower, BigDecimal flatPower, BigDecimal valleysPower, BigDecimal topsIngTime, BigDecimal peaksIngTime, BigDecimal flatIngTime, BigDecimal valleysIngTime, BigDecimal topsSelectricCurrent, BigDecimal peaksSelectricCurrent, BigDecimal flatSelectricCurrent, BigDecimal valleysSelectricCurrent, BigDecimal topsProportion, BigDecimal peaksProportion, BigDecimal flatProportion, BigDecimal valleysProportion, Integer proportion, String dates, String createTime) {
+        this.deviceTitle = deviceTitle;
+        this.devicePointId = devicePointId;
+        this.deviceRegionId = deviceRegionId;
+        this.deviceInformationId = deviceInformationId;
+        this.ingTime = ingTime;
+        this.selectricCurrent = selectricCurrent;
+        this.power = power;
+        this.topsPower = topsPower;
+        this.peaksPower = peaksPower;
+        this.flatPower = flatPower;
+        this.valleysPower = valleysPower;
+        this.topsIngTime = topsIngTime;
+        this.peaksIngTime = peaksIngTime;
+        this.flatIngTime = flatIngTime;
+        this.valleysIngTime = valleysIngTime;
+        this.topsSelectricCurrent = topsSelectricCurrent;
+        this.peaksSelectricCurrent = peaksSelectricCurrent;
+        this.flatSelectricCurrent = flatSelectricCurrent;
+        this.valleysSelectricCurrent = valleysSelectricCurrent;
+        this.topsProportion = topsProportion;
+        this.peaksProportion = peaksProportion;
+        this.flatProportion = flatProportion;
+        this.valleysProportion = valleysProportion;
+        this.proportion = proportion;
+        this.dates = dates;
+        this.createTime = createTime;
+    }
+}

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

@@ -1,5 +1,6 @@
 package org.jeecg.modules.fpgLeanModel.service;
 
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.service.IService;
 import org.jeecg.modules.fpgLeanModel.entity.DeviceStatiscsModelMongodb;
@@ -22,4 +23,8 @@ public interface IFpgLeanModelService extends IService<FpgLeanModel> {
     IPage<LeanModelDeviceHistoryInfo> getDeviceHistoryInfo(String deviceRegionId, String deviceInformationId, Integer pageSize, Integer pageNo);
 
     List<DeviceStatiscsModelMongodb> queryRealTimeDataById(String deviceInformationId);
+
+    JSONObject queryFpgDataByLeanModelCode(String leanModelCode);
+
+    JSONObject queryFpgPowerDataByLeanModelCode(String leanModelCode);
 }

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

@@ -1,6 +1,9 @@
 package org.jeecg.modules.fpgLeanModel.service.impl;
 
 
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -9,10 +12,7 @@ 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.entity.*;
 import org.jeecg.modules.fpgLeanModel.mapper.FpgLeanModelMapper;
 import org.jeecg.modules.fpgLeanModel.service.IFpgLeanModelService;
 import org.jeecg.modules.homePageData.entity.LeanEventWarnInfo;
@@ -25,7 +25,9 @@ import org.springframework.data.mongodb.core.query.Criteria;
 import org.springframework.data.mongodb.core.query.Query;
 import org.springframework.stereotype.Service;
 
+import java.text.SimpleDateFormat;
 import java.util.*;
+import java.util.stream.Collectors;
 
 /**
  * @Description: 峰平谷模型
@@ -120,8 +122,6 @@ public class FpgLeanModelServiceImpl extends ServiceImpl<FpgLeanModelMapper, Fpg
         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)){
@@ -129,4 +129,151 @@ public class FpgLeanModelServiceImpl extends ServiceImpl<FpgLeanModelMapper, Fpg
         }
         return deviceStatiscsModelMongodbList;
     }
+
+    @Override
+    public JSONObject queryFpgDataByLeanModelCode(String leanModelCode) {
+
+        JSONObject result = new JSONObject();
+
+        List<DeviceStatiscsModelMongodb> fpgStatiscsModelDataList = queryByTimeRanges(mongoTemplate, leanModelCode, null, null, null, null, null);
+        List<String> deviceInformationIds = fpgStatiscsModelDataList.stream().map(DeviceStatiscsModelMongodb::getDeviceInformationId).collect(Collectors.toList());
+        LambdaQueryWrapper<DeviceInformation> queryWrapper = new LambdaQueryWrapper<>();
+        queryWrapper.in(DeviceInformation::getId, deviceInformationIds);
+        List<DeviceInformation> deviceInformationList = deviceInformationMapper.selectList(queryWrapper);
+        // 将listA转换为以(设备Id, 区域Id)为键的Map
+        Map<String, DeviceInformation> mapA = deviceInformationList.stream()
+                .collect(Collectors.toMap(a -> a.getId() + "_" + a.getDeviceRegionId(), a -> a));
+
+        // 遍历listB,根据相同的(设备Id, 区域Id)与mapA中的对象合并成新的ModelResult并添加到新列表
+        List<ModelReportFormResult> combinedList = fpgStatiscsModelDataList.stream()
+                .map(b -> {
+                    String key = b.getDeviceInformationId() + "_" + b.getDeviceRegionId();
+                    DeviceInformation a = mapA.get(key);
+                    if (a != null) {
+                        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+                        String dateString = sdf.format(b.getCreateTime());
+                        return new ModelReportFormResult(a.getDeviceTitle(), b.getDevicePointId(), b.getDeviceRegionId(), b.getDeviceInformationId(),
+                                b.getIngTime(), b.getSelectricCurrent(), b.getPower(), b.getTopsPower(), b.getPeaksPower(), b.getFlatPower(), b.getValleysPower(),
+                                b.getTopsIngTime(), b.getPeaksIngTime(), b.getFlatIngTime(), b.getValleysIngTime(),
+                                b.getTopsSelectricCurrent(), b.getPeaksSelectricCurrent(), b.getFlatSelectricCurrent(), b.getValleysSelectricCurrent(),
+                                b.getTopsProportion(), b.getPeaksProportion(), b.getFlatProportion(), b.getValleysProportion(), b.getProportion(), b.getDates(), dateString);
+                    }
+                    return null;
+                }).filter(x -> x != null).collect(Collectors.toList());
+
+        JSONArray jArray = JSON.parseArray(JSON.toJSONString(combinedList));
+        result.put("data", jArray);
+        return result;
+    }
+
+    @Override
+    public JSONObject queryFpgPowerDataByLeanModelCode(String leanModelCode) {
+
+        JSONObject result = new JSONObject();
+
+        List<DeviceStatiscsModelMongodb> fpgStatiscsModelDataList = queryByTimeRanges(mongoTemplate, leanModelCode, null, null, null, null, null);
+        List<String> deviceInformationIds = fpgStatiscsModelDataList.stream().map(DeviceStatiscsModelMongodb::getDeviceInformationId).collect(Collectors.toList());
+        LambdaQueryWrapper<DeviceInformation> queryWrapper = new LambdaQueryWrapper<>();
+        queryWrapper.in(DeviceInformation::getId, deviceInformationIds);
+        List<DeviceInformation> deviceInformationList = deviceInformationMapper.selectList(queryWrapper);
+        // 将listA转换为以(设备Id, 区域Id)为键的Map
+        Map<String, DeviceInformation> mapA = deviceInformationList.stream()
+                .collect(Collectors.toMap(a -> a.getId() + "_" + a.getDeviceRegionId(), a -> a));
+
+        // 遍历listB,根据相同的(设备Id, 区域Id)与mapA中的对象合并成新的ModelResult并添加到新列表
+        List<ModelReportFormResult> combinedList = fpgStatiscsModelDataList.stream()
+                .map(b -> {
+                    String key = b.getDeviceInformationId() + "_" + b.getDeviceRegionId();
+                    DeviceInformation a = mapA.get(key);
+                    if (a != null) {
+                        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+                        String dateString = sdf.format(b.getCreateTime());
+                        return new ModelReportFormResult(a.getDeviceTitle(), b.getDevicePointId(), b.getDeviceRegionId(), b.getDeviceInformationId(),
+                                b.getIngTime(), b.getSelectricCurrent(), b.getPower(), b.getTopsPower(), b.getPeaksPower(), b.getFlatPower(), b.getValleysPower(),
+                                b.getTopsIngTime(), b.getPeaksIngTime(), b.getFlatIngTime(), b.getValleysIngTime(),
+                                b.getTopsSelectricCurrent(), b.getPeaksSelectricCurrent(), b.getFlatSelectricCurrent(), b.getValleysSelectricCurrent(),
+                                b.getTopsProportion(), b.getPeaksProportion(), b.getFlatProportion(), b.getValleysProportion(), b.getProportion(), b.getDates(), dateString);
+                    }
+                    return null;
+                }).filter(x -> x != null).collect(Collectors.toList());
+
+        List<ModelDataResult> modelDataResults = new ArrayList<>();
+        for (ModelReportFormResult modelReportFormResult : combinedList) {
+            for (int i = 0; i < 5; i++) {
+                ModelDataResult modelDataResult = new ModelDataResult();
+                if (i == 0){
+                    modelDataResult.setKey("尖");
+                    modelDataResult.setValue(modelReportFormResult.getTopsPower());
+                }
+                if (i == 1){
+                    modelDataResult.setKey("峰");
+                    modelDataResult.setValue(modelReportFormResult.getPeaksPower());
+                }
+                if (i == 2){
+                    modelDataResult.setKey("平");
+                    modelDataResult.setValue(modelReportFormResult.getFlatPower());
+                }
+                if (i == 3){
+                    modelDataResult.setKey("谷");
+                    modelDataResult.setValue(modelReportFormResult.getValleysPower());
+                }
+                if (i == 4){
+                    modelDataResult.setKey("反有总");
+                    modelDataResult.setValue(modelReportFormResult.getTopsPower().add(modelReportFormResult.getPeaksPower()).add(modelReportFormResult.getFlatPower()).add(modelReportFormResult.getValleysPower()));
+                }
+                modelDataResult.setDeviceTitle(modelReportFormResult.getDeviceTitle());
+                modelDataResult.setDeviceRegionId(modelReportFormResult.getDeviceRegionId());
+                modelDataResult.setDeviceInformationId(modelReportFormResult.getDeviceInformationId());
+                modelDataResult.setCreateTime(modelReportFormResult.getCreateTime());
+                modelDataResults.add(modelDataResult);
+            }
+        }
+        JSONArray jArray = JSON.parseArray(JSON.toJSONString(modelDataResults));
+        result.put("data", jArray);
+        return result;
+    }
+
+
+    /**
+     * 基于模型编码、采集点ID、设备ID、区域ID、峰平谷配置时间范围 动态查询mongoDB
+     * @param mongoTemplate
+     * @param devicePointId
+     * @param deviceInformationId
+     * @param deviceRegionId
+     * @return
+     */
+    public List<DeviceStatiscsModelMongodb> queryByTimeRanges(MongoTemplate mongoTemplate, String leanModeCode, String startTimeParam,  String endTimeParam, String devicePointId, String deviceInformationId, String deviceRegionId) {
+        Query query = new Query();
+        query.with(Sort.by(Sort.Direction.ASC, "createTime"));
+        if (oConvertUtils.isNotEmpty(devicePointId)){
+            // 设备采集点
+            query.addCriteria(Criteria.where("devicePointId").is(devicePointId));
+        }
+        if (oConvertUtils.isNotEmpty(devicePointId)){
+            // 虚拟设备
+            query.addCriteria(Criteria.where("deviceInformationId").is(deviceInformationId));
+        }
+        if (oConvertUtils.isNotEmpty(devicePointId)){
+            // 虚拟设备区域
+            query.addCriteria(Criteria.where("deviceRegionId").is(deviceRegionId));
+        }
+        if (oConvertUtils.isNotEmpty(startTimeParam) && oConvertUtils.isNotEmpty(endTimeParam)){
+            // 使用Criteria添加多个时间范围条件
+            // DateUtils.date2Str(startTime, new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS")) 毫秒
+            Date startTime = DateUtils.str2Date(startTimeParam, DateUtils.datetimeFormat.get());
+            Calendar calendar1 = Calendar.getInstance();
+            calendar1.setTime(startTime);
+            calendar1.add(Calendar.HOUR, 8);
+            Date specifiedTimePlus8HoursStartTime = calendar1.getTime();
+            Date endTime = DateUtils.str2Date(endTimeParam, DateUtils.datetimeFormat.get());
+            Calendar calendar2 = Calendar.getInstance();
+            calendar2.setTime(endTime);
+            calendar2.add(Calendar.HOUR, 8);
+            Date specifiedTimePlus8HoursStartEndTime = calendar2.getTime();
+            query.addCriteria(Criteria.where("createTime").gte(specifiedTimePlus8HoursStartTime).lt(specifiedTimePlus8HoursStartEndTime));
+        }
+        // 执行查询
+        List<DeviceStatiscsModelMongodb> fpgStatiscsModelDataList = mongoTemplate.find(query, DeviceStatiscsModelMongodb.class, "total_day_power_sum");
+        return fpgStatiscsModelDataList;
+    }
 }