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