2023-10-31 17:45:22 +08:00

148 lines
6.6 KiB
Java

package com.zhgd.jeecg;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.zhgd.xmgl.modules.foundation.entity.DeepExcavationCurrentData;
import com.zhgd.xmgl.modules.foundation.entity.DeepExcavationSensor;
import com.zhgd.xmgl.modules.foundation.enums.DataStatusEnum;
import com.zhgd.xmgl.modules.foundation.service.DeepExcavationSensorService;
import com.zhgd.xmgl.modules.foundation.service.IDeepExcavationCurrentDataService;
import com.zhgd.xmgl.task.DevExcavationTask;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
* @author 邱平毅
* @ClassName DeepTest
* @date 2022/9/22 18:06
* @Version 1.0
*/
@SpringBootTest
@RunWith(SpringRunner.class)
public class DeepTest {
@Autowired
DeepExcavationSensorService deepExcavationSensorService;
@Autowired
IDeepExcavationCurrentDataService deepExcavationCurrentDataService;
/**
* 生成监测类型
*/
@Test
public void monitorTypeGenerate() {
String sensorSn = "21830";
List<DeepExcavationCurrentData> dataList = deepExcavationCurrentDataService.list(Wrappers.<DeepExcavationCurrentData>lambdaQuery()
.eq(DeepExcavationCurrentData::getSensorSn, sensorSn).ge(DeepExcavationCurrentData::getReceiveTime, "2022-09-27 17:59:05"));
// String receiveTime = "0001-01-01 01:01:01";
Map<String, List<DeepExcavationCurrentData>> dateAndDataMap = dataList.stream().collect(Collectors.groupingBy(DeepExcavationCurrentData::getReceiveTime));
//
// int size = 0;
//
Set<Map.Entry<String, List<DeepExcavationCurrentData>>> entrySet = dateAndDataMap.entrySet();
// for (Map.Entry<String, List<DeepExcavationCurrentData>> entry : entrySet) {
// int valueSize = entry.getValue().size();
// if (valueSize > size && entry.getKey() != null && DateUtils.parse(entry.getKey(), DatePattern.NORM_DATETIME_PATTERN).getTime() >= DateUtils.parse(receiveTime, DatePattern.NORM_DATETIME_PATTERN).getTime()) {
// receiveTime = entry.getKey();
// size = valueSize;
// }
// }
// log.info("数量最多的一次为:" + receiveTime);
// log.info(dateAndDataMap);
//
//
// List<DeepExcavationCurrentData> deepExcavationCurrentDataList = dateAndDataMap.get(receiveTime);
// List<DeepExcavationSensor> sensorList = new LinkedList<>();
//
// DeepExcavationSensor sensor = deepExcavationSensorService.getOne(Wrappers.<DeepExcavationSensor>lambdaQuery().eq(DeepExcavationSensor::getSensorSn, sensorSn));
//
// log.info();
// for (int index = 1; index < deepExcavationCurrentDataList.size(); index++) {
// DeepExcavationCurrentData data = deepExcavationCurrentDataList.get(index);
// sensorList.add(new DeepExcavationSensor(sensorSn + "(" + (index + 1) + ")", sensor, data));
// }
//
//
// log.info(sensorList);
List<DeepExcavationCurrentData> newDataList = new LinkedList<>();
// deepExcavationSensorService.saveBatch(sensorList)
for (Map.Entry<String, List<DeepExcavationCurrentData>> dateAndData : entrySet) {
List<DeepExcavationCurrentData> value = dateAndData.getValue().stream().sorted(Comparator.comparing(DeepExcavationCurrentData::getId)).collect(Collectors.toList());
for (int index = 0; index < value.size(); index++) {
value.get(index).setSensorSn(sensorSn + (index > 0 ? "(" + (index + 1) + ")" : ""));
newDataList.add(value.get(index));
}
}
// deepExcavationCurrentDataService.updateBatchById(newDataList);
System.out.println(newDataList);
}
/**
* 生成监测类型
*/
@Test
public void deepStatus() {
List<DeepExcavationCurrentData> allList = deepExcavationCurrentDataService.list(Wrappers.<DeepExcavationCurrentData>lambdaQuery().ge(DeepExcavationCurrentData::getReceiveTime, "2022-09-27 18:10:36"));
List<DeepExcavationSensor> sensorList = deepExcavationSensorService.list();
Map<String, DeepExcavationSensor> sensorMap = sensorList.stream().collect(Collectors.toMap(DeepExcavationSensor::getSensorSn, Function.identity()));
for (DeepExcavationCurrentData data : allList) {
String sensorSn = data.getSensorSn();
Float rateAlarmValue = sensorMap.get(sensorSn).getRateAlarmValue();
Float alarmValue = sensorMap.get(sensorSn).getAlarmValue();
if (rateAlarmValue == null || alarmValue == null) {
System.out.println("编号:" + sensorSn + "阈值有问题!");
continue;
}
Integer status = data.getAlarmState();
if (data.getDataRate() != null && data.getDataRate() > rateAlarmValue) {
status = DataStatusEnum.RATE_OF_CHANGE_ALARM.getId();
} else if (data.getDataTotal() != null && data.getDataTotal() > alarmValue) {
status = DataStatusEnum.SUPER_ALARM.getId();
} else {
status = 1;
}
data.setAlarmState(status);
}
System.out.println(allList);
// deepExcavationCurrentDataService.updateBatchById(allList);
}
@Autowired
DevExcavationTask deepExcavationTask;
@Test
public void deepExcavationTaskTest() {
deepExcavationTask.deepExcavationDropped();
}
@Test
public void deepExcavationTaskTest1() {
List<DeepExcavationCurrentData> list = deepExcavationCurrentDataService.list(Wrappers.<DeepExcavationCurrentData>lambdaQuery().likeRight(DeepExcavationCurrentData::getSensorSn, "21830").le(DeepExcavationCurrentData::getReceiveTime, "2022-09-29 18:24:22").ge(DeepExcavationCurrentData::getReceiveTime, "2022-09-29 11:38:56"));
Map<String, Float> floatMap = deepExcavationSensorService.list(Wrappers.<DeepExcavationSensor>lambdaQuery().likeRight(DeepExcavationSensor::getSensorSn, "21830")).stream().collect(Collectors.toMap(DeepExcavationSensor::getSensorSn, DeepExcavationSensor::getFiducialValue));
for (DeepExcavationCurrentData data : list) {
data.setDataTotal(data.getData() + floatMap.get(data.getSensorSn()));
data.setData(data.getDataTotal() + floatMap.get(data.getSensorSn()));
data.setData(data.getDataTotal() - floatMap.get(data.getSensorSn()));
data.setDataTotal(data.getData() + floatMap.get(data.getSensorSn()));
}
System.out.println(list);
}
}