yangdi пре 4 година
родитељ
комит
4365f9faf4

+ 63 - 0
huimv-test-platform/huimv-ctwing/src/main/java/com/huimv/devicedata/controller/DeviceIncidentreportController.java

@@ -0,0 +1,63 @@
+package com.huimv.devicedata.controller;
+
+import com.alibaba.fastjson.JSONObject;
+import com.huimv.devicedata.service.IDeviceDataService;
+import com.huimv.devicedata.service.IDeviceIncidentReportService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.util.Calendar;
+import java.util.Date;
+
+/**
+ * @Project : huimv.shiwan
+ * @Package : com.huimv.biosafety.uface.controller
+ * @Description : TODO
+ * @Version : 1.0
+ * @Author : ZhuoNing
+ * @Create : 2020-12-25
+ **/
+@RestController
+@RequestMapping(value = "/deviceData",method = RequestMethod.POST)
+public class DeviceIncidentreportController {
+    public static Logger logger = LoggerFactory.getLogger(DeviceIncidentreportController.class);
+    @Autowired
+    private IDeviceIncidentReportService iDeviceIncidentReportService ;
+
+    @RequestMapping(value = "/deviceIncidentReport",method = {RequestMethod.POST,RequestMethod.GET})
+    public String deviceUpAndDown(HttpServletRequest request, HttpServletResponse response){
+        long startTime = Calendar.getInstance().getTimeInMillis();
+        Date startDate = new Date(startTime);
+        java.text.SimpleDateFormat f = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        logger.info("开始接收时间:"+f.format(startDate));
+        StringBuffer resultStr = new StringBuffer("");
+        try{
+            BufferedReader br = new BufferedReader(new InputStreamReader(request.getInputStream(),"utf-8"));
+            StringBuffer sb = new StringBuffer("");
+            String temp;
+            while ((temp = br.readLine()) != null){
+                sb.append(temp);
+            }
+            br.close();
+            //真正接收到的数据
+            String result = sb.toString();
+            System.out.println("接收到数据result>>"+result);
+//          result = "{'upPacketSN':-1,'upDataSN':-1,'topic':'v1/up/ad19','timestamp':1617172207604,'tenantId':'2000031842','serviceId':12,'protocol':'lwm2m','productId':'15039192','payload':{'VER':1,'TIME':15,'TEMP':201,'STC':94,'RSSI':18,'HUMI':564,'BAT':3600},'messageType':'dataReport','deviceType':'','deviceId':'488200bd80e14a97826c95834dee135e','assocAssetId':'','IMSI':'undefined','IMEI':'864333043632975'}";
+            JSONObject deviceUpDataJson = JSONObject.parseObject(result);
+            // 保存设备上传数据
+            iDeviceIncidentReportService.saveDeviceIncidentReport(deviceUpDataJson);
+        }catch (Exception e){
+            e.printStackTrace();
+        }
+//        return resultStr;
+        return "200";
+    }
+}

+ 57 - 0
huimv-test-platform/huimv-ctwing/src/main/java/com/huimv/devicedata/controller/DeviceUpAndDown.java

