|
@@ -0,0 +1,228 @@
|
|
|
+package com.ruoyi.system.service.impl;
|
|
|
+
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
+import com.ruoyi.system.domain.*;
|
|
|
+import com.ruoyi.system.mapper.*;
|
|
|
+import com.ruoyi.system.service.SaveDataService;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.util.Date;
|
|
|
+
|
|
|
+/**
|
|
|
+ * classname: 站点信息
|
|
|
+ * description 服务实现类
|
|
|
+ */
|
|
|
+@Service
|
|
|
+@Slf4j
|
|
|
+public class SaveDataServiceImpl implements SaveDataService {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private HeartBeatMapper heartBeatMapper;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private SiteInfoMapper siteInfoMapper;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private TaskNoticeMapper taskNoticeMapper;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private TaskResultMapper taskResultMapper;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private CarPositionMapper carPositionMapper;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private MeasureUploadMapper measureUploadMapper;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void saveDate(String data, String topics) {
|
|
|
+ String[] topicsList = topics.split("/");
|
|
|
+ if (topicsList.length == 3) {
|
|
|
+ String action = topicsList[2];
|
|
|
+ switch (action) {
|
|
|
+ case "heartbeat" ->
|
|
|
+ //存入心跳
|
|
|
+ heartbeat(data);
|
|
|
+ case "startMeasure" ->
|
|
|
+ //开始测流
|
|
|
+ startMeasure(data);
|
|
|
+ case "taskFault" ->
|
|
|
+ //任务故障
|
|
|
+ taskFault(data);
|
|
|
+ case "positionUpdate" ->
|
|
|
+ //小车位置
|
|
|
+ positionUpdate(data);
|
|
|
+ case "measureBegin" ->
|
|
|
+ //停泊点开始测流
|
|
|
+ measureBegin(data);
|
|
|
+ case "measureUpload" ->
|
|
|
+ //停泊点流速上报
|
|
|
+ measureUpload(data);
|
|
|
+ case "return" ->
|
|
|
+ //小车开始返航
|
|
|
+ xiaoReturn(data);
|
|
|
+ case "taskend" ->
|
|
|
+ //小车任务完成上报
|
|
|
+ taskend(data);
|
|
|
+ case "waterLevelUpload" ->
|
|
|
+ //水位数据上报
|
|
|
+ waterLevelUpload(data);
|
|
|
+ case "measureStop" ->
|
|
|
+ //测流停止
|
|
|
+ measureStop(data);
|
|
|
+ case "resultUpload" ->
|
|
|
+ //测流上报
|
|
|
+ resultUpload(data);
|
|
|
+ default -> log.error("topic 命令没找到:{}", topics);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ log.error("topic is error:{}",topics);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void heartbeat(String data){
|
|
|
+ try {
|
|
|
+ HeartBeat heartBeat = JSONUtil.toBean(data, HeartBeat.class);
|
|
|
+ heartBeat.setHeartId(0L);
|
|
|
+ heartBeat.setCreateTime(new Date());
|
|
|
+ SiteInfo siteInfo = siteInfoMapper.queryBySiteCode(heartBeat.getId());
|
|
|
+ if (siteInfo == null){
|
|
|
+ log.error("查询站点失败入库失败 站码:{}",heartBeat.getId());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ heartBeat.setSiteId(siteInfo.getSiteId());
|
|
|
+ heartBeatMapper.insert(heartBeat);
|
|
|
+ log.info("insert heartbeat:{}",heartBeat);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("存入心跳 入库错误:",e);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public void startMeasure(String data){
|
|
|
+ try {
|
|
|
+ TaskNotice taskNotice = JSONUtil.toBean(data, TaskNotice.class);
|
|
|
+ SiteInfo siteInfo = siteInfoMapper.queryBySiteCode(taskNotice.getId());
|
|
|
+ if (siteInfo == null) {
|
|
|
+ log.error("查询站点失败入库失败 站码:{}", taskNotice.getId());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ taskNotice.setStartId(0L);
|
|
|
+ if (taskNotice.getWorkmode() == 1) {
|
|
|
+ taskNotice.setRemark("时间任务触发 开始测流任务");
|
|
|
+ } else if (taskNotice.getWorkmode() == 2) {
|
|
|
+ taskNotice.setRemark("变幅任务触发 开始测流任务");
|
|
|
+ } else if (taskNotice.getWorkmode() == 3) {
|
|
|
+ taskNotice.setRemark("手动任务触发 开始测流任务");
|
|
|
+ }
|
|
|
+ taskNotice.setCreateTime(new Date());
|
|
|
+ taskNotice.setSiteId(siteInfo.getSiteId());
|
|
|
+ taskNoticeMapper.insert(taskNotice);
|
|
|
+ //新建结果报告 状态设置为测流中
|
|
|
+ TaskResult taskResult = new TaskResult();
|
|
|
+ taskResult.setResultId(0L);
|
|
|
+ taskResult.setTaskid(taskNotice.getTaskid());
|
|
|
+ taskResult.setStatus(0);
|
|
|
+ taskResult.setSiteId(siteInfo.getSiteId());
|
|
|
+ taskResult.setCreateTime(new Date());
|
|
|
+ taskResultMapper.insert(taskResult);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("开始测流 入库错误:",e);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public void taskFault(String data) {
|
|
|
+ try {
|
|
|
+ TaskNotice taskNotice = JSONUtil.toBean(data, TaskNotice.class);
|
|
|
+ SiteInfo siteInfo = siteInfoMapper.queryBySiteCode(taskNotice.getId());
|
|
|
+ if (siteInfo == null) {
|
|
|
+ log.error("查询站点失败入库失败 站码:{}", taskNotice.getId());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ taskNotice.setStartId(0L);
|
|
|
+ taskNotice.setRemark("任务故障");
|
|
|
+ taskNotice.setCreateTime(new Date());
|
|
|
+ taskNotice.setSiteId(siteInfo.getSiteId());
|
|
|
+ taskNoticeMapper.insert(taskNotice);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("任务故障 入库错误:", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ public void positionUpdate(String data){
|
|
|
+ try {
|
|
|
+ CarPosition carPosition= JSONUtil.toBean(data, CarPosition.class);
|
|
|
+ SiteInfo siteInfo = siteInfoMapper.queryBySiteCode(carPosition.getId());
|
|
|
+ if (siteInfo == null) {
|
|
|
+ log.error("查询站点失败入库失败 站码:{}", carPosition.getId());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ carPosition.setSiteId(siteInfo.getSiteId());
|
|
|
+ carPosition.setCarId(0L);
|
|
|
+ carPosition.setCreateTime(new Date());
|
|
|
+ carPositionMapper.insert(carPosition);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("小车位置 入库错误:", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void measureBegin(String data){
|
|
|
+ try {
|
|
|
+ TaskNotice taskNotice = JSONUtil.toBean(data, TaskNotice.class);
|
|
|
+ SiteInfo siteInfo = siteInfoMapper.queryBySiteCode(taskNotice.getId());
|
|
|
+ if (siteInfo == null) {
|
|
|
+ log.error("查询站点失败入库失败 站码:{}", taskNotice.getId());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ taskNotice.setStartId(0L);
|
|
|
+ taskNotice.setRemark(taskNotice.getPn() + "号停泊点开始测流");
|
|
|
+ taskNotice.setCreateTime(new Date());
|
|
|
+ taskNotice.setSiteId(siteInfo.getSiteId());
|
|
|
+ taskNoticeMapper.insert(taskNotice);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("停泊点开始测流 入库错误:", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void measureUpload(String data){
|
|
|
+ try {
|
|
|
+ MeasureUpload measureUpload= JSONUtil.toBean(data, MeasureUpload.class);
|
|
|
+ SiteInfo siteInfo = siteInfoMapper.queryBySiteCode(measureUpload.getId());
|
|
|
+ if (siteInfo == null) {
|
|
|
+ log.error("查询站点失败入库失败 站码:{}", measureUpload.getId());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ measureUpload.setSiteId(siteInfo.getSiteId());
|
|
|
+ measureUpload.setMeasureId(0L);
|
|
|
+ measureUpload.setCreateTime(new Date());
|
|
|
+ measureUploadMapper.insert(measureUpload);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("停泊点流速上报 入库错误:", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void taskend(String data){
|
|
|
+ log.info("taskend:{}",data);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void waterLevelUpload(String data){
|
|
|
+ log.info("waterLevelUpload:{}",data);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void xiaoReturn(String data){
|
|
|
+ log.info("xiaoReturn:{}",data);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void measureStop(String data){
|
|
|
+ log.info("measureStop:{}",data);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void resultUpload(String data){
|
|
|
+ log.info("resultUpload:{}",data);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+}
|