项目-高支模上传报警阈值

This commit is contained in:
Administrator 2023-04-28 15:56:33 +08:00
parent c7498de691
commit 42230a1b3b
3 changed files with 175 additions and 85 deletions

View File

@ -68,7 +68,7 @@ public class QueryGenerator {
* @return QueryWrapper实例
*/
public static <T> QueryWrapper<T> initQueryWrapper(T searchObj, Map<String, String[]> parameterMap) {
return initQueryWrapper(searchObj, parameterMap, null);
return initQueryWrapper(searchObj, parameterMap, null, null);
}
/**
@ -83,8 +83,24 @@ public class QueryGenerator {
return initQueryWrapper(searchObj, parameterMap, excludeFields, null, false);
}
public static <T> QueryWrapper<T> initQueryWrapper(T searchObj, Map<String, String[]> parameterMap, List<String> excludeFields, List<String> likeFields) {
return initQueryWrapper(searchObj, parameterMap, excludeFields, null, false);
return initQueryWrapper(searchObj, parameterMap, excludeFields, null, false, null);
}
/**
* @param searchObj
* @param parameterMap
* @param defaultAlias 默认的表别名
* @param <T>
* @return
*/
public static <T> QueryWrapper<T> initQueryWrapper(T searchObj, Map<String, String[]> parameterMap, String defaultAlias) {
return initQueryWrapper(searchObj, parameterMap, null, null, false, defaultAlias);
}
public static <T> QueryWrapper<T> initQueryWrapper(T searchObj, Map<String, String[]> parameterMap, List<String> excludeFields, List<String> likeFields, String defaultAlias) {
return initQueryWrapper(searchObj, parameterMap, excludeFields, null, false, defaultAlias);
}
/**
@ -98,9 +114,14 @@ public class QueryGenerator {
* @return
*/
public static <T> QueryWrapper<T> initQueryWrapper(T searchObj, Map<String, String[]> parameterMap, List<String> excludeFields, List<String> likeFields, boolean enableAlias) {
return initQueryWrapper(searchObj, parameterMap, excludeFields, null, false, null);
}
public static <T> QueryWrapper<T> initQueryWrapper(T searchObj, Map<String, String[]> parameterMap, List<String> excludeFields, List<String> likeFields, boolean enableAlias, String defaultAlias) {
long start = System.currentTimeMillis();
QueryWrapper<T> queryWrapper = new QueryWrapper<T>();
installMplus(queryWrapper, searchObj, parameterMap, excludeFields, likeFields, enableAlias);
installMplus(queryWrapper, searchObj, parameterMap, excludeFields, likeFields, enableAlias, defaultAlias);
log.info("---查询条件构造器初始化完成,耗时:" + (System.currentTimeMillis() - start) + "毫秒----");
return queryWrapper;
}
@ -118,6 +139,10 @@ public class QueryGenerator {
}
public static void installMplus(QueryWrapper<?> queryWrapper, Object searchObj, Map<String, String[]> parameterMap, List<String> excludeFields, List<String> likeFields, boolean enableAlias) {
installMplus(queryWrapper, searchObj, parameterMap, excludeFields, null, false, null);
}
public static void installMplus(QueryWrapper<?> queryWrapper, Object searchObj, Map<String, String[]> parameterMap, List<String> excludeFields, List<String> likeFields, boolean enableAlias, String defaultAlias) {
/*
* 注意:权限查询由前端配置数据规则 当一个人有多个所属部门时候 可以在规则配置包含条件 orgCode 包含 #{sys_org_code}
@ -188,7 +213,7 @@ public class QueryGenerator {
//根据参数值带什么关键字符串判断走什么类型的查询
QueryRuleEnum rule = convert2Rule(value);
value = replaceValue(rule, value);
addEasyQuery(queryWrapper, name, rule, value);
addEasyQuery(queryWrapper, name, rule, value, defaultAlias);
}
} catch (Exception e) {
@ -402,11 +427,18 @@ public class QueryGenerator {
* @param value 查询条件值
*/
private static void addEasyQuery(QueryWrapper<?> queryWrapper, String name, QueryRuleEnum rule, Object value) {
addEasyQuery(queryWrapper, name, rule, value);
}
private static void addEasyQuery(QueryWrapper<?> queryWrapper, String name, QueryRuleEnum rule, Object value, String alias) {
if (value == null || rule == null) {
return;
}
name = oConvertUtils.camelToUnderline(name);
log.info("--查询规则-->" + name + " " + rule.getValue() + " " + value);
if (org.apache.commons.lang3.StringUtils.isNotBlank(alias)) {
name = alias + name;
}
switch (rule) {
case GT:
queryWrapper.gt(name, value);

View File

@ -51,12 +51,8 @@
hfmd.device_type AS hfmd_device_type
FROM
`high_formwork_measure_point` hfmp
INNER JOIN high_formwork_measure_device hfmd ON hfmd.measure_point_id = hfmp.id
WHERE hfmd.device_sn in
<foreach collection="list" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>
and hfmp.measure_point_number =#{measurePointNumber}
LEFT JOIN high_formwork_measure_device hfmd ON hfmd.measure_point_id = hfmp.id
WHERE hfmp.measure_point_number =#{measurePointNumber}
and hfmp.acquisition_instrument_number = #{acquisitionInstrumentNumber}
</select>
</mapper>

View File

@ -5,6 +5,7 @@ import com.zhgd.xmgl.modules.highformwork.entity.*;
import com.zhgd.xmgl.modules.highformwork.mapper.*;
import com.zhgd.xmgl.modules.highformwork.netty.tcp.constant.HighFormworkSupport;
import com.zhgd.xmgl.modules.highformwork.service.IHighFormworkMeasureCurrentDataService;
import io.swagger.models.auth.In;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
@ -13,11 +14,12 @@ import org.springframework.stereotype.Component;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
* 高支模tcp服务端
@ -139,20 +141,7 @@ public class HighFormworkSupportService {
// highFormworkSupportUploadMapper.insert(upload);
} else if (dataMap.keySet().stream().anyMatch(HighFormworkSupport.GZ_CS::equals)) {
log.info("saveTcpData() >>> \r\n {}", "高支模测点信息");
// HighFormworkSupportDevice device = highFormworkSupportDeviceMapper.selectOne(deviceLambdaQueryWrapper
// );
// //高支模测点信息
// HighFormworkSupportMeasurePoint point = new HighFormworkSupportMeasurePoint();
// point.setHighFormworkSupportDeviceId(device != null ? device.getId() : null);
// point.setDevSn(dataMap.get(HighFormworkSupport.DEV_SN));
// point.setSnCj(dataMap.get(HighFormworkSupport.SN_CJ));
// point.setGzCs(dataMap.get(HighFormworkSupport.GZ_CS));
// point.setGzBj(dataMap.get(HighFormworkSupport.GZ_BJ));
// point.setGzYj(dataMap.get(HighFormworkSupport.GZ_YJ));
// String coord = dataMap.get(HighFormworkSupport.GZ_ZB);
// point.setGzZbX(Integer.valueOf(coord.split(",")[0]));
// point.setGzZbY(Integer.valueOf(coord.split(",")[1]));
// highFormworkSupportMeasurePointMapper.insert(point);
saveAlarmThreshold(dataMap);
} else if (dataMap.keySet().stream().anyMatch(s -> s.contains(HighFormworkSupport.GZ_CJ))) {
log.info("saveTcpData() >>> \r\n {}", "高支模设备采集数据");
pickData(dataMap);
@ -168,6 +157,48 @@ public class HighFormworkSupportService {
}
}
private void saveAlarmThreshold(HashMap<String, String> dataMap) {
HighFormworkMeasurePoint point = highFormworkMeasurePointMapper.selectOne(new LambdaQueryWrapper<HighFormworkMeasurePoint>()
.eq(HighFormworkMeasurePoint::getMeasurePointNumber, dataMap.get(HighFormworkSupport.DEV_BH))
.eq(HighFormworkMeasurePoint::getAcquisitionInstrumentNumber, dataMap.get(HighFormworkSupport.DEV_SN)));
if (point == null) {
return;
}
Integer type = getThresholdType(dataMap.get(HighFormworkSupport.SN_CJ));
LambdaQueryWrapper<HighFormworkMeasurePointThreshold> q = new LambdaQueryWrapper<HighFormworkMeasurePointThreshold>()
.eq(HighFormworkMeasurePointThreshold::getMeasurePointId, point.getId())
.eq(HighFormworkMeasurePointThreshold::getType, type);
HighFormworkMeasurePointThreshold threshold = highFormworkMeasurePointThresholdMapper.selectOne(q);
String warningValue = dataMap.get(HighFormworkSupport.GZ_YJ);
String alarmValue = dataMap.get(HighFormworkSupport.GZ_BJ);
if (threshold != null) {
threshold.setWarningValue(warningValue);
threshold.setAlarmValue(alarmValue);
highFormworkMeasurePointThresholdMapper.update(threshold, q);
} else {
HighFormworkMeasurePointThreshold t = new HighFormworkMeasurePointThreshold();
t.setMeasurePointId(point.getId());
t.setType(type);
t.setWarningValue(warningValue);
t.setAlarmValue(alarmValue);
highFormworkMeasurePointThresholdMapper.insert(t);
}
}
private Integer getThresholdType(String no) {
String noType = no.substring(no.length() - 1);
if (noType.equals("L")) {
return 3;
} else if (noType.equals("F")) {
return 4;
} else if (noType.equals("V")) {
return 5;
}
return null;
}
/**
* 高支模设备采集数据
*
@ -177,53 +208,78 @@ public class HighFormworkSupportService {
/*
说明测点编号后缀为测点类型识别F-立杆轴力单位为牛H-水平位移单位为mmV-模板沉降单位为mmL-立杆倾斜单位为°D-地基沉降,例如测点 0001L表示测点类型为立杆倾斜
*/
//高支模设备采集数据
String no = dataMap.get(HighFormworkSupport.GZ_CJ1);
String no2 = dataMap.get(HighFormworkSupport.GZ_CJ2);
String no3 = dataMap.get(HighFormworkSupport.GZ_CJ3);
List<String> list = Arrays.asList(no, no2, no3);
HighFormworkMeasurePointQo qo = new HighFormworkMeasurePointQo();
qo.setList(list);
qo.setMeasurePointNumber(dataMap.get(HighFormworkSupport.DEV_BH));
qo.setAcquisitionInstrumentNumber(dataMap.get(HighFormworkSupport.DEV_SN));
HighFormworkMeasurePoint point = highFormworkMeasurePointMapper.queryhighFormworkMeasurePointWithDevice(qo);
if (point == null) {
log.warn("高支模需要更改/添加高支模-测量点的测量点编号(联瑞科-设备编号):{},采集仪编号(联瑞科-终端编号):{}",
dataMap.get(HighFormworkSupport.DEV_BH), dataMap.get(HighFormworkSupport.DEV_SN));
log.warn("高支模需要添加设备设备sn{}设备sn2{}设备sn3{}", no, no2, no3);
return;
}
List<HighFormworkMeasureDevice> existDevices = point.getDeviceList();
Map<String, HighFormworkMeasureDevice> deviceSnMap = existDevices.stream().collect(Collectors.toMap(HighFormworkMeasureDevice::getDeviceSn, highFormworkMeasureDevice -> highFormworkMeasureDevice));
if (deviceSnMap.get(no) == null) {
log.warn("高支模需要添加设备设备sn{},测量点名称:{}", no, point.getMeasurePointName());
}
if (deviceSnMap.get(no2) == null) {
log.warn("高支模需要添加设备设备sn{},测量点名称:{}", no2, point.getMeasurePointName());
}
if (deviceSnMap.get(no3) == null) {
log.warn("高支模需要添加设备设备sn{},测量点名称:{}", no3, point.getMeasurePointName());
}
if (CollectionUtils.isNotEmpty(existDevices)) {
//测点1类型
String noType = no.substring(no.length() - 1);
//测点编号后缀为测点类型识别F-立杆轴力单位为牛H-水平位移单位为mmV-模板沉降单位为mmL-立杆倾斜单位为°D-地基沉降,例如测点 0001L表示测点类型为立杆倾斜
HighFormworkMeasureCurrentData currentData = new HighFormworkMeasureCurrentData();
currentData.setMeasurePointNumber(point.getMeasurePointNumber());
currentData.setProjectSn(point.getProjectSn());
currentData.setElectricPower(null);
currentData.setAngleXAxis(null);
if (noType.equals("L")) {
currentData.setAngleYAxis(dataMap.get(HighFormworkSupport.GZ_DS1));
}
if (noType.equals("F")) {
currentData.setPressure(String.valueOf(Double.parseDouble(dataMap.get(HighFormworkSupport.GZ_DS1)) / 1000));
}
if (noType.equals("V")) {
currentData.setSubside(dataMap.get(HighFormworkSupport.GZ_DS1));
}
//测点2类型
List<HighFormworkMeasureDevice> existDevices = point.getDeviceList();
//高支模设备采集数据
String no = dataMap.get(HighFormworkSupport.GZ_CJ1);
String no2 = dataMap.get(HighFormworkSupport.GZ_CJ2);
String no3 = dataMap.get(HighFormworkSupport.GZ_CJ3);
List<String> list = Stream.of(no, no2, no3).filter(Objects::nonNull).collect(Collectors.toList());
//保存设备
Map<String, String> noMap = list.stream().collect(Collectors.toMap(x -> x, x -> x));
if (noMap.size() != existDevices.size() || existDevices.stream().allMatch(x -> noMap.containsKey(x))) {
highFormworkMeasureDeviceMapper.delete(new LambdaQueryWrapper<HighFormworkMeasureDevice>().eq(HighFormworkMeasureDevice::getMeasurePointId, point.getId()));
for (String nu : list) {
HighFormworkMeasureDevice d = new HighFormworkMeasureDevice();
d.setProjectSn(point.getProjectSn());
d.setMeasurePointId(point.getId());
d.setDeviceSn(nu);
d.setDeviceName(nu);
d.setDeviceType(getDeviceTypeByNo(nu));
highFormworkMeasureDeviceMapper.insert(d);
}
}
HighFormworkMeasureCurrentData currentData = getHighFormworkMeasureCurrentData(dataMap, no, no2, no3, point);
//插入报警/预警数据
addAlarmData(point, currentData);
}
private Integer getDeviceTypeByNo(String no) {
String noType = no.substring(no.length() - 1);
if (noType.equals("L")) {
return 1;
} else if (noType.equals("F")) {
return 2;
} else if (noType.equals("V")) {
return 3;
}
return null;
}
private HighFormworkMeasureCurrentData getHighFormworkMeasureCurrentData(HashMap<String, String> dataMap, String no, String no2, String no3, HighFormworkMeasurePoint point) {
//测点编号后缀为测点类型识别F-立杆轴力单位为牛H-水平位移单位为mmV-模板沉降单位为mmL-立杆倾斜单位为°D-地基沉降,例如测点 0001L表示测点类型为立杆倾斜
HighFormworkMeasureCurrentData currentData = new HighFormworkMeasureCurrentData();
currentData.setMeasurePointNumber(point.getMeasurePointNumber());
currentData.setProjectSn(point.getProjectSn());
currentData.setElectricPower(null);
currentData.setAngleXAxis(null);
//测点1类型
String noType = no.substring(no.length() - 1);
if (noType.equals("L")) {
currentData.setAngleYAxis(dataMap.get(HighFormworkSupport.GZ_DS1));
}
if (noType.equals("F")) {
currentData.setPressure(String.valueOf(Double.parseDouble(dataMap.get(HighFormworkSupport.GZ_DS1)) / 1000));
}
if (noType.equals("V")) {
currentData.setSubside(dataMap.get(HighFormworkSupport.GZ_DS1));
}
//测点2类型
if (StringUtils.isNotBlank(no2)) {
String noType2 = no2.substring(no2.length() - 1);
currentData.setAngleXAxis(null);
if (noType2.equals("L")) {
@ -235,8 +291,10 @@ public class HighFormworkSupportService {
if (noType2.equals("V")) {
currentData.setSubside(dataMap.get(HighFormworkSupport.GZ_DS2));
}
}
//测点3类型
//测点3类型
if (StringUtils.isNotBlank(no3)) {
String noType3 = no3.substring(no3.length() - 1);
currentData.setAngleXAxis(null);
if (noType3.equals("L")) {
@ -248,28 +306,32 @@ public class HighFormworkSupportService {
if (noType3.equals("V")) {
currentData.setSubside(dataMap.get(HighFormworkSupport.GZ_DS3));
}
//设置报警状态
Integer alarmState = null;
if (getAlarmState(dataMap.get(HighFormworkSupport.GZ_ZT1)).equals(3) ||
getAlarmState(dataMap.get(HighFormworkSupport.GZ_ZT2)).equals(3) ||
getAlarmState(dataMap.get(HighFormworkSupport.GZ_ZT3)).equals(3)) {
//报警
alarmState = 3;
} else if (getAlarmState(dataMap.get(HighFormworkSupport.GZ_ZT1)).equals(2) ||
getAlarmState(dataMap.get(HighFormworkSupport.GZ_ZT2)).equals(2) ||
getAlarmState(dataMap.get(HighFormworkSupport.GZ_ZT3)).equals(2)) {
//预警
alarmState = 2;
} else {
//正常
alarmState = 1;
}
currentData.setAlarmState(alarmState);
dataService.save(currentData);
//插入报警/预警数据
addAlarmData(point, currentData);
}
//设置报警状态
setAlarmStatus(dataMap, currentData);
dataService.save(currentData);
return currentData;
}
private void setAlarmStatus(HashMap<String, String> dataMap, HighFormworkMeasureCurrentData currentData) {
Integer alarmState = null;
if (getAlarmState(dataMap.get(HighFormworkSupport.GZ_ZT1)).equals(3) ||
getAlarmState(dataMap.get(HighFormworkSupport.GZ_ZT2)).equals(3) ||
getAlarmState(dataMap.get(HighFormworkSupport.GZ_ZT3)).equals(3)) {
//报警
alarmState = 3;
} else if (getAlarmState(dataMap.get(HighFormworkSupport.GZ_ZT1)).equals(2) ||
getAlarmState(dataMap.get(HighFormworkSupport.GZ_ZT2)).equals(2) ||
getAlarmState(dataMap.get(HighFormworkSupport.GZ_ZT3)).equals(2)) {
//预警
alarmState = 2;
} else {
//正常
alarmState = 1;
}
currentData.setAlarmState(alarmState);
}
/**