@@ -0,0 +1,57 @@
+package com.huimv.devicedata.controller;
+
+import com.alibaba.fastjson.JSONObject;
+import com.huimv.devicedata.service.IDeviceDataService;
+import com.huimv.devicedata.service.IDeviceUpAndDownService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.util.Calendar;
+import java.util.Date;
+
+@RestController
+@RequestMapping(value = "/deviceData",method = RequestMethod.POST)
+public class DeviceUpAndDown {
+    public static Logger logger = LoggerFactory.getLogger(DeviceDataController.class);
+    @Autowired
+    private IDeviceUpAndDownService iDeviceUpAndDownService ;
+
+    @RequestMapping(value = "/deviceUpAndDown",method = {RequestMethod.POST,RequestMethod.GET})
+    public String deviceUpAndDown(HttpServletRequest request, HttpServletResponse response){
+        long startTime = Calendar.getInstance().getTimeInMillis();
+        Date startDate = new Date(startTime);
+        java.text.SimpleDateFormat f = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        logger.info("开始接收时间:"+f.format(startDate));
+        StringBuffer resultStr = new StringBuffer("");
+        try{
+            BufferedReader br = new BufferedReader(new InputStreamReader(request.getInputStream(),"utf-8"));
+            StringBuffer sb = new StringBuffer("");
+            String temp;
+            while ((temp = br.readLine()) != null){
+                sb.append(temp);
+            }
+            br.close();
+            //真正接收到的数据
+            String result = sb.toString();
+            System.out.println("接收到数据result>>"+result);
+//          result = "{'upPacketSN':-1,'upDataSN':-1,'topic':'v1/up/ad19','timestamp':1617172207604,'tenantId':'2000031842','serviceId':12,'protocol':'lwm2m','productId':'15039192','payload':{'VER':1,'TIME':15,'TEMP':201,'STC':94,'RSSI':18,'HUMI':564,'BAT':3600},'messageType':'dataReport','deviceType':'','deviceId':'488200bd80e14a97826c95834dee135e','assocAssetId':'','IMSI':'undefined','IMEI':'864333043632975'}";
+            JSONObject deviceUpDataJo = JSONObject.parseObject(result);
+            // 保存设备上传数据
+            //更改
+            iDeviceUpAndDownService.DeviceUpAndDown(deviceUpDataJo);
+        }catch (Exception e){
+            e.printStackTrace();
+        }
+//        return resultStr;
+        return "200";
+    }
+}
+

+ 180 - 0
huimv-test-platform/huimv-ctwing/src/main/java/com/huimv/devicedata/entity/DeviceIncidentReport.java

@@ -0,0 +1,180 @@
+package com.huimv.devicedata.entity;
+
+
+import javax.persistence.*;
+import java.io.Serializable;
+
+
+
+@Entity
+@Table(name = "device_incident_report")
+public class DeviceIncidentReport implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    @Id
+    @Column(name = "id", nullable = false)
+    @GeneratedValue(strategy = GenerationType.IDENTITY)
+    private Integer id;
+
+    @Column(name = "tenantId")
+    private String tenantId;
+
+    @Column(name = "productId")
+    private String productId;
+
+    @Column(name = "deviceId")
+    private String deviceId;
+
+    @Column(name = "messageType")
+    private String messageType;
+
+    @Column(name = "imei")
+    private String imei;
+
+    @Column(name = "imsi")
+    private String imsi;
+
+    @Column(name = "deviceSn")
+    private String deviceSn;
+
+    @Column(name = "timestamp")
+    private String timestamp;
+
+    @Column(name = "eventType")
+    private Integer eventType;
+
+    @Column(name = "eventContent")
+    private String eventContent;
+
+    @Column(name = "serviceId")
+    private Integer serviceId;
+
+    @Column(name = "protocol")
+    private String protocol;
+    // device_incident_report
+
+    public static long getSerialVersionUID() {
+        return serialVersionUID;
+    }
+
+    public Integer getId() {
+        return id;
+    }
+
+    public void setId(Integer id) {
+        this.id = id;
+    }
+
+    public String getTenantId() {
+        return tenantId;
+    }
+
+    public void setTenantId(String tenantId) {
+        this.tenantId = tenantId;
+    }
+
+    public String getProductId() {
+        return productId;
+    }
+
+    public void setProductId(String productId) {
+        this.productId = productId;
+    }
+
+    public String getDeviceId() {
+        return deviceId;
+    }
+
+    public void setDeviceId(String deviceId) {
+        this.deviceId = deviceId;
+    }
+
+    public String getMessageType() {
+        return messageType;
+    }
+
+    public void setMessageType(String messageType) {
+        this.messageType = messageType;
+    }
+
+    public String getImei() {
+        return imei;
+    }
+
+    public void setImei(String imei) {
+        this.imei = imei;
+    }
+
+    public String getImsi() {
+        return imsi;
+    }
+
+    public void setImsi(String imsi) {
+        this.imsi = imsi;
+    }
+
+    public String getDeviceSn() {
+        return deviceSn;
+    }
+
+    public void setDeviceSn(String deviceSn) {
+        this.deviceSn = deviceSn;
+    }
+
+
+    public void setTimestamp(String timestamp) {
+        this.timestamp = timestamp;
+    }
+
+    public Integer getEventType() {
+        return eventType;
+    }
+
+    public void setEventType(Integer eventType) {
+        this.eventType = eventType;
+    }
+
+    public String getEventContent() {
+        return eventContent;
+    }
+
+    public void setEventContent(String eventContent) {
+        this.eventContent = eventContent;
+    }
+
+    public Integer getServiceId() {
+        return serviceId;
+    }
+
+    public void setServiceId(Integer serviceId) {
+        this.serviceId = serviceId;
+    }
+
+    public String getProtocol() {
+        return protocol;
+    }
+
+    public void setProtocol(String protocol) {
+        this.protocol = protocol;
+    }
+
+    @Override
+    public String toString() {
+        return "DeviceIncidentReport{" +
+                "id=" + id +
+                ", tenantId='" + tenantId + '\'' +
+                ", productId='" + productId + '\'' +
+                ", deviceId='" + deviceId + '\'' +
+                ", messageType='" + messageType + '\'' +
+                ", imei='" + imei + '\'' +
+                ", imsi='" + imsi + '\'' +
+                ", deviceSn='" + deviceSn + '\'' +
+                ", timestamp=" + timestamp +
+                ", eventType=" + eventType +
+                ", eventContent='" + eventContent + '\'' +
+                ", serviceId=" + serviceId +
+                ", protocol='" + protocol + '\'' +
+                '}';
+    }
+}

