Browse Source

add SingleDevice kafka

459242451@qq.com 3 years ago
parent
commit
b94d5c1e67

+ 6 - 0
README.md

@@ -113,4 +113,10 @@ test02/12345678
 
 http://sqpc.xt.wenhq.top:8083/
 
+> 宿迁本地部署
+```
+docker build -t 10.211.55.3:18080/hses/yjzh_server:v3.1 .
+docker push 10.211.55.3:18080/hses/yjzh_server:v3.1
+```
+
 

+ 25 - 1
ruoyi-admin/src/main/java/com/ruoyi/web/controller/task/SysGatewayUserTask.java

@@ -1,6 +1,10 @@
 package com.ruoyi.web.controller.task;
 
+import cn.hutool.core.convert.Convert;
+import cn.hutool.json.JSONArray;
+import cn.hutool.json.JSONObject;
 import cn.hutool.json.JSONUtil;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.ruoyi.common.core.domain.entity.SysDept;
 import com.ruoyi.common.core.domain.entity.SysUser;
 import com.ruoyi.system.service.ISysDeptService;
@@ -8,6 +12,10 @@ import com.ruoyi.system.service.ISysUserService;
 import com.ruoyi.zhdd.domain.GatewayDept;
 import com.ruoyi.zhdd.domain.GatewayOrg;
 import com.ruoyi.zhdd.domain.GatewaySUser;
+import com.ruoyi.zhdd.domain.SingleDevice;
+import com.ruoyi.zhdd.domain.bo.SingleDeviceBo;
+import com.ruoyi.zhdd.domain.vo.SingleDeviceVo;
+import com.ruoyi.zhdd.service.ISingleDeviceService;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.kafka.annotation.KafkaListener;
@@ -26,6 +34,9 @@ public class SysGatewayUserTask {
     @Autowired
     ISysDeptService deptService;
 
+    @Autowired
+    private ISingleDeviceService singleDeviceService;
+
     @KafkaListener(topics = "t_uc_user")
     public void onUserMessage(String message){
         log.info("kafka用户信息消费:{}", message);
@@ -214,9 +225,22 @@ public class SysGatewayUserTask {
         System.out.println(message);
     }
 
-    @KafkaListener(topics = "executestation_5ee63b516d4e4d79a46cdf88a202caa1"/*, groupId = "huashe-consumer-group"*/)
+    @KafkaListener(topics = "executestation_5ee63b516d4e4d79a46cdf88a202caa1")
     public void onDeviceMessage(String message){
         log.info("kafka单兵设备信息消费:{}", message);
+        JSONObject jsonObject = JSONUtil.parseObj(message);
+        JSONObject info = jsonObject.getJSONObject("info");
+        if (info != null) {
+            JSONArray gps = info.getJSONArray("gps");
+            if (gps != null && !gps.isEmpty()) {
+                for (Object gp : gps) {
+                    SingleDeviceBo singleDeviceBo = JSONUtil.toBean(Convert.toStr(gp), SingleDeviceBo.class);
+                    // 根据deviceCod删除再新增
+                    singleDeviceService.remove(Wrappers.<SingleDevice>lambdaQuery().eq(SingleDevice::getDeviceCode, singleDeviceBo.getDeviceCode()));
+                    singleDeviceService.insertByBo(singleDeviceBo);
+                }
+            }
+        }
     }
 
 }

+ 2 - 2
ruoyi-admin/src/main/java/com/ruoyi/web/controller/zhdd/SingleDeviceController.java

@@ -48,8 +48,8 @@ public class SingleDeviceController extends BaseController {
     @ApiOperation("查询单兵数据信息列表")
     @PreAuthorize("@ss.hasPermi('zhdd:singleDevice:list')")
     @GetMapping("/list")
-    public TableDataInfo<SingleDeviceVo> list(@Validated(QueryGroup.class) SingleDeviceBo bo) {
-        return iSingleDeviceService.queryPageList(bo);
+    public AjaxResult<List<SingleDeviceVo>> list(@Validated(QueryGroup.class) SingleDeviceBo bo) {
+        return AjaxResult.success(iSingleDeviceService.queryList(bo));
     }
 
     /**

+ 2 - 0
ruoyi-zhdd/src/main/java/com/ruoyi/zhdd/domain/SingleDevice.java

@@ -93,4 +93,6 @@ public class SingleDevice implements Serializable {
      */
     private String deviceExtendInfo;
 
+    private String channelId;
+
 }

+ 1 - 0
ruoyi-zhdd/src/main/java/com/ruoyi/zhdd/domain/bo/SingleDeviceBo.java

@@ -109,6 +109,7 @@ public class SingleDeviceBo extends BaseEntity {
     @ApiModelProperty(value = "设备的扩展信息")
     private String deviceExtendInfo;
 
+    private String channelId;
 
     /**
      * 分页大小

+ 2 - 0
ruoyi-zhdd/src/main/java/com/ruoyi/zhdd/domain/vo/SingleDeviceVo.java

@@ -125,5 +125,7 @@ public class SingleDeviceVo {
 	@ApiModelProperty("设备的扩展信息")
 	private String deviceExtendInfo;
 
+    private String channelId;
+
 
 }