SaveDataServiceImpl.java 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. package com.ruoyi.system.service.impl;
  2. import cn.hutool.json.JSONUtil;
  3. import com.ruoyi.system.domain.*;
  4. import com.ruoyi.system.mapper.*;
  5. import com.ruoyi.system.service.SaveDataService;
  6. import lombok.extern.slf4j.Slf4j;
  7. import org.springframework.stereotype.Service;
  8. import javax.annotation.Resource;
  9. import java.util.Date;
  10. /**
  11. * classname: 站点信息
  12. * description 服务实现类
  13. */
  14. @Service
  15. @Slf4j
  16. public class SaveDataServiceImpl implements SaveDataService {
  17. @Resource
  18. private HeartBeatMapper heartBeatMapper;
  19. @Resource
  20. private SiteInfoMapper siteInfoMapper;
  21. @Resource
  22. private TaskNoticeMapper taskNoticeMapper;
  23. @Resource
  24. private TaskResultMapper taskResultMapper;
  25. @Resource
  26. private CarPositionMapper carPositionMapper;
  27. @Resource
  28. private MeasureUploadMapper measureUploadMapper;
  29. @Resource
  30. private WaterLevelMapper waterLevelMapper;
  31. @Override
  32. public void saveDate(String data, String topics) {
  33. String[] topicsList = topics.split("/");
  34. if (topicsList.length == 3) {
  35. String action = topicsList[2];
  36. switch (action) {
  37. case "heartbeat" ->
  38. //存入心跳
  39. heartbeat(data);
  40. case "startMeasure" ->
  41. //开始测流
  42. startMeasure(data);
  43. case "taskFault" ->
  44. //任务故障
  45. taskFault(data);
  46. case "positionUpdate" ->
  47. //小车位置
  48. positionUpdate(data);
  49. case "measureBegin" ->
  50. //停泊点开始测流
  51. measureBegin(data);
  52. case "measureUpload" ->
  53. //停泊点流速上报
  54. measureUpload(data);
  55. case "return" ->
  56. //小车开始返航
  57. xiaoReturn(data);
  58. case "taskend" ->
  59. //小车任务完成上报
  60. taskend(data);
  61. case "waterLevelUpload" ->
  62. //水位数据上报
  63. waterLevelUpload(data);
  64. case "resultUpload" ->
  65. //测流结果上报
  66. resultUpload(data);
  67. default -> log.error("topic 命令没找到:{}", topics);
  68. }
  69. } else {
  70. log.error("topic is error:{}",topics);
  71. }
  72. }
  73. public void heartbeat(String data){
  74. try {
  75. HeartBeat heartBeat = JSONUtil.toBean(data, HeartBeat.class);
  76. heartBeat.setHeartId(0L);
  77. heartBeat.setCreateTime(new Date());
  78. SiteInfo siteInfo = siteInfoMapper.queryBySiteCode(heartBeat.getId());
  79. if (siteInfo == null){
  80. log.error("查询站点失败入库失败 站码:{}",heartBeat.getId());
  81. return;
  82. }
  83. heartBeat.setSiteId(siteInfo.getSiteId());
  84. heartBeatMapper.insert(heartBeat);
  85. log.info("insert heartbeat:{}",heartBeat);
  86. } catch (Exception e) {
  87. log.error("存入心跳 入库错误:",e);
  88. }
  89. }
  90. public void startMeasure(String data){
  91. try {
  92. TaskNotice taskNotice = JSONUtil.toBean(data, TaskNotice.class);
  93. SiteInfo siteInfo = siteInfoMapper.queryBySiteCode(taskNotice.getId());
  94. if (siteInfo == null) {
  95. log.error("查询站点失败入库失败 站码:{}", taskNotice.getId());
  96. return;
  97. }
  98. taskNotice.setStartId(0L);
  99. if (taskNotice.getWorkmode() == 1) {
  100. taskNotice.setRemark("时间任务触发 开始测流任务");
  101. } else if (taskNotice.getWorkmode() == 2) {
  102. taskNotice.setRemark("变幅任务触发 开始测流任务");
  103. } else if (taskNotice.getWorkmode() == 3) {
  104. taskNotice.setRemark("手动任务触发 开始测流任务");
  105. }
  106. taskNotice.setCreateTime(new Date());
  107. taskNotice.setSiteId(siteInfo.getSiteId());
  108. taskNoticeMapper.insert(taskNotice);
  109. //新建结果报告 状态设置为测流中
  110. TaskResult taskResult = new TaskResult();
  111. taskResult.setResultId(0L);
  112. taskResult.setTaskid(taskNotice.getTaskid());
  113. taskResult.setStatus(0);
  114. taskResult.setSiteId(siteInfo.getSiteId());
  115. taskResult.setCreateTime(new Date());
  116. taskResultMapper.insert(taskResult);
  117. } catch (Exception e) {
  118. log.error("开始测流 入库错误:",e);
  119. }
  120. }
  121. public void taskFault(String data) {
  122. try {
  123. TaskNotice taskNotice = JSONUtil.toBean(data, TaskNotice.class);
  124. SiteInfo siteInfo = siteInfoMapper.queryBySiteCode(taskNotice.getId());
  125. if (siteInfo == null) {
  126. log.error("查询站点失败入库失败 站码:{}", taskNotice.getId());
  127. return;
  128. }
  129. taskNotice.setStartId(0L);
  130. taskNotice.setRemark("任务故障");
  131. taskNotice.setCreateTime(new Date());
  132. taskNotice.setSiteId(siteInfo.getSiteId());
  133. taskNoticeMapper.insert(taskNotice);
  134. } catch (Exception e) {
  135. log.error("任务故障 入库错误:", e);
  136. }
  137. }
  138. public void positionUpdate(String data){
  139. try {
  140. CarPosition carPosition= JSONUtil.toBean(data, CarPosition.class);
  141. SiteInfo siteInfo = siteInfoMapper.queryBySiteCode(carPosition.getId());
  142. if (siteInfo == null) {
  143. log.error("查询站点失败入库失败 站码:{}", carPosition.getId());
  144. return;
  145. }
  146. carPosition.setSiteId(siteInfo.getSiteId());
  147. carPosition.setCarId(0L);
  148. carPosition.setCreateTime(new Date());
  149. carPositionMapper.insert(carPosition);
  150. } catch (Exception e) {
  151. log.error("小车位置 入库错误:", e);
  152. }
  153. }
  154. public void measureBegin(String data){
  155. try {
  156. TaskNotice taskNotice = JSONUtil.toBean(data, TaskNotice.class);
  157. SiteInfo siteInfo = siteInfoMapper.queryBySiteCode(taskNotice.getId());
  158. if (siteInfo == null) {
  159. log.error("查询站点失败入库失败 站码:{}", taskNotice.getId());
  160. return;
  161. }
  162. taskNotice.setStartId(0L);
  163. taskNotice.setRemark(taskNotice.getPn() + "号停泊点开始测流");
  164. taskNotice.setCreateTime(new Date());
  165. taskNotice.setSiteId(siteInfo.getSiteId());
  166. taskNoticeMapper.insert(taskNotice);
  167. } catch (Exception e) {
  168. log.error("停泊点开始测流 入库错误:", e);
  169. }
  170. }
  171. public void measureUpload(String data){
  172. try {
  173. MeasureUpload measureUpload= JSONUtil.toBean(data, MeasureUpload.class);
  174. SiteInfo siteInfo = siteInfoMapper.queryBySiteCode(measureUpload.getId());
  175. if (siteInfo == null) {
  176. log.error("查询站点失败入库失败 站码:{}", measureUpload.getId());
  177. return;
  178. }
  179. measureUpload.setSiteId(siteInfo.getSiteId());
  180. measureUpload.setMeasureId(0L);
  181. measureUpload.setCreateTime(new Date());
  182. measureUploadMapper.insert(measureUpload);
  183. } catch (Exception e) {
  184. log.error("停泊点流速上报 入库错误:", e);
  185. }
  186. }
  187. public void taskend(String data){
  188. try {
  189. TaskNotice taskNotice = JSONUtil.toBean(data, TaskNotice.class);
  190. SiteInfo siteInfo = siteInfoMapper.queryBySiteCode(taskNotice.getId());
  191. if (siteInfo == null) {
  192. log.error("查询站点失败入库失败 站码:{}", taskNotice.getId());
  193. return;
  194. }
  195. taskNotice.setStartId(0L);
  196. taskNotice.setRemark("小车任务完成");
  197. taskNotice.setCreateTime(new Date());
  198. taskNotice.setSiteId(siteInfo.getSiteId());
  199. taskNoticeMapper.insert(taskNotice);
  200. } catch (Exception e) {
  201. log.error("小车任务完成 入库错误:", e);
  202. }
  203. }
  204. public void waterLevelUpload(String data){
  205. try {
  206. WaterLevel waterLevel = JSONUtil.toBean(data, WaterLevel.class);
  207. SiteInfo siteInfo = siteInfoMapper.queryBySiteCode(waterLevel.getId());
  208. if (siteInfo == null) {
  209. log.error("查询站点失败入库失败 站码:{}", waterLevel.getId());
  210. return;
  211. }
  212. waterLevel.setCreateTime(new Date());
  213. waterLevel.setWaterId(0L);
  214. waterLevel.setSiteId(siteInfo.getSiteId());
  215. waterLevelMapper.insert(waterLevel);
  216. } catch (Exception e) {
  217. log.error("小车任务完成 入库错误:", e);
  218. }
  219. }
  220. public void xiaoReturn(String data){
  221. try {
  222. TaskNotice taskNotice = JSONUtil.toBean(data, TaskNotice.class);
  223. SiteInfo siteInfo = siteInfoMapper.queryBySiteCode(taskNotice.getId());
  224. if (siteInfo == null) {
  225. log.error("查询站点失败入库失败 站码:{}", taskNotice.getId());
  226. return;
  227. }
  228. taskNotice.setStartId(0L);
  229. taskNotice.setRemark("小车开始返航");
  230. taskNotice.setCreateTime(new Date());
  231. taskNotice.setSiteId(siteInfo.getSiteId());
  232. taskNoticeMapper.insert(taskNotice);
  233. } catch (Exception e) {
  234. log.error("小车返航 入库错误:", e);
  235. }
  236. }
  237. public void resultUpload(String data){
  238. try {
  239. TaskResult taskResult = JSONUtil.toBean(data, TaskResult.class);
  240. SiteInfo siteInfo = siteInfoMapper.queryBySiteCode(taskResult.getId());
  241. if (siteInfo == null) {
  242. log.error("查询站点失败入库失败 站码:{}", taskResult.getId());
  243. return;
  244. }
  245. TaskResult one = taskResultMapper.queryByTaskid(taskResult.getTaskid());
  246. if (one == null) {
  247. log.error("测流结果上报 数据更新失败 taskid {}", taskResult.getTaskid());
  248. return;
  249. }
  250. taskResult.setResultId(one.getResultId());
  251. taskResult.setStatus(2);
  252. taskResultMapper.update(taskResult);
  253. } catch (Exception e) {
  254. log.error("测流结果上报 入库错误:", e);
  255. }
  256. }
  257. }