有毒气体开发

This commit is contained in:
guo 2024-01-10 17:48:38 +08:00
parent d2eaab456c
commit 85db1f7233
11 changed files with 188 additions and 42 deletions

View File

@ -46,6 +46,10 @@ public class TcpNettyHandler extends SimpleChannelInboundHandler<Object> {
highFormworkSupportResponseOk(ctx); highFormworkSupportResponseOk(ctx);
} }
} }
//有毒气体
if (StringUtils.startsWith(str, "##")) {
poisonousGasDevCurrentDataService.addDataFromTcpFor212Protocol(str);
}
//16进制判断 //16进制判断
String hexString = readToHexString(bytes); String hexString = readToHexString(bytes);

View File

@ -8,6 +8,7 @@ import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup; import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioDatagramChannel; import io.netty.channel.socket.nio.NioDatagramChannel;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -16,16 +17,18 @@ import javax.annotation.PostConstruct;
@Component @Component
@Slf4j @Slf4j
public class UDPServerApp { public class UDPServerApp {
@Autowired
private UDPServerHandler udpServerHandler;
@Value("${udp.port:}") @Value("${udp.port:}")
private Integer port; private Integer port;
@PostConstruct @PostConstruct
public void startUdpApp() { public void startUdpApp() {
if (port == null) { if (port == null) {
return; return;
} }
log.info("启动udp……"); log.info("启动udp……");
Bootstrap bootstrap = new Bootstrap(); Bootstrap bootstrap = new Bootstrap();
EventLoopGroup workGroup = new NioEventLoopGroup(); EventLoopGroup workGroup = new NioEventLoopGroup();
bootstrap.group(workGroup).channel(NioDatagramChannel.class) bootstrap.group(workGroup).channel(NioDatagramChannel.class)
@ -34,7 +37,7 @@ public class UDPServerApp {
@Override @Override
protected void initChannel(NioDatagramChannel ch) throws Exception { protected void initChannel(NioDatagramChannel ch) throws Exception {
ch.pipeline().addLast(new UDPServerHandler()); ch.pipeline().addLast(udpServerHandler);
} }
}); });
try { try {

View File

@ -3,6 +3,7 @@ package com.zhgd.netty.udp;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.IdUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.zhgd.xmgl.modules.location.entity.LocationData; import com.zhgd.xmgl.modules.location.entity.LocationData;
import com.zhgd.xmgl.modules.location.entity.LocationTunnel; import com.zhgd.xmgl.modules.location.entity.LocationTunnel;
import com.zhgd.xmgl.modules.location.mapper.LocationDataMapper; import com.zhgd.xmgl.modules.location.mapper.LocationDataMapper;
@ -17,10 +18,12 @@ import io.netty.channel.socket.DatagramPacket;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.List; import java.util.List;
@Slf4j @Slf4j
@Component
public class UDPServerHandler extends SimpleChannelInboundHandler<DatagramPacket> { public class UDPServerHandler extends SimpleChannelInboundHandler<DatagramPacket> {
@Autowired @Autowired
private PoisonousGasDevMapper poisonousGasDevMapper; private PoisonousGasDevMapper poisonousGasDevMapper;
@ -54,36 +57,30 @@ public class UDPServerHandler extends SimpleChannelInboundHandler<DatagramPacket
List<LocationTunnel> locationTunnels = locationTunnelMapper.selectList(new LambdaQueryWrapper<LocationTunnel>() List<LocationTunnel> locationTunnels = locationTunnelMapper.selectList(new LambdaQueryWrapper<LocationTunnel>()
.eq(LocationTunnel::getProjectSn, projectSn)); .eq(LocationTunnel::getProjectSn, projectSn));
if (CollUtil.isNotEmpty(locationTunnels)) { if (CollUtil.isNotEmpty(locationTunnels)) {
long l = IdUtil.getSnowflake().nextId(); //清除以前标签
locationDataMapper.update(null, new LambdaUpdateWrapper<LocationData>()
.set(LocationData::getRealtimeId, null)
.eq(LocationData::getCardno, cardno)
.isNotNull(LocationData::getRealtimeId));
LocationTunnel locationTunnel = locationTunnels.get(0); LocationTunnel locationTunnel = locationTunnels.get(0);
Long realtimeId = locationTunnel.getRealtimeId();
if (realtimeId == null) {
realtimeId = IdUtil.getSnowflake().nextId();
}
LocationData locationData = new LocationData(); LocationData locationData = new LocationData();
locationData.setCardType("1510"); locationData.setCardType("1510");
locationData.setCardno(cardno); locationData.setCardno(cardno);
locationData.setPersonName(workerInfos.get(0).getWorkerName()); locationData.setPersonName(workerInfos.get(0).getWorkerName());
//locationData.setRegionId();
//locationData.setRegionCode();
//locationData.setRegionName();
//locationData.setPileNo();
//locationData.setNX();
//locationData.setNY();
//locationData.setPX();
//locationData.setPY();
//算出洞口的距离 //算出洞口的距离
locationData.setInlX(Double.valueOf(inlX) + 271); locationData.setInlX(Double.valueOf(inlX) + 271);
//locationData.setMasterX();
//locationData.setRingNum();
//locationData.setLongitude();
//locationData.setLatitude();
//locationData.setAltitude();
locationData.setAlarm(0); locationData.setAlarm(0);
//locationData.setVolume();
//locationData.setHeartRate();
locationData.setProjectSn(projectSn); locationData.setProjectSn(projectSn);
locationData.setRealtimeId(l); locationData.setRealtimeId(realtimeId);
locationData.setTunnelId(locationTunnel.getTunnelId()); locationData.setTunnelId(locationTunnel.getTunnelId());
locationDataMapper.insert(locationData); locationDataMapper.insert(locationData);
locationTunnel.setRealtimeId(l); locationTunnel.setRealtimeId(realtimeId);
locationTunnelMapper.updateById(locationTunnel); locationTunnelMapper.updateById(locationTunnel);
} }
} }

View File

@ -27,4 +27,6 @@ public interface LocationDataMapper extends BaseMapper<LocationData> {
List<LocationData> getRealTimeLocationWorker(HashMap<String, Object> paramMap); List<LocationData> getRealTimeLocationWorker(HashMap<String, Object> paramMap);
IPage<LocationData> queryPageList(Page<LocationData> page, @Param(Constants.WRAPPER) QueryWrapper<LocationData> queryWrapper); IPage<LocationData> queryPageList(Page<LocationData> page, @Param(Constants.WRAPPER) QueryWrapper<LocationData> queryWrapper);
Integer clearLocationData();
} }

View File

@ -23,8 +23,10 @@
<select id="getRealTimeLocationWorker" resultType="com.zhgd.xmgl.modules.location.entity.LocationData"> <select id="getRealTimeLocationWorker" resultType="com.zhgd.xmgl.modules.location.entity.LocationData">
select d.* select d.*
from location_data d from location_data d
join (select max(id) id from location_data group by cardno)t on t.id=d.id
join worker_info wi on d.cardno = wi.location_cardno join worker_info wi on d.cardno = wi.location_cardno
where d.realtime_id = (select location_tunnel.realtime_id from location_tunnel where id = #{locationTunnelId}) join location_tunnel lt on lt.realtime_id=d.realtime_id
where lt.id = #{locationTunnelId}
<if test="queryStr != null and queryStr != ''"> <if test="queryStr != null and queryStr != ''">
and (wi.worker_name like concat('%', #{queryStr}, '%') or and (wi.worker_name like concat('%', #{queryStr}, '%') or
wi.location_cardno like concat('%', #{queryStr}, '%')) wi.location_cardno like concat('%', #{queryStr}, '%'))
@ -37,4 +39,11 @@
join worker_info wi on d.cardno = wi.location_cardno join worker_info wi on d.cardno = wi.location_cardno
${ew.customSqlSegment} ${ew.customSqlSegment}
</select> </select>
<select id="clearLocationData" resultType="java.lang.Integer">
UPDATE location_data d,location_tunnel t
SET d.realtime_id = NULL
WHERE d.realtime_id = t.realtime_id
AND d.create_time <![CDATA[<]]> DATE_SUB(now(), interval 30 MINUTE)
</select>
</mapper> </mapper>

View File

@ -103,6 +103,13 @@ public class PoisonousGasDevAlarm implements Serializable {
@Excel(name = "项目sn", width = 15) @Excel(name = "项目sn", width = 15)
@ApiModelProperty(value = "项目sn") @ApiModelProperty(value = "项目sn")
private java.lang.String projectSn; private java.lang.String projectSn;
@Excel(name = "监测值", width = 15)
@ApiModelProperty(value = "气体值")
private Double gasVal;
@ApiModelProperty(value = "单位 0:ppm;1:%LEL;2:%VOL;3:mg/m3;4:pphm;5:g/m3;6:无单位;7:ppb")
private java.lang.Integer unit;
@ApiModelProperty(value = "报警状态 1低报警2高报警3超量程4故障5、A2报警6、A1报警")
private java.lang.Integer alarmType;
/** /**
* 创建时间 * 创建时间
*/ */
@ -120,13 +127,6 @@ public class PoisonousGasDevAlarm implements Serializable {
@ApiModelProperty(value = "更新时间") @ApiModelProperty(value = "更新时间")
private java.util.Date updateTime; private java.util.Date updateTime;
@Excel(name = "监测值", width = 15)
@ApiModelProperty(value = "气体值")
private Double gasVal;
@ApiModelProperty(value = "单位 0:ppm;1:%LEL;2:%VOL;3:mg/m3;4:pphm;5:g/m3;6:无单位;7:ppb")
private java.lang.Integer unit;
@ApiModelProperty(value = "报警状态 1低报警2高报警3超量程")
private java.lang.Integer alarmType;
@ApiModelProperty(value = "设备名称") @ApiModelProperty(value = "设备名称")
@TableField(exist = false) @TableField(exist = false)

View File

@ -38,10 +38,10 @@ public class PoisonousGasDevCurrentData implements Serializable {
@ApiModelProperty(value = "设备sn") @ApiModelProperty(value = "设备sn")
private java.lang.String devSn; private java.lang.String devSn;
/** /**
* 气体类型1氧气2甲烷3一氧化碳 * 气体类型1氧气2甲烷3一氧化碳4硫化氢
*/ */
@Excel(name = "气体类型", width = 15, replace = {"氧气_1", "甲烷_2", "一氧化碳_3"}) @Excel(name = "气体类型", width = 15, replace = {"氧气_1", "甲烷_2", "一氧化碳_3", "硫化氢_4"})
@ApiModelProperty(value = "气体类型1氧气、2甲烷、3一氧化碳") @ApiModelProperty(value = "气体类型1氧气、2甲烷、3一氧化碳、4硫化氢")
private Integer gasType; private Integer gasType;
@Excel(name = "监测值", width = 15) @Excel(name = "监测值", width = 15)
@ -59,10 +59,6 @@ public class PoisonousGasDevCurrentData implements Serializable {
@ApiModelProperty(value = "单位 0:ppm;1:%LEL;2:%VOL;3:mg/m3;4:pphm;5:g/m3;6:无单位;7:ppb") @ApiModelProperty(value = "单位 0:ppm;1:%LEL;2:%VOL;3:mg/m3;4:pphm;5:g/m3;6:无单位;7:ppb")
private java.lang.Integer unit; private java.lang.Integer unit;
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@ApiModelProperty(value = "创建时间 yyyy-MM-dd HH:mm:ss")
private java.util.Date createDate;
/** /**
* 上传时间 yyyy-MM-dd HH:mm:ss * 上传时间 yyyy-MM-dd HH:mm:ss
*/ */
@ -71,6 +67,10 @@ public class PoisonousGasDevCurrentData implements Serializable {
@ApiModelProperty(value = "上传时间 yyyy-MM-dd HH:mm:ss") @ApiModelProperty(value = "上传时间 yyyy-MM-dd HH:mm:ss")
@Excel(name = "上报时间", width = 20, format = "yyyy-MM-dd HH:mm:ss") @Excel(name = "上报时间", width = 20, format = "yyyy-MM-dd HH:mm:ss")
private java.util.Date uploadTime; private java.util.Date uploadTime;
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@ApiModelProperty(value = "创建时间 yyyy-MM-dd HH:mm:ss")
private java.util.Date createDate;
/** /**
* 更新时间 yyyy-MM-dd HH:mm:ss * 更新时间 yyyy-MM-dd HH:mm:ss
*/ */

View File

@ -26,4 +26,6 @@ public interface IPoisonousGasDevCurrentDataService extends IService<PoisonousGa
IPage<PoisonousGasDevCurrentData> queryPageList(PoisonousGasDevCurrentData poisonousGasDevCurrentData, Integer pageNo, Integer pageSize, HttpServletRequest req); IPage<PoisonousGasDevCurrentData> queryPageList(PoisonousGasDevCurrentData poisonousGasDevCurrentData, Integer pageNo, Integer pageSize, HttpServletRequest req);
void add(PoisonousGasDevCurrentData poisonousGasDevCurrentData); void add(PoisonousGasDevCurrentData poisonousGasDevCurrentData);
void addDataFromTcpFor212Protocol(String str);
} }

View File

@ -1,6 +1,7 @@
package com.zhgd.xmgl.modules.poisonous.service.impl; package com.zhgd.xmgl.modules.poisonous.service.impl;
import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@ -20,6 +21,7 @@ import com.zhgd.xmgl.modules.poisonous.mapper.PoisonousGasDevMapper;
import com.zhgd.xmgl.modules.poisonous.service.IPoisonousGasDevCurrentDataService; import com.zhgd.xmgl.modules.poisonous.service.IPoisonousGasDevCurrentDataService;
import com.zhgd.xmgl.util.RefUtil; import com.zhgd.xmgl.util.RefUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.jeecgframework.poi.excel.def.NormalExcelConstants; import org.jeecgframework.poi.excel.def.NormalExcelConstants;
import org.jeecgframework.poi.excel.entity.ExportParams; import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView; import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
@ -203,6 +205,94 @@ public class PoisonousGasDevCurrentDataServiceImpl extends ServiceImpl<Poisonous
} }
} }
@Override
public void addDataFromTcpFor212Protocol(String str) {
//##0342QN=202401101134000;ST=27;CN=2011;PW=123456;MN=F2100231103001;CP=&&DataTime=202401101134;F21001-Rtd=0.000,F21001-Flag=0;F21002-Rtd=20.565,F21002-Flag=0;F21003-Rtd=0.000,F21003-Flag=0;F21004-Rtd=0.000,F21004-Flag=0;F21005-Rtd=99.000,F21005-Flag=0;F21006-Rtd=99.000,F21006-Flag=0;F21007-Rtd=99.000,F21007-Flag=0;F21008-Rtd=99.000,F21008-Flag=0&&A781
String[] dataArr = str.split("&&");
String devSn = StringUtils.split(StringUtils.split(dataArr[0], ";")[4], "=")[1];
String data = dataArr[1];
String[] iDataArr = StringUtils.split(data, ";");
String time = StringUtils.split(iDataArr[0], "=")[1];
PoisonousGasDev poisonousGasDev = poisonousGasDevMapper.selectOne(new LambdaQueryWrapper<PoisonousGasDev>().eq(PoisonousGasDev::getDevSn, devSn));
if (poisonousGasDev == null) {
log.info("addDataFromTcpFor212Protocol设备不存在devSn{}", devSn);
return;
}
DateTime dateTime = DateUtil.parse(time + "00");
//1甲烷 2氧气 3硫化氢 4一氧化碳
insertCurrentData(devSn, 2, iDataArr, 1, poisonousGasDev, 1, dateTime);
insertCurrentData(devSn, 1, iDataArr, 2, poisonousGasDev, 2, dateTime);
insertCurrentData(devSn, 4, iDataArr, 3, poisonousGasDev, 0, dateTime);
insertCurrentData(devSn, 3, iDataArr, 4, poisonousGasDev, 0, dateTime);
insertAlarmIf(devSn, "甲烷", dateTime, poisonousGasDev, iDataArr, 1, 1);
insertAlarmIf(devSn, "氧气", dateTime, poisonousGasDev, iDataArr, 2, 2);
insertAlarmIf(devSn, "硫化氢", dateTime, poisonousGasDev, iDataArr, 3, 0);
insertAlarmIf(devSn, "一氧化碳", dateTime, poisonousGasDev, iDataArr, 4, 0);
}
private void insertAlarmIf(String devSn, String monitorObject, DateTime dateTime, PoisonousGasDev poisonousGasDev, String[] iDataArr, int x, int unit) {
//0正常,1故障,2超量程,3A2报警,4A1报警
String gasEq = iDataArr[x];
String[] dataAndAlarmArr = StringUtils.split(gasEq, ",");
String flag = StringUtils.split(dataAndAlarmArr[1], "=")[1];
if (!Objects.equals(flag, "0")) {
PoisonousGasDevAlarm devAlarm1 = new PoisonousGasDevAlarm();
devAlarm1.setDevSn(devSn);
devAlarm1.setMonitorObject(monitorObject);
devAlarm1.setAlarmDetail(getAlarm(flag));
devAlarm1.setAlarmTime(dateTime);
devAlarm1.setProjectSn(poisonousGasDev.getProjectSn());
devAlarm1.setGasVal(Double.valueOf(StringUtils.split(dataAndAlarmArr[0], "=")[1]));
devAlarm1.setUnit(unit);
devAlarm1.setAlarmType(getAlarmType(flag));
poisonousGasDevAlarmMapper.insert(devAlarm1);
}
}
private Integer getAlarmType(String flag) {
//0正常,1故障,2超量程,3A2报警,4A1报警
switch (flag) {
case "1":
return 4;
case "2":
return 3;
case "3":
return 5;
case "4":
return 6;
}
return null;
}
private String getAlarm(String flag) {
//0正常,1故障,2超量程,3A2报警,4A1报警
switch (flag) {
case "1":
return "故障";
case "2":
return "超量程";
case "3":
return "A2报警";
case "4":
return "A1报警";
}
return null;
}
private void insertCurrentData(String devSn, int gasType, String[] iDataArr, int x, PoisonousGasDev poisonousGasDev, int unit, Date time) {
PoisonousGasDevCurrentData currentData1 = new PoisonousGasDevCurrentData();
currentData1.setDevSn(devSn);
currentData1.setGasType(gasType);
String gasEq = iDataArr[x];
String[] dataAndAlarmArr = StringUtils.split(gasEq, ",");
currentData1.setGasVal(Double.valueOf(StringUtils.split(dataAndAlarmArr[0], "=")[1]));
currentData1.setProjectSn(poisonousGasDev.getProjectSn());
currentData1.setUnit(unit);
currentData1.setUploadTime(time);
poisonousGasDevCurrentDataMapper.insert(currentData1);
}
private String getAlarmTypeName(Integer alarmType) { private String getAlarmTypeName(Integer alarmType) {
if (alarmType == null) { if (alarmType == null) {
return null; return null;

View File

@ -290,6 +290,7 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
.antMatchers("/xmgl/rtNewTechnologiesAndNewProcess/page").permitAll() .antMatchers("/xmgl/rtNewTechnologiesAndNewProcess/page").permitAll()
.antMatchers("/xmgl/taskProgress/queryById").permitAll() .antMatchers("/xmgl/taskProgress/queryById").permitAll()
.antMatchers("/xmgl/videoItem/getPlayUrlFromHikvision").permitAll() .antMatchers("/xmgl/videoItem/getPlayUrlFromHikvision").permitAll()
.antMatchers("/xmgl/workerInfo/selectProjectWorkerTypeTotalList").permitAll()
.antMatchers(HttpMethod.OPTIONS, "/**").anonymous() .antMatchers(HttpMethod.OPTIONS, "/**").anonymous()
.anyRequest().authenticated() // 剩下所有的验证都需要验证 .anyRequest().authenticated() // 剩下所有的验证都需要验证
.and() .and()

View File

@ -0,0 +1,38 @@
package com.zhgd.xmgl.task;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zhgd.xmgl.modules.location.entity.LocationData;
import com.zhgd.xmgl.modules.location.mapper.LocationDataMapper;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Date;
import java.util.List;
@Slf4j
@Component
@Api(tags = "隧道定位")
@RestController
@RequestMapping
public class LocationDataTask {
@Autowired
private LocationDataMapper locationDataMapper;
/**
* 隧道定位数据超时人员标签清除
*/
@Scheduled(cron = "0 0/10 * * * ?")
@GetMapping("/xmgl/task/clearLocationData")
public void clearLocationData() {
log.info("隧道定位数据超时人员标签清除执行");
locationDataMapper.clearLocationData();
}
}