From 059fa27bb1cae5ba748bd536a536a05b315c0dcb Mon Sep 17 00:00:00 2001 From: guo Date: Mon, 18 Mar 2024 19:23:56 +0800 Subject: [PATCH] =?UTF-8?q?bug=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../zhgd/xmgl/config/SafetyHatWSClient.java | 18 ++++++--- .../controller/SafetyHatAlarmController.java | 2 + .../controller/SafetyHatDataController.java | 4 +- .../impl/SafetyHatAlarmServiceImpl.java | 12 ++++++ .../impl/SafetyHatDataServiceImpl.java | 39 +++++++++++++------ .../impl/SafetyHatDayRecordServiceImpl.java | 4 +- 6 files changed, 60 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/zhgd/xmgl/config/SafetyHatWSClient.java b/src/main/java/com/zhgd/xmgl/config/SafetyHatWSClient.java index 991fdf8fa..3a4905c60 100644 --- a/src/main/java/com/zhgd/xmgl/config/SafetyHatWSClient.java +++ b/src/main/java/com/zhgd/xmgl/config/SafetyHatWSClient.java @@ -10,9 +10,9 @@ import com.zhgd.xmgl.enums.ParamEnum; import com.zhgd.xmgl.modules.safetyhat.entity.SafetyHatAlarm; import com.zhgd.xmgl.modules.safetyhat.entity.SafetyHatData; import com.zhgd.xmgl.modules.safetyhat.entity.SafetyHatDev; -import com.zhgd.xmgl.modules.safetyhat.mapper.SafetyHatAlarmMapper; -import com.zhgd.xmgl.modules.safetyhat.mapper.SafetyHatDataMapper; import com.zhgd.xmgl.modules.safetyhat.mapper.SafetyHatDevMapper; +import com.zhgd.xmgl.modules.safetyhat.service.ISafetyHatAlarmService; +import com.zhgd.xmgl.modules.safetyhat.service.ISafetyHatDataService; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; @@ -37,7 +37,7 @@ public class SafetyHatWSClient { } /** - * 插入安全帽实时数据和报警数据 + * 插入智能安全帽实时数据和报警数据 * * @param message */ @@ -81,7 +81,11 @@ public class SafetyHatWSClient { data.setLongitude(yPoint); data.setUploadTime(new Date(ctime * 1000L)); data.setProjectSn(dev.getProjectSn()); - SpringContextUtils.getBean(SafetyHatDataMapper.class).insert(data); + try { + SpringContextUtils.getBean(ISafetyHatDataService.class).add(data); + } catch (Exception e) { + e.printStackTrace(); + } } } } @@ -111,7 +115,11 @@ public class SafetyHatWSClient { alarm.setAlarmType(sosType); alarm.setLatitude(yPoint); alarm.setLongitude(xPoint); - SpringContextUtils.getBean(SafetyHatAlarmMapper.class).insert(alarm); + try { + SpringContextUtils.getBean(ISafetyHatAlarmService.class).add(alarm); + } catch (Exception e) { + e.printStackTrace(); + } } } } diff --git a/src/main/java/com/zhgd/xmgl/modules/safetyhat/controller/SafetyHatAlarmController.java b/src/main/java/com/zhgd/xmgl/modules/safetyhat/controller/SafetyHatAlarmController.java index 47841a0ae..f03d662d2 100644 --- a/src/main/java/com/zhgd/xmgl/modules/safetyhat/controller/SafetyHatAlarmController.java +++ b/src/main/java/com/zhgd/xmgl/modules/safetyhat/controller/SafetyHatAlarmController.java @@ -1,5 +1,6 @@ package com.zhgd.xmgl.modules.safetyhat.controller; +import com.gexin.fastjson.JSON; import com.zhgd.xmgl.base.entity.vo.TrendVo; import com.zhgd.xmgl.modules.safetyhat.service.ISafetyHatAlarmService; import io.swagger.annotations.Api; @@ -75,6 +76,7 @@ public class SafetyHatAlarmController { @ApiOperation(value = "添加智能安全帽-报警信息", notes = "添加智能安全帽-报警信息", httpMethod = "POST") @PostMapping(value = "/add") public Result add(@RequestBody @Validate SafetyHatAlarm safetyHatAlarm) { + log.info("添加智能安全帽-报警信息:{}", JSON.toJSONString(safetyHatAlarm)); safetyHatAlarmService.add(safetyHatAlarm); return Result.ok(); } diff --git a/src/main/java/com/zhgd/xmgl/modules/safetyhat/controller/SafetyHatDataController.java b/src/main/java/com/zhgd/xmgl/modules/safetyhat/controller/SafetyHatDataController.java index 681e6fd7c..8fdfebfb4 100644 --- a/src/main/java/com/zhgd/xmgl/modules/safetyhat/controller/SafetyHatDataController.java +++ b/src/main/java/com/zhgd/xmgl/modules/safetyhat/controller/SafetyHatDataController.java @@ -1,5 +1,6 @@ package com.zhgd.xmgl.modules.safetyhat.controller; +import com.gexin.fastjson.JSON; import com.zhgd.xmgl.modules.safetyhat.entity.SafetyHatData; import com.zhgd.xmgl.modules.safetyhat.service.ISafetyHatDataService; import io.swagger.annotations.Api; @@ -74,7 +75,8 @@ public class SafetyHatDataController { @ApiOperation(value = "添加智能安全帽-实时数据信息", notes = "添加智能安全帽-实时数据信息", httpMethod = "POST") @PostMapping(value = "/add") public Result add(@RequestBody @Validate SafetyHatData safetyHatData) { - safetyHatDataService.add(safetyHatData); + log.info("列表查询智能安全帽-实时数据信息:{}", JSON.toJSONString(safetyHatData)); + safetyHatDataService.add(safetyHatData); return Result.ok(); } diff --git a/src/main/java/com/zhgd/xmgl/modules/safetyhat/service/impl/SafetyHatAlarmServiceImpl.java b/src/main/java/com/zhgd/xmgl/modules/safetyhat/service/impl/SafetyHatAlarmServiceImpl.java index 3ae94c79d..7ba878cd6 100644 --- a/src/main/java/com/zhgd/xmgl/modules/safetyhat/service/impl/SafetyHatAlarmServiceImpl.java +++ b/src/main/java/com/zhgd/xmgl/modules/safetyhat/service/impl/SafetyHatAlarmServiceImpl.java @@ -1,9 +1,12 @@ package com.zhgd.xmgl.modules.safetyhat.service.impl; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.zhgd.jeecg.common.execption.OpenAlertException; import com.zhgd.xmgl.base.entity.vo.TrendVo; import com.zhgd.xmgl.modules.safetyhat.entity.SafetyHatAlarm; +import com.zhgd.xmgl.modules.safetyhat.entity.SafetyHatDev; import com.zhgd.xmgl.modules.safetyhat.mapper.SafetyHatAlarmMapper; +import com.zhgd.xmgl.modules.safetyhat.mapper.SafetyHatDevMapper; import com.zhgd.xmgl.modules.safetyhat.service.ISafetyHatAlarmService; import org.springframework.stereotype.Service; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; @@ -31,6 +34,8 @@ import org.springframework.beans.factory.annotation.Autowired; public class SafetyHatAlarmServiceImpl extends ServiceImpl implements ISafetyHatAlarmService { @Autowired private SafetyHatAlarmMapper safetyHatAlarmMapper; + @Autowired + private SafetyHatDevMapper safetyHatDevMapper; @Override public IPage queryPageList(HashMap paramMap) { @@ -60,6 +65,13 @@ public class SafetyHatAlarmServiceImpl extends ServiceImpl() + .eq(SafetyHatDev::getDevSn, safetyHatAlarm.getDevSn())); + if (dev == null) { + throw new OpenAlertException("设备编号不正确"); + } + safetyHatAlarm.setWorkerInfoId(dev.getWorkerInfoId()); + safetyHatAlarm.setProjectSn(dev.getProjectSn()); safetyHatAlarm.setId(null); baseMapper.insert(safetyHatAlarm); } diff --git a/src/main/java/com/zhgd/xmgl/modules/safetyhat/service/impl/SafetyHatDataServiceImpl.java b/src/main/java/com/zhgd/xmgl/modules/safetyhat/service/impl/SafetyHatDataServiceImpl.java index 669d8c93d..1653f5cf9 100644 --- a/src/main/java/com/zhgd/xmgl/modules/safetyhat/service/impl/SafetyHatDataServiceImpl.java +++ b/src/main/java/com/zhgd/xmgl/modules/safetyhat/service/impl/SafetyHatDataServiceImpl.java @@ -1,24 +1,27 @@ package com.zhgd.xmgl.modules.safetyhat.service.impl; -import com.zhgd.jeecg.common.execption.OpenAlertException; -import com.zhgd.xmgl.modules.safetyhat.entity.SafetyHatData; -import com.zhgd.xmgl.modules.safetyhat.mapper.SafetyHatDataMapper; -import com.zhgd.xmgl.modules.safetyhat.service.ISafetyHatDataService; -import org.springframework.stereotype.Service; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import com.zhgd.jeecg.common.system.query.QueryGenerator; -import com.zhgd.xmgl.util.PageUtil; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.zhgd.jeecg.common.execption.OpenAlertException; +import com.zhgd.jeecg.common.system.query.QueryGenerator; +import com.zhgd.xmgl.modules.safetyhat.entity.SafetyHatData; +import com.zhgd.xmgl.modules.safetyhat.entity.SafetyHatDev; +import com.zhgd.xmgl.modules.safetyhat.mapper.SafetyHatDataMapper; +import com.zhgd.xmgl.modules.safetyhat.mapper.SafetyHatDevMapper; +import com.zhgd.xmgl.modules.safetyhat.service.ISafetyHatDataService; +import com.zhgd.xmgl.util.PageUtil; +import com.zhgd.xmgl.util.RefUtil; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import java.util.Date; import java.util.HashMap; import java.util.List; -import com.zhgd.xmgl.util.RefUtil; -import org.springframework.transaction.annotation.Transactional; -import org.springframework.beans.factory.annotation.Autowired; - /** * @Description: 智能安全帽-实时数据 * @author: pds @@ -30,6 +33,8 @@ import org.springframework.beans.factory.annotation.Autowired; public class SafetyHatDataServiceImpl extends ServiceImpl implements ISafetyHatDataService { @Autowired private SafetyHatDataMapper safetyHatDataMapper; + @Autowired + private SafetyHatDevMapper safetyHatDevMapper; @Override public IPage queryPageList(HashMap paramMap) { @@ -59,7 +64,19 @@ public class SafetyHatDataServiceImpl extends ServiceImpl() + .eq(SafetyHatDev::getDevSn, safetyHatData.getDevSn())); + if (dev == null) { + throw new OpenAlertException("设备编号不正确"); + } + dev.setHeartbeatTime(new Date()); + safetyHatDevMapper.update(dev, new LambdaQueryWrapper() + .eq(SafetyHatDev::getDevSn, safetyHatData.getDevSn())); + safetyHatData.setDevSn(dev.getDevSn()); + safetyHatData.setProjectSn(dev.getProjectSn()); safetyHatData.setId(null); + safetyHatData.setWorkerInfoId(dev.getWorkerInfoId()); + safetyHatData.setUploadTime(new Date()); baseMapper.insert(safetyHatData); } diff --git a/src/main/java/com/zhgd/xmgl/modules/safetyhat/service/impl/SafetyHatDayRecordServiceImpl.java b/src/main/java/com/zhgd/xmgl/modules/safetyhat/service/impl/SafetyHatDayRecordServiceImpl.java index e4c3505b3..f93a03d4a 100644 --- a/src/main/java/com/zhgd/xmgl/modules/safetyhat/service/impl/SafetyHatDayRecordServiceImpl.java +++ b/src/main/java/com/zhgd/xmgl/modules/safetyhat/service/impl/SafetyHatDayRecordServiceImpl.java @@ -50,11 +50,11 @@ public class SafetyHatDayRecordServiceImpl extends ServiceImpl() .eq(SafetyHatDev::getDevSn, safetyHatDayRecord.getDevSn())); if (dev == null) { - throw new OpenAlertException("设备不存在"); + throw new OpenAlertException("设备编号不正确"); } safetyHatDayRecord.setProjectSn(dev.getProjectSn()); safetyHatDayRecord.setId(null); - save(safetyHatDayRecord); + baseMapper.insert(safetyHatDayRecord); }