+ 111 - 0
huimv-test-platform/huimv-ctwing/src/main/java/com/huimv/devicedata/entity/DeviceUpAndDown.java

@@ -0,0 +1,111 @@
+package com.huimv.devicedata.entity;
+
+
+import javax.persistence.*;
+import java.io.Serializable;
+
+
+
+@Entity
+@Table(name = "device_up_and_down")
+public class DeviceUpAndDown implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    @Id
+    @Column(name = "id", nullable = false)
+    @GeneratedValue(strategy = GenerationType.IDENTITY)
+    private Integer id;
+
+    @Column(name = "tenantId")
+    private String tenantId;
+
+    @Column(name = "productId")
+    private String productId;
+
+    @Column(name = "deviceId")
+    private String deviceId;
+
+    @Column(name = "messageType")
+    private String messageType;
+
+    @Column(name = "eventType")
+    private Integer eventType;
+
+    @Column(name = "timestamp")
+    private String timestamp;
+
+    public static long getSerialVersionUID() {
+        return serialVersionUID;
+    }
+
+    public Integer getId() {
+        return id;
+    }
+
+    public void setId(Integer id) {
+        this.id = id;
+    }
+
+    public String getTenantId() {
+        return tenantId;
+    }
+
+    public void setTenantId(String tenantId) {
+        this.tenantId = tenantId;
+    }
+
+    public String getProductId() {
+        return productId;
+    }
+
+    public void setProductId(String productId) {
+        this.productId = productId;
+    }
+
+    public String getDeviceId() {
+        return deviceId;
+    }
+
+    public void setDeviceId(String deviceId) {
+        this.deviceId = deviceId;
+    }
+
+    public String getMessageType() {
+        return messageType;
+    }
+
+    public void setMessageType(String messageType) {
+        this.messageType = messageType;
+    }
+
+    public Integer getEventType() {
+        return eventType;
+    }
+
+    public void setEventType(Integer eventType) {
+        this.eventType = eventType;
+    }
+
+    public void setTimestamp(String timestamp) {
+        this.timestamp = timestamp;
+    }
+
+    public String getTimestamp() {
+        return timestamp;
+    }
+
+
+    @Override
+    public String toString() {
+        return "DeviceUpAndDown{" +
+                "id=" + id +
+                ", tenantId='" + tenantId + '\'' +
+                ", productId='" + productId + '\'' +
+                ", deviceId='" + deviceId + '\'' +
+                ", messageType='" + messageType + '\'' +
+                ", eventType=" + eventType +
+                ", timestamp=" + timestamp +
+                '}';
+    }
+}

