|
@@ -0,0 +1,92 @@
|
|
|
+package com.sooka.sponest.event.centereventteventcatalogue.controller;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.dahuatech.icc.exception.ClientException;
|
|
|
+import com.ruoyi.common.core.domain.R;
|
|
|
+import com.ruoyi.common.core.utils.StringUtils;
|
|
|
+import com.ruoyi.common.core.web.domain.AjaxResult;
|
|
|
+import com.sooka.sponest.event.centereventteventcatalogue.domain.DaHuaEventBO;
|
|
|
+import com.sooka.sponest.event.centereventteventcatalogue.domain.sensor.SensorEventVo;
|
|
|
+import com.sooka.sponest.event.centereventteventcatalogue.service.AlarmEventService;
|
|
|
+import com.sooka.sponest.event.centereventtreportmessage.domain.CentereventTReportmessage;
|
|
|
+import com.sooka.sponest.event.centereventtreportmessage.service.ICentereventTReportmessageService;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.Date;
|
|
|
+
|
|
|
+@RestController
|
|
|
+@RequestMapping("/fireIncident")
|
|
|
+public class FireIncidentController {
|
|
|
+
|
|
|
+ protected final Logger logger = LoggerFactory.getLogger(this.getClass());
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private AlarmEventService alarmEventService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ICentereventTReportmessageService centereventTReportmessageService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 传感器事件上报
|
|
|
+ * @param sensorEventVo
|
|
|
+ * @return R
|
|
|
+ */
|
|
|
+ @PostMapping("/insertSensorEvent")
|
|
|
+ public R insertSensorEvent(@RequestBody SensorEventVo sensorEventVo) {
|
|
|
+ String eventCode = null;
|
|
|
+ try {
|
|
|
+ eventCode = alarmEventService.insertSensorEvent(sensorEventVo);
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error(e.getMessage());
|
|
|
+ }
|
|
|
+ if (StringUtils.isBlank(eventCode)) {
|
|
|
+ eventCode = String.valueOf(System.currentTimeMillis()) + "_";
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ String[] array = eventCode.split("_");
|
|
|
+ CentereventTReportmessage tReportMessage = new CentereventTReportmessage();
|
|
|
+ tReportMessage.setId(array[0]);
|
|
|
+ tReportMessage.setSource("传感器-" + array[1]);
|
|
|
+ tReportMessage.setContext(JSON.toJSONString(sensorEventVo));
|
|
|
+ centereventTReportmessageService.insertCentereventTReportmessage(tReportMessage);
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error(e.getMessage());
|
|
|
+ }
|
|
|
+ return R.ok();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 事件回查图片
|
|
|
+ * @param eventBO
|
|
|
+ * eventCode 事件编号
|
|
|
+ * logId 事件日志id
|
|
|
+ * @return AjaxResult
|
|
|
+ * @throws ClientException 异常类
|
|
|
+ */
|
|
|
+ @PostMapping("/updateFireEventImage")
|
|
|
+ public AjaxResult updateFireEventImage(@RequestBody DaHuaEventBO eventBO) throws ClientException {
|
|
|
+ CentereventTReportmessage centereventTReportmessage = null;
|
|
|
+ if (StringUtils.isNotBlank(eventBO.getEventCode()) && StringUtils.isNotBlank(eventBO.getLogId())) {
|
|
|
+ // 通过eventCode获取报文信息
|
|
|
+ centereventTReportmessage = centereventTReportmessageService.selectCentereventTReportmessageById(eventBO.getEventCode());
|
|
|
+ }
|
|
|
+ if (StringUtils.isNull(centereventTReportmessage)) {
|
|
|
+ return AjaxResult.success("参数异常");
|
|
|
+ }
|
|
|
+ // 解析报文
|
|
|
+ JSONObject context = JSONObject.parseObject(centereventTReportmessage.getContext()).getJSONObject("info");
|
|
|
+ eventBO.setAlarmCode(context.getString("alarmCode"));
|
|
|
+ eventBO.setAlarmDate(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(context.getLong("alarmDate"))));
|
|
|
+ eventBO.setDbType("0");
|
|
|
+ return AjaxResult.success(alarmEventService.updateFireEventImage(eventBO));
|
|
|
+ }
|
|
|
+}
|