Browse Source

物联网

home 2 years ago
parent
commit
b04c0c1046

+ 5 - 0
hx-service-api/syringe-production-api/src/main/java/com/fjhx/constants/RedisConstant.java

@@ -6,4 +6,9 @@ public interface RedisConstant {
 
     String DATA_AUTOCLAVES = PREFIX + "dataAutoclaves:";
 
+    /**
+     * 设备数据前缀
+     */
+    String DEVICE_PREFIX = "device:";
+
 }

+ 0 - 69
hx-service-api/syringe-production-api/src/main/java/com/fjhx/entity/amqp/AmqpData.java

@@ -1,69 +0,0 @@
-package com.fjhx.entity.amqp;
-
-import com.baomidou.mybatisplus.annotation.IdType;
-import com.baomidou.mybatisplus.annotation.TableId;
-import lombok.Data;
-
-import java.io.Serializable;
-import java.util.Date;
-
-/**
- * <p>
- *
- * </p>
- *
- * @author ${author}
- * @since 2022-07-27
- */
-@Data
-public class AmqpData implements Serializable {
-
-    private static final long serialVersionUID = 1L;
-
-    /**
-     * 主键id
-     */
-    @TableId(value = "id", type = IdType.ASSIGN_ID)
-    private Long id;
-
-    /**
-     * 设备编号
-     */
-    private String equipmentNo;
-
-    /**
-     * 设备IP地址
-     */
-    private String ipAddress;
-
-    /**
-     * 设备端口号
-     */
-    private Integer port;
-
-    /**
-     * 设备类型
-     */
-    private Integer type;
-
-    /**
-     * 数据获取时间
-     */
-    private Date obtainTime;
-
-    /**
-     * 数据
-     */
-    private String dataInfo;
-
-    /**
-     * 获取数据状态 1成功 0失败
-     */
-    private Integer status;
-
-    /**
-     * 创建时间
-     */
-    private Date createTime;
-
-}

+ 0 - 17
hx-service-api/syringe-production-api/src/main/java/com/fjhx/params/amqp/AmqpDataEx.java

@@ -1,17 +0,0 @@
-package com.fjhx.params.amqp;
-
-import com.fjhx.entity.amqp.AmqpData;
-import lombok.Data;
-import lombok.EqualsAndHashCode;
-
-/**
- * 
- *
- * @author ${author}
- * @since 2022-07-27
- */
-@Data
-@EqualsAndHashCode(callSuper = true)
-public class AmqpDataEx extends AmqpData {
-
-}

+ 0 - 17
hx-service-api/syringe-production-api/src/main/java/com/fjhx/params/amqp/AmqpDataVo.java

@@ -1,17 +0,0 @@
-package com.fjhx.params.amqp;
-
-import com.fjhx.entity.amqp.AmqpData;
-import lombok.Data;
-import lombok.EqualsAndHashCode;
-
-/**
- * 
- *
- * @author ${author}
- * @since 2022-07-27
- */
-@Data
-@EqualsAndHashCode(callSuper = true)
-public class AmqpDataVo extends AmqpData {
-
-}

+ 0 - 28
hx-service/syringe-production/src/main/java/com/fjhx/controller/amqp/AmqpController.java

@@ -1,28 +0,0 @@
-package com.fjhx.controller.amqp;
-
-import com.fjhx.constants.IotProductionRedisPrefixConstant;
-import com.fjhx.entity.amqp.AmqpData;
-import org.springblade.core.redis.cache.BladeRedis;
-import org.springblade.core.tool.api.R;
-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 javax.annotation.Resource;
-import java.util.Map;
-
-@RestController
-@RequestMapping("/amqpData")
-public class AmqpController {
-
-    @Resource
-    private BladeRedis redisCache;
-
-    @PostMapping("/getEquipmentInfo")
-    public R getEquipmentInfo(@RequestBody Map<String, String> condition) {
-        AmqpData equipmentNo = redisCache.get(IotProductionRedisPrefixConstant.INSTANTANEOUS_STATE + condition.get("equipmentNo"));
-        return R.success(equipmentNo);
-    }
-
-}

