|
@@ -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;
|
|
|
+ }
|
|
|
}
|