+ 9 - 0
huimv-test-platform/huimv-ctwing/src/main/java/com/huimv/devicedata/repo/DeviceIncidentReportRepository.java

@@ -0,0 +1,9 @@
+package com.huimv.devicedata.repo;
+
+import com.huimv.devicedata.entity.DeviceIncidentReport;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
+
+public interface DeviceIncidentReportRepository extends JpaRepository<DeviceIncidentReport, Integer>, JpaSpecificationExecutor<DeviceIncidentReport> {
+
+}

+ 9 - 0
huimv-test-platform/huimv-ctwing/src/main/java/com/huimv/devicedata/repo/DeviceUpAndDownRepository.java

@@ -0,0 +1,9 @@
+package com.huimv.devicedata.repo;
+
+import com.huimv.devicedata.entity.DeviceUpAndDown;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
+
+public interface DeviceUpAndDownRepository extends JpaRepository<DeviceUpAndDown, Integer>, JpaSpecificationExecutor<DeviceUpAndDown> {
+
+}

+ 9 - 0
huimv-test-platform/huimv-ctwing/src/main/java/com/huimv/devicedata/service/IDeviceIncidentReportService.java

@@ -0,0 +1,9 @@
+package com.huimv.devicedata.service;
+
+import com.alibaba.fastjson.JSONObject;
+
+public interface IDeviceIncidentReportService {
+
+    void saveDeviceIncidentReport(JSONObject deviceUpDataJson);
+
+}

+ 8 - 0
huimv-test-platform/huimv-ctwing/src/main/java/com/huimv/devicedata/service/IDeviceUpAndDownService.java

@@ -0,0 +1,8 @@
+package com.huimv.devicedata.service;
+
+import com.alibaba.fastjson.JSONObject;
+
+public interface IDeviceUpAndDownService {
+
+    void DeviceUpAndDown(JSONObject deviceUpDataJson);
+}

+ 60 - 0
huimv-test-platform/huimv-ctwing/src/main/java/com/huimv/devicedata/service/impl/IDeviceIncidentReportServiceImpl.java