+ 3 - 4
hx-service/syringe-production/src/main/java/com/fjhx/controller/factory/FactoryProductController.java

@@ -1,9 +1,8 @@
 package com.fjhx.controller.factory;
 
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.fjhx.constants.RedisConstant;
 import com.fjhx.entity.factory.FactoryProduct;
-import com.fjhx.listener.IotDataListener;
-import com.fjhx.params.IotData.MessageBody;
 import com.fjhx.params.factory.FactoryProductVo;
 import com.fjhx.service.factory.FactoryProductService;
 import org.springblade.core.redis.cache.BladeRedis;
@@ -38,8 +37,8 @@ public class FactoryProductController {
 
     @PostMapping("/getData")
     public R getData(@RequestBody FactoryProduct factoryProduct) {
-        MessageBody.Service service = redisCache.get(IotDataListener.DEVICE_PREFIX + factoryProduct.getEquipmentNo());
-        return R.success(service);
+        Object data = redisCache.get(RedisConstant.DEVICE_PREFIX + factoryProduct.getEquipmentNo());
+        return R.success(data);
     }
 
     @PostMapping("/list")

+ 4 - 6
hx-service/syringe-production/src/main/java/com/fjhx/listener/IotDataListener.java

@@ -1,6 +1,7 @@
 package com.fjhx.listener;
 
 import com.alibaba.fastjson.JSONObject;
+import com.fjhx.constants.RedisConstant;
 import com.fjhx.enums.ProductEnum;
 import com.fjhx.params.IotData.MessageBody;
 import com.fjhx.params.IotData.UpperComputerData;
@@ -25,9 +26,6 @@ import java.util.List;
 @Component
 public class IotDataListener {
 
-    // 设备前缀
-    public static final String DEVICE_PREFIX = "device:";
-
     @Resource
     private BladeRedis redisCache;
 
@@ -107,7 +105,7 @@ public class IotDataListener {
     private void appointProductHandle(ProductEnum productEnum, Message message, List<MessageBody.Service> services) {
         // 获取设备编号
         String equipmentNo = productEnum.getEquipmentNo();
-        String redisKey = DEVICE_PREFIX + equipmentNo;
+        String redisKey = RedisConstant.DEVICE_PREFIX + equipmentNo;
 
         MessageBody.Service oldService = redisCache.get(redisKey);
         MessageBody.Service newService = services.get(0);
@@ -124,14 +122,14 @@ public class IotDataListener {
     }
 
     /**
-     * 默认处理
+     * 上位机连接设备处理
      */
     private void upperComputerHandle(Message message, List<MessageBody.Service> services) {
         MessageBody.Service service = services.get(0);
 
         UpperComputerData newData = service.getProperties().toJavaObject(UpperComputerData.class);
 
-        String redisKey = DEVICE_PREFIX + newData.getEquipmentNo();
+        String redisKey = RedisConstant.DEVICE_PREFIX + newData.getEquipmentNo();
         UpperComputerData oldData = redisCache.get(redisKey);
 
         if (oldData == null || newData.getCreateTime().compareTo(oldData.getCreateTime()) > 0) {

+ 0 - 16
hx-service/syringe-production/src/main/java/com/fjhx/mapper/amqp/AmqpDataMapper.java

@@ -1,16 +0,0 @@
-package com.fjhx.mapper.amqp;
-
-import com.fjhx.entity.amqp.AmqpData;
-import com.baomidou.mybatisplus.core.mapper.BaseMapper;
-
-/**
- * <p>
- *  Mapper 接口
- * </p>
- *
- * @author ${author}
- * @since 2022-07-27
- */
-public interface AmqpDataMapper extends BaseMapper<AmqpData> {
-
-}

+ 0 - 5
hx-service/syringe-production/src/main/java/com/fjhx/mapper/amqp/AmqpDataMapper.xml

@@ -1,5 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
-<mapper namespace="com.fjhx.mapper.amqp.AmqpDataMapper">
-
-</mapper>

+ 0 - 16
hx-service/syringe-production/src/main/java/com/fjhx/service/amqp/AmqpDataService.java

@@ -1,16 +0,0 @@
-package com.fjhx.service.amqp;
-
-import com.fjhx.base.BaseService;
-import com.fjhx.entity.amqp.AmqpData;
-
-/**
- * <p>
- * 服务类
- * </p>
- *
- * @author ${author}
- * @since 2022-07-27
- */
-public interface AmqpDataService extends BaseService<AmqpData> {
-
-}

+ 0 - 92
hx-service/syringe-production/src/main/java/com/fjhx/service/amqp/impl/AmqpDataServiceImpl.java

@@ -1,92 +0,0 @@
-package com.fjhx.service.amqp.impl;
-
-import com.alibaba.fastjson.JSONObject;
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import com.fjhx.constants.IotProductionRedisPrefixConstant;
-import com.fjhx.entity.amqp.AmqpData;
-import com.fjhx.mapper.amqp.AmqpDataMapper;
-import com.fjhx.service.amqp.AmqpDataService;
-import lombok.extern.slf4j.Slf4j;
-import org.springblade.core.redis.cache.BladeRedis;
-import org.springframework.stereotype.Service;
-
-import javax.annotation.Resource;
-import javax.jms.JMSException;
-import javax.jms.Message;
-import java.util.Collection;
-import java.util.Date;
-import java.util.List;
-import java.util.stream.Collectors;
-
-/**
- * <p>
- * 服务实现类
- * </p>
- *
- * @author ${author}
- * @since 2022-07-27
- */
-@Service
-@Slf4j
-public class AmqpDataServiceImpl extends ServiceImpl<AmqpDataMapper, AmqpData> implements AmqpDataService {
-
-    @Resource
-    private BladeRedis redisCache;
-
-    private void saveData(Message message) {
-        try {
-
-            JSONObject jsonObject = JSONObject.parseObject(message.getBody(String.class));
-
-            JSONObject bodyObj = jsonObject
-                    .getJSONObject("notify_data")
-                    .getJSONObject("body");
-
-            // 设备状态
-            String status = bodyObj.getString("status");
-            if (status != null) {
-                System.out.println(jsonObject);
-                return;
-            }
-
-            String dataStr = bodyObj.getJSONArray("services")
-                    .getJSONObject(0)
-                    .getJSONObject("properties")
-                    .getString("DeviceData");
-
-            List<AmqpData> amqpDataList = JSONObject.parseArray(dataStr, AmqpData.class);
-            Date date = new Date();
-            amqpDataList.forEach(item -> item.setCreateTime(date));
-
-            saveInstantaneousState(amqpDataList);
-            saveBatch(amqpDataList);
-
-            message.acknowledge();
-
-        } catch (JMSException e) {
-            e.printStackTrace();
-        }
-    }
-
-    /**
-     * 保存设备最新状态
-     */
-    private void saveInstantaneousState(List<AmqpData> amqpDataList) {
-        Collection<AmqpData> amqpDataCollection = amqpDataList.stream().collect(Collectors.toMap(
-                AmqpData::getEquipmentNo,
-                item -> item,
-                (v1, v2) -> (v1.getObtainTime().compareTo(v2.getObtainTime()) > 0) ? v1 : v2
-        )).values();
-
-        for (AmqpData item : amqpDataCollection) {
-            String equipmentNo = item.getEquipmentNo();
-
-            String redisKey = IotProductionRedisPrefixConstant.INSTANTANEOUS_STATE + equipmentNo;
-            AmqpData amqpData = redisCache.get(redisKey);
-            if (amqpData == null || item.getObtainTime().compareTo(amqpData.getObtainTime()) > 0) {
-                redisCache.setEx(redisKey, item, 40L);
-            }
-        }
-    }
-
-}