From 42230a1b3bc391403ea22d2411d17e6140f8ca66 Mon Sep 17 00:00:00 2001 From: Administrator <1923636941@qq.com> Date: Fri, 28 Apr 2023 15:56:33 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A1=B9=E7=9B=AE-=E9=AB=98=E6=94=AF=E6=A8=A1?= =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=8A=A5=E8=AD=A6=E9=98=88=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/system/query/QueryGenerator.java | 40 +++- .../xml/HighFormworkMeasurePointMapper.xml | 10 +- .../service/HighFormworkSupportService.java | 210 ++++++++++++------ 3 files changed, 175 insertions(+), 85 deletions(-) diff --git a/src/main/java/com/zhgd/jeecg/common/system/query/QueryGenerator.java b/src/main/java/com/zhgd/jeecg/common/system/query/QueryGenerator.java index 9207ba8c0..86d25ac2b 100644 --- a/src/main/java/com/zhgd/jeecg/common/system/query/QueryGenerator.java +++ b/src/main/java/com/zhgd/jeecg/common/system/query/QueryGenerator.java @@ -68,7 +68,7 @@ public class QueryGenerator { * @return QueryWrapper实例 */ public static QueryWrapper initQueryWrapper(T searchObj, Map 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 QueryWrapper initQueryWrapper(T searchObj, Map parameterMap, List excludeFields, List likeFields) { - return initQueryWrapper(searchObj, parameterMap, excludeFields, null, false); + return initQueryWrapper(searchObj, parameterMap, excludeFields, null, false, null); + } + + /** + * @param searchObj + * @param parameterMap + * @param defaultAlias 默认的表别名 + * @param + * @return + */ + public static QueryWrapper initQueryWrapper(T searchObj, Map parameterMap, String defaultAlias) { + return initQueryWrapper(searchObj, parameterMap, null, null, false, defaultAlias); + } + + public static QueryWrapper initQueryWrapper(T searchObj, Map parameterMap, List excludeFields, List likeFields, String defaultAlias) { + return initQueryWrapper(searchObj, parameterMap, excludeFields, null, false, defaultAlias); } /** @@ -98,9 +114,14 @@ public class QueryGenerator { * @return */ public static QueryWrapper initQueryWrapper(T searchObj, Map parameterMap, List excludeFields, List likeFields, boolean enableAlias) { + return initQueryWrapper(searchObj, parameterMap, excludeFields, null, false, null); + + } + + public static QueryWrapper initQueryWrapper(T searchObj, Map parameterMap, List excludeFields, List likeFields, boolean enableAlias, String defaultAlias) { long start = System.currentTimeMillis(); QueryWrapper queryWrapper = new QueryWrapper(); - 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 parameterMap, List excludeFields, List likeFields, boolean enableAlias) { + installMplus(queryWrapper, searchObj, parameterMap, excludeFields, null, false, null); + } + + public static void installMplus(QueryWrapper queryWrapper, Object searchObj, Map parameterMap, List excludeFields, List 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); diff --git a/src/main/java/com/zhgd/xmgl/modules/highformwork/mapper/xml/HighFormworkMeasurePointMapper.xml b/src/main/java/com/zhgd/xmgl/modules/highformwork/mapper/xml/HighFormworkMeasurePointMapper.xml index 91d8282ed..868430b43 100644 --- a/src/main/java/com/zhgd/xmgl/modules/highformwork/mapper/xml/HighFormworkMeasurePointMapper.xml +++ b/src/main/java/com/zhgd/xmgl/modules/highformwork/mapper/xml/HighFormworkMeasurePointMapper.xml @@ -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 - - #{item} - - 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} - \ No newline at end of file + diff --git a/src/main/java/com/zhgd/xmgl/modules/highformwork/netty/tcp/service/HighFormworkSupportService.java b/src/main/java/com/zhgd/xmgl/modules/highformwork/netty/tcp/service/HighFormworkSupportService.java index 48d6ccce4..457edccf4 100644 --- a/src/main/java/com/zhgd/xmgl/modules/highformwork/netty/tcp/service/HighFormworkSupportService.java +++ b/src/main/java/com/zhgd/xmgl/modules/highformwork/netty/tcp/service/HighFormworkSupportService.java @@ -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 dataMap) { + HighFormworkMeasurePoint point = highFormworkMeasurePointMapper.selectOne(new LambdaQueryWrapper() + .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 q = new LambdaQueryWrapper() + .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-水平位移(单位为mm)、V-模板沉降(单位为mm)、L-立杆倾斜(单位为°)、D-地基沉降;,例如测点 0001L表示测点类型为立杆倾斜; */ - //高支模设备采集数据 - String no = dataMap.get(HighFormworkSupport.GZ_CJ1); - String no2 = dataMap.get(HighFormworkSupport.GZ_CJ2); - String no3 = dataMap.get(HighFormworkSupport.GZ_CJ3); - List 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 existDevices = point.getDeviceList(); - Map 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-水平位移(单位为mm)、V-模板沉降(单位为mm)、L-立杆倾斜(单位为°)、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 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 list = Stream.of(no, no2, no3).filter(Objects::nonNull).collect(Collectors.toList()); + //保存设备 + Map 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().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 dataMap, String no, String no2, String no3, HighFormworkMeasurePoint point) { + //测点编号后缀为测点类型识别:F-立杆轴力(单位为牛)、H-水平位移(单位为mm)、V-模板沉降(单位为mm)、L-立杆倾斜(单位为°)、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 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); } /**