@@ -0,0 +1,60 @@
+package com.huimv.devicedata.service.impl;
+
+import com.alibaba.fastjson.JSONObject;
+import com.huimv.devicedata.entity.DeviceIncidentReport;
+import com.huimv.devicedata.repo.DeviceIncidentReportRepository;
+import com.huimv.devicedata.service.IDeviceIncidentReportService;
+import com.huimv.devicedata.utils.DateUtil;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+
+
+@Service
+public class IDeviceIncidentReportServiceImpl implements IDeviceIncidentReportService {
+
+        @Autowired
+        DeviceIncidentReportRepository  deviceIncidentReportRepository ;
+
+        @Autowired
+        private DateUtil dateUtil;
+
+        @Override
+        public void saveDeviceIncidentReport(JSONObject deviceUpDataJo) {
+
+            String productId = deviceUpDataJo.getString("productId");
+            String deviceId = deviceUpDataJo.getString("deviceId");
+            long timestamp = deviceUpDataJo.getLong("timestamp");
+            String eventType = deviceUpDataJo.getString("eventType");
+            String upDataDate = dateUtil.formatLongDate(timestamp);
+            String serviceId = deviceUpDataJo.getString("serviceId");
+            String imsi = deviceUpDataJo.getString("imsi");
+            String imei = deviceUpDataJo.getString("imei");
+            String deviceSn = deviceUpDataJo.getString("deviceSn");
+            String messageType = deviceUpDataJo.getString("messageType");
+
+            String protocol = deviceUpDataJo.getString("protocol");
+            String tenantId = deviceUpDataJo.getString("tenantId");
+
+            JSONObject businessDataJo = deviceUpDataJo.getJSONObject("eventContent");  //再次解析嵌套
+
+            //eventContent":{"m":44}
+            int m = businessDataJo.getInteger("m");
+            DeviceIncidentReport deviceIncidentReport= new DeviceIncidentReport();
+            deviceIncidentReport.setProductId(productId); //*
+            deviceIncidentReport.setDeviceId(deviceId);//*
+            deviceIncidentReport.setTimestamp(upDataDate);
+            deviceIncidentReport.setServiceId( Integer.parseInt(serviceId));//*
+            deviceIncidentReport.setEventType( Integer.parseInt(eventType));//*
+            deviceIncidentReport.setImei(imei);//*
+            deviceIncidentReport.setImsi(imsi);//*
+            deviceIncidentReport.setDeviceSn(deviceSn);//*
+            deviceIncidentReport.setMessageType(messageType);//*
+            deviceIncidentReport.setTenantId(tenantId);//*
+            deviceIncidentReport.setProtocol(protocol);//*
+            deviceIncidentReport.setEventContent(Integer.toString(m));
+
+            deviceIncidentReportRepository.saveAndFlush(deviceIncidentReport);
+        }
+    }
+

+ 45 - 0
huimv-test-platform/huimv-ctwing/src/main/java/com/huimv/devicedata/service/impl/IDeviceUpAndDownServiceImpl.java

@@ -0,0 +1,45 @@
+package com.huimv.devicedata.service.impl;
+
+import com.alibaba.fastjson.JSONObject;
+import com.huimv.devicedata.entity.DeviceIncidentReport;
+import com.huimv.devicedata.entity.DeviceUpAndDown;
+import com.huimv.devicedata.repo.DeviceIncidentReportRepository;
+import com.huimv.devicedata.repo.DeviceUpAndDownRepository;
+import com.huimv.devicedata.service.IDeviceUpAndDownService;
+import com.huimv.devicedata.utils.DateUtil;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+
+@Service
+public class IDeviceUpAndDownServiceImpl implements IDeviceUpAndDownService {
+
+    @Autowired
+    DeviceUpAndDownRepository  deviceUpAndDownRepository ;
+
+    @Autowired
+    private DateUtil dateUtil;
+
+
+    @Override
+    public void DeviceUpAndDown(JSONObject deviceUpDataJo) {
+
+
+        String productId = deviceUpDataJo.getString("productId");//
+        String deviceId = deviceUpDataJo.getString("deviceId");//
+        long timestamp = deviceUpDataJo.getLong("timestamp");//
+        String eventType = deviceUpDataJo.getString("eventType");//
+        String upDataDate = dateUtil.formatLongDate(timestamp);
+        String messageType = deviceUpDataJo.getString("messageType");//
+        String tenantId = deviceUpDataJo.getString("tenantId");//
+
+        DeviceUpAndDown  deviceUpAndDown= new DeviceUpAndDown();
+        deviceUpAndDown.setProductId(productId); //*
+        deviceUpAndDown.setDeviceId(deviceId);//*
+        deviceUpAndDown.setTimestamp(upDataDate);
+        deviceUpAndDown.setEventType( Integer.parseInt(eventType));//*
+        deviceUpAndDown.setMessageType(messageType);//*
+        deviceUpAndDown.setTenantId(tenantId);//*
+        deviceUpAndDownRepository.save(deviceUpAndDown);
+    }
+}