浏览代码

Merge branch 'server-165' of uskycloud/usky-modules into master

gez 11 月之前
父节点
当前提交
e5d8dcb0a7
共有 27 个文件被更改,包括 736 次插入28 次删除
  1. 4 0
      service-agbox/service-agbox-biz/pom.xml
  2. 3 2
      service-agbox/service-agbox-biz/src/main/java/com/usky/agbox/controller/MybatisGeneratorUtils.java
  3. 53 0
      service-agbox/service-agbox-biz/src/main/java/com/usky/agbox/controller/web/PatrolInspectionAgboxController.java
  4. 61 0
      service-agbox/service-agbox-biz/src/main/java/com/usky/agbox/domain/PatrolInspectionAgbox.java
  5. 16 0
      service-agbox/service-agbox-biz/src/main/java/com/usky/agbox/mapper/PatrolInspectionAgboxMapper.java
  6. 19 0
      service-agbox/service-agbox-biz/src/main/java/com/usky/agbox/service/PatrolInspectionAgboxService.java
  7. 61 0
      service-agbox/service-agbox-biz/src/main/java/com/usky/agbox/service/config/rabbitmq/RabbitMQConfig.java
  8. 42 0
      service-agbox/service-agbox-biz/src/main/java/com/usky/agbox/service/impl/PatrolInspectionAgboxServiceImpl.java
  9. 34 10
      service-agbox/service-agbox-biz/src/main/java/com/usky/agbox/service/job/patrolAgbox.java
  10. 65 0
      service-agbox/service-agbox-biz/src/main/java/com/usky/agbox/service/listener/RabbitMQListener.java
  11. 2 2
      service-agbox/service-agbox-biz/src/main/resources/bootstrap.yml
  12. 16 0
      service-agbox/service-agbox-biz/src/main/resources/mapper/agbox/PatrolInspectionAgboxMapper.xml
  13. 4 1
      service-fire/service-fire-biz/pom.xml
  14. 2 1
      service-fire/service-fire-biz/src/main/java/com/usky/fire/RuoYiSystemApplication.java
  15. 5 0
      service-fire/service-fire-biz/src/main/java/com/usky/fire/controller/web/PatrolInspectionEventController.java
  16. 20 0
      service-fire/service-fire-biz/src/main/java/com/usky/fire/domain/PatrolInspectionEvent.java
  17. 70 0
      service-fire/service-fire-biz/src/main/java/com/usky/fire/service/config/rabbitmq/RabbitMQConfig.java
  18. 17 6
      service-fire/service-fire-biz/src/main/java/com/usky/fire/service/impl/PatrolInspectionAttendanceServiceImpl.java
  19. 84 1
      service-fire/service-fire-biz/src/main/java/com/usky/fire/service/impl/PatrolInspectionEventServiceImpl.java
  20. 35 0
      service-fire/service-fire-biz/src/main/java/com/usky/fire/service/listener/RabbitMQListener.java
  21. 17 0
      service-fire/service-fire-biz/src/main/java/com/usky/fire/service/vo/PatrolInspectionPlanRequestVO.java
  22. 4 0
      service-fire/service-fire-biz/src/main/resources/mapper/fire/PatrolInspectionEventMapper.xml
  23. 4 0
      service-iot/service-iot-biz/pom.xml
  24. 2 0
      service-iot/service-iot-biz/src/main/java/com/usky/iot/RuoYiSystemApplication.java
  25. 44 0
      service-iot/service-iot-biz/src/main/java/com/usky/iot/service/config/rabbitmq/RabbitMQConfig.java
  26. 23 5
      service-iot/service-iot-biz/src/main/java/com/usky/iot/service/impl/BaseAppInfoServiceImpl.java
  27. 29 0
      service-iot/service-iot-biz/src/main/java/com/usky/iot/service/listener/RabbitMQListener.java

+ 4 - 0
service-agbox/service-agbox-biz/pom.xml

@@ -62,6 +62,10 @@
             <version>0.0.1</version>
             <scope>compile</scope>
         </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-amqp</artifactId>
+        </dependency>
     </dependencies>
 
     <build>

+ 3 - 2
service-agbox/service-agbox-biz/src/main/java/com/usky/agbox/controller/MybatisGeneratorUtils.java

@@ -44,7 +44,8 @@ public class MybatisGeneratorUtils {
         //2、数据源配置
         //修改数据源
         DataSourceConfig dsc = new DataSourceConfig();
-        dsc.setUrl("jdbc:mysql://172.16.120.165:3306/usky-cloud?useUnicode=true&serverTimezone=GMT&useSSL=false&characterEncoding=utf8");
+        dsc.setUrl("jdbc:mysql://172.16.120.165:3306/usky-fire?useUnicode=true&serverTimezone=GMT&useSSL=false" +
+                "&characterEncoding=utf8");
         dsc.setDriverName("com.mysql.jdbc.Driver");
         dsc.setUsername("usky");
         dsc.setPassword("Yt#75Usky");
@@ -72,7 +73,7 @@ public class MybatisGeneratorUtils {
         // strategy.setTablePrefix("t_"); // 表名前缀
         strategy.setEntityLombokModel(true); //使用lombok
         //修改自己想要生成的表
-        strategy.setInclude("sys_user");  // 逆向工程使用的表   如果要生成多个,这里可以传入String[]
+        strategy.setInclude("patrol_inspection_agbox");  // 逆向工程使用的表   如果要生成多个,这里可以传入String[]
         mpg.setStrategy(strategy);
 
         // 关闭默认 xml 生成,调整生成 至 根目录

+ 53 - 0
service-agbox/service-agbox-biz/src/main/java/com/usky/agbox/controller/web/PatrolInspectionAgboxController.java

@@ -0,0 +1,53 @@
+package com.usky.agbox.controller.web;
+
+
+import com.usky.agbox.domain.PatrolInspectionAgbox;
+import com.usky.agbox.service.PatrolInspectionAgboxService;
+import com.usky.common.core.bean.ApiResult;
+import com.usky.common.core.bean.CommonPage;
+import com.usky.common.log.annotation.Log;
+import com.usky.common.log.enums.BusinessType;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import org.springframework.stereotype.Controller;
+
+/**
+ * <p>
+ *  前端控制器
+ * </p>
+ *
+ * @author han
+ * @since 2024-05-23
+ */
+@RestController
+@RequestMapping("/patrolInspectionAgbox")
+public class PatrolInspectionAgboxController {
+    @Autowired
+    private PatrolInspectionAgboxService patrolInspectionAgboxService;
+
+    /**
+     * 修改
+     * @param patrolInspectionAgbox
+     * @return
+     */
+    @PutMapping("/update")
+    public ApiResult<Void> update(@RequestBody PatrolInspectionAgbox patrolInspectionAgbox){
+        patrolInspectionAgboxService.update(patrolInspectionAgbox);
+        return ApiResult.success();
+    }
+
+    /**
+     * 分页
+     * @param current
+     * @param size
+     * @return
+     */
+    @GetMapping("/page")
+    public ApiResult<CommonPage<PatrolInspectionAgbox>> page(@RequestParam(value = "current", required = false, defaultValue = "1") Integer current,
+                                                             @RequestParam(value = "size", required = false, defaultValue = "10") Integer size)
+    {
+        return ApiResult.success(patrolInspectionAgboxService.page(current,size));
+    }
+}
+

+ 61 - 0
service-agbox/service-agbox-biz/src/main/java/com/usky/agbox/domain/PatrolInspectionAgbox.java

@@ -0,0 +1,61 @@
+package com.usky.agbox.domain;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import java.time.LocalDateTime;
+import java.io.Serializable;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+/**
+ * <p>
+ * 
+ * </p>
+ *
+ * @author han
+ * @since 2024-05-23
+ */
+@Data
+@EqualsAndHashCode(callSuper = false)
+public class PatrolInspectionAgbox implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * 主键ID
+     */
+    @TableId(value = "id", type = IdType.AUTO)
+    private Integer id;
+
+    /**
+     * agboxKey
+     */
+    private String agboxKey;
+
+    /**
+     * agbox转发路径
+     */
+    private String agboxUrl;
+
+    /**
+     * 更新人
+     */
+    private String updateBy;
+
+    /**
+     * 更新时间
+     */
+    private LocalDateTime updateTime;
+
+    /**
+     * 组织机构ID
+     */
+    private Integer deptId;
+
+    /**
+     * 租户ID
+     */
+    private Integer tenantId;
+
+
+}

+ 16 - 0
service-agbox/service-agbox-biz/src/main/java/com/usky/agbox/mapper/PatrolInspectionAgboxMapper.java

@@ -0,0 +1,16 @@
+package com.usky.agbox.mapper;
+
+import com.usky.agbox.domain.PatrolInspectionAgbox;
+import com.usky.common.mybatis.core.CrudMapper;
+
+/**
+ * <p>
+ *  Mapper 接口
+ * </p>
+ *
+ * @author han
+ * @since 2024-05-23
+ */
+public interface PatrolInspectionAgboxMapper extends CrudMapper<PatrolInspectionAgbox> {
+
+}

+ 19 - 0
service-agbox/service-agbox-biz/src/main/java/com/usky/agbox/service/PatrolInspectionAgboxService.java

@@ -0,0 +1,19 @@
+package com.usky.agbox.service;
+
+import com.usky.agbox.domain.PatrolInspectionAgbox;
+import com.usky.common.core.bean.CommonPage;
+import com.usky.common.mybatis.core.CrudService;
+
+/**
+ * <p>
+ *  服务类
+ * </p>
+ *
+ * @author han
+ * @since 2024-05-23
+ */
+public interface PatrolInspectionAgboxService extends CrudService<PatrolInspectionAgbox> {
+    void update(PatrolInspectionAgbox patrolInspectionAgbox);
+
+    CommonPage<PatrolInspectionAgbox> page(Integer pageNum,Integer pageSize);
+}

+ 61 - 0
service-agbox/service-agbox-biz/src/main/java/com/usky/agbox/service/config/rabbitmq/RabbitMQConfig.java

@@ -0,0 +1,61 @@
+package com.usky.agbox.service.config.rabbitmq;
+
+import com.rabbitmq.client.AMQP;
+import org.springframework.amqp.core.*;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+public class RabbitMQConfig {
+    //队列
+    public String patrolEventQueue = "Patrol_QEvent";
+    //交换机
+    public String patrolEventExchange = "Patrol_EEvent";
+    //路由
+    public String patrolEventRoute = "Patrol_REvent";
+
+    //注册一个队列
+    @Bean
+    public Queue patrolQueue(){
+        return QueueBuilder.durable(patrolEventQueue).maxLength(100).build();    //启动的时候,它会根据这个名称先去查找有没有这个队列,如果有什么都不做,如果没有就创建一个新的
+    }
+
+    //注册交换机
+    @Bean
+    public DirectExchange patrolExchange(){
+        return ExchangeBuilder.directExchange(patrolEventExchange).build();
+    }
+
+    //绑定交换机与队列关系
+    @Bean
+    public Binding bindingPatrolExchangeMessage(){
+        return BindingBuilder.bind(patrolQueue()).to(patrolExchange()).with(patrolEventRoute);
+    }
+
+
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+ 42 - 0
service-agbox/service-agbox-biz/src/main/java/com/usky/agbox/service/impl/PatrolInspectionAgboxServiceImpl.java

@@ -0,0 +1,42 @@
+package com.usky.agbox.service.impl;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.usky.agbox.domain.PatrolInspectionAgbox;
+import com.usky.agbox.mapper.PatrolInspectionAgboxMapper;
+import com.usky.agbox.service.PatrolInspectionAgboxService;
+import com.usky.common.core.bean.CommonPage;
+import com.usky.common.mybatis.core.AbstractCrudService;
+import com.usky.common.security.utils.SecurityUtils;
+import org.springframework.stereotype.Service;
+
+import java.time.LocalDateTime;
+
+/**
+ * <p>
+ *  服务实现类
+ * </p>
+ *
+ * @author han
+ * @since 2024-05-23
+ */
+@Service
+public class PatrolInspectionAgboxServiceImpl extends AbstractCrudService<PatrolInspectionAgboxMapper, PatrolInspectionAgbox> implements PatrolInspectionAgboxService {
+    @Override
+    public void update(PatrolInspectionAgbox patrolInspectionAgbox) {
+        patrolInspectionAgbox.setUpdateTime(LocalDateTime.now());
+        patrolInspectionAgbox.setUpdateBy(SecurityUtils.getUsername());
+        this.updateById(patrolInspectionAgbox);
+    }
+
+    @Override
+    public CommonPage<PatrolInspectionAgbox> page(Integer pageNum,Integer pageSize) {
+        IPage<PatrolInspectionAgbox> page = new Page<>(pageNum, pageSize);
+        LambdaQueryWrapper<PatrolInspectionAgbox> lambdaQuery = Wrappers.lambdaQuery();
+        page = this.page(page,lambdaQuery);
+        return new CommonPage<>(page.getRecords(),page.getTotal(),page.getCurrent(),page.getSize());
+    }
+}

+ 34 - 10
service-agbox/service-agbox-biz/src/main/java/com/usky/agbox/service/job/patrolAgbox.java

@@ -1,10 +1,16 @@
 package com.usky.agbox.service.job;
 
 import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.usky.agbox.domain.PatrolInspectionAgbox;
+import com.usky.agbox.service.PatrolInspectionAgboxService;
 import com.usky.agbox.service.util.HttpClientUtils;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Component;
 import java.util.HashMap;
+import java.util.List;
 
 @Component
 public class patrolAgbox {
@@ -14,15 +20,29 @@ public class patrolAgbox {
     @Value("${agBox.url}")
     private String URL;
 
+    @Autowired
+    private PatrolInspectionAgboxService patrolInspectionAgboxService;
+
+    /**
+     * 获取推送配置信息
+     * @return
+     */
+    public List<PatrolInspectionAgbox> getAgBox() {
+        LambdaQueryWrapper<PatrolInspectionAgbox> lambdaQuery = Wrappers.lambdaQuery();
+        List<PatrolInspectionAgbox> list = patrolInspectionAgboxService.list(lambdaQuery);
+        return list;
+    }
+
     /**
      * 获取事件编码信息
      * @return
      */
     public JSONObject getEventCode() {
+        List<PatrolInspectionAgbox> list = this.getAgBox();
         HashMap map = new HashMap();
-        map.put("key", KEY);
+        map.put("key", list.get(0).getAgboxKey());
         map.put("json", "{\"jsonrpc\":\"2.0\",\"method\":\"getPatrolEventCode\"}");
-        String resultString = HttpClientUtils.doPost(URL,map);
+        String resultString = HttpClientUtils.doPost(list.get(0).getAgboxUrl(),map);
         JSONObject resultVO = JSONObject.parseObject(resultString);
         return resultVO;
     }
@@ -32,10 +52,11 @@ public class patrolAgbox {
      * @return
      */
     public JSONObject getDeviceList() {
+        List<PatrolInspectionAgbox> list = this.getAgBox();
         HashMap map = new HashMap();
-        map.put("key", KEY);
+        map.put("key", list.get(0).getAgboxKey());
         map.put("json", "{\"jsonrpc\":\"2.0\",\"method\":\"getDeviceList\"}");
-        String resultString = HttpClientUtils.doPost(URL,map);
+        String resultString = HttpClientUtils.doPost(list.get(0).getAgboxUrl(),map);
         JSONObject resultVO = JSONObject.parseObject(resultString);
         return resultVO;
     }
@@ -45,13 +66,14 @@ public class patrolAgbox {
      * @return
      */
     public JSONObject addEvent(String requestBody) {
+        List<PatrolInspectionAgbox> list = this.getAgBox();
         JSONObject eventVO = JSONObject.parseObject(requestBody);
         HashMap map = new HashMap();
-        map.put("key", KEY);
+        map.put("key", list.get(0).getAgboxKey());
         map.put("json", "{\"jsonrpc\":\"2.0\",\"method\":\"addEvent\",\"params\":{\"deviceId\":\""+eventVO.get("deviceId").toString()+"\"," +
                 "\"triggerTime\":\""+eventVO.get("triggerTime").toString()+"\",\"eventCode\":"+eventVO.get("eventCode")+",\"name" +
                 "\":\""+eventVO.get("name").toString()+"\",\"certifiedNo\":\""+eventVO.get("certifiedNo").toString()+"\"}}");
-        String resultString = HttpClientUtils.doPost(URL,map);
+        String resultString = HttpClientUtils.doPost(list.get(0).getAgboxUrl(),map);
         JSONObject resultVO = JSONObject.parseObject(resultString);
         return resultVO;
     }
@@ -61,12 +83,13 @@ public class patrolAgbox {
      * @return
      */
     public JSONObject updateHeart(String requestBody) {
+        List<PatrolInspectionAgbox> list = this.getAgBox();
         JSONObject eventVO = JSONObject.parseObject(requestBody);
         HashMap map = new HashMap();
-        map.put("key", KEY);
+        map.put("key", list.get(0).getAgboxKey());
         map.put("json",
                 "{\"jsonrpc\":\"2.0\",\"method\":\"updateHeart\",\"params\":{\"deviceId\":\""+eventVO.get("deviceId").toString()+"\"}}");
-        String resultString = HttpClientUtils.doPost(URL,map);
+        String resultString = HttpClientUtils.doPost(list.get(0).getAgboxUrl(),map);
         JSONObject resultVO = JSONObject.parseObject(resultString);
         return resultVO;
     }
@@ -76,11 +99,12 @@ public class patrolAgbox {
      * @return
      */
     public JSONObject getEvent(String requestBody) {
+        List<PatrolInspectionAgbox> list = this.getAgBox();
         JSONObject eventVO = JSONObject.parseObject(requestBody);
         HashMap map = new HashMap();
-        map.put("key", KEY);
+        map.put("key", list.get(0).getAgboxKey());
         map.put("json", "{\"jsonrpc\":\"2.0\",\"method\":\"getEvent\",\"params\":{\"eventId\":\""+eventVO.get("eventId").toString()+"\"}}");
-        String resultString = HttpClientUtils.doPost(URL,map);
+        String resultString = HttpClientUtils.doPost(list.get(0).getAgboxUrl(),map);
         JSONObject resultVO = JSONObject.parseObject(resultString);
         return resultVO;
     }

+ 65 - 0
service-agbox/service-agbox-biz/src/main/java/com/usky/agbox/service/listener/RabbitMQListener.java

@@ -0,0 +1,65 @@
+package com.usky.agbox.service.listener;
+
+import com.alibaba.fastjson.JSONObject;
+import com.usky.agbox.service.job.patrolAgbox;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.amqp.core.ExchangeTypes;
+import org.springframework.amqp.core.Message;
+import org.springframework.amqp.rabbit.annotation.*;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+@Slf4j
+@Component
+public class RabbitMQListener {
+    @Autowired
+    private patrolAgbox PatrolAgbox;
+    @RabbitHandler
+    @RabbitListener(bindings = @QueueBinding(
+            value = @Queue(),
+            exchange = @Exchange(value = "Patrol_FEvent",type = ExchangeTypes.FANOUT)
+    ))
+    public void getData(Message message){
+        try {
+            String str = new String(message.getBody(),"utf-8");
+            JSONObject eventVO1 = JSONObject.parseObject(str);
+            JSONObject eventVO = new JSONObject();
+            if (eventVO1.get("eventType").equals(31)){
+                eventVO1.put("eventCode",1);
+                PatrolAgbox.addEvent(eventVO1.toJSONString());
+            }else if (eventVO1.get("eventType").equals(32)){
+                eventVO1.put("eventCode",2);
+                PatrolAgbox.addEvent(eventVO1.toJSONString());
+            }else {
+                eventVO.put("eventCode",16);
+                String timeWithT = eventVO1.get("createTime").toString();
+                eventVO.put("deviceId",eventVO1.get("deviceId"));
+                eventVO.put("triggerTime",timeWithT.replace("T", " "));
+                eventVO.put("name",eventVO1.get("createBy"));
+                eventVO.put("certifiedNo","");
+                PatrolAgbox.addEvent(eventVO.toJSONString());
+            }
+            System.out.println("FEventReceiver消费者收到消息: " + str);
+        } catch (Exception e){
+            e.printStackTrace();
+        }
+    }
+
+    @RabbitHandler
+    @RabbitListener(bindings = @QueueBinding(
+            value = @Queue(),
+            exchange = @Exchange(value = "Patrol_FInfo",type = ExchangeTypes.FANOUT)
+    ))
+    public void getDataInfo(Message message){
+        try {
+            String str = new String(message.getBody(),"utf-8");
+            JSONObject eventVO1 = JSONObject.parseObject(str);
+            JSONObject eventVO = new JSONObject();
+            eventVO.put("deviceId",eventVO1.get("deviceId"));
+            PatrolAgbox.updateHeart(eventVO.toJSONString());
+            System.out.println("FInfoReceiver消费者收到消息: " + str);
+        } catch (Exception e){
+            e.printStackTrace();
+        }
+    }
+}

+ 2 - 2
service-agbox/service-agbox-biz/src/main/resources/bootstrap.yml

@@ -14,10 +14,10 @@ spring:
     nacos:
       discovery:
         # 服务注册地址
-        server-addr: 172.16.120.165:8848
+        server-addr: usky-cloud-nacos:8848
       config:
         # 配置中心地址
-        server-addr: 172.16.120.165:8848
+        server-addr: usky-cloud-nacos:8848
         # 配置文件格式
         file-extension: yml
         # 共享配置

+ 16 - 0
service-agbox/service-agbox-biz/src/main/resources/mapper/agbox/PatrolInspectionAgboxMapper.xml

@@ -0,0 +1,16 @@
+<?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.usky.agbox.mapper.PatrolInspectionAgboxMapper">
+
+    <!-- 通用查询映射结果 -->
+    <resultMap id="BaseResultMap" type="com.usky.agbox.domain.PatrolInspectionAgbox">
+        <id column="id" property="id" />
+        <result column="agbox_key" property="agboxKey" />
+        <result column="agbox_url" property="agboxUrl" />
+        <result column="update_by" property="updateBy" />
+        <result column="update_time" property="updateTime" />
+        <result column="dept_id" property="deptId" />
+        <result column="tenant_id" property="tenantId" />
+    </resultMap>
+
+</mapper>

+ 4 - 1
service-fire/service-fire-biz/pom.xml

@@ -111,7 +111,10 @@
             <artifactId>commons-collections4</artifactId>
             <version>4.4</version>
         </dependency>
-
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-amqp</artifactId>
+        </dependency>
 
     </dependencies>
 

+ 2 - 1
service-fire/service-fire-biz/src/main/java/com/usky/fire/RuoYiSystemApplication.java

@@ -2,6 +2,7 @@ package com.usky.fire;
 
 
 import org.mybatis.spring.annotation.MapperScan;
+import org.springframework.amqp.rabbit.annotation.EnableRabbit;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.cloud.openfeign.EnableFeignClients;
@@ -13,7 +14,7 @@ import org.springframework.context.annotation.ComponentScan;
  * @author ruoyi
  */
 
-
+@EnableRabbit
 @EnableFeignClients(basePackages = "com.usky")
 @MapperScan(value = "com.usky.fire.mapper")
 @ComponentScan("com.usky")

+ 5 - 0
service-fire/service-fire-biz/src/main/java/com/usky/fire/controller/web/PatrolInspectionEventController.java

@@ -46,6 +46,11 @@ public class PatrolInspectionEventController {
         return ApiResult.success();
     }
 
+    /**
+     * 修改
+     * @param patrolInspectionEvent
+     * @return
+     */
     @PutMapping("edit")
     public ApiResult<Void> edit(@RequestBody PatrolInspectionEvent patrolInspectionEvent){
         patrolInspectionEventService.edit(patrolInspectionEvent);

+ 20 - 0
service-fire/service-fire-biz/src/main/java/com/usky/fire/domain/PatrolInspectionEvent.java

@@ -58,6 +58,11 @@ public class PatrolInspectionEvent implements Serializable {
      */
     private Integer eventCategory;
 
+    /**
+     * 事件图片
+     */
+    private String eventImage;
+
     /**
      * 处置状态
      */
@@ -78,6 +83,21 @@ public class PatrolInspectionEvent implements Serializable {
      */
     private LocalDateTime handleTime;
 
+    /**
+     * 处置图片
+     */
+    private String handleImage;
+
+    /**
+     * 处置内容
+     */
+    private String handleContent;
+
+    /**
+     * 备注
+     */
+    private String remark;
+
     /**
      * 租户号
      */

+ 70 - 0
service-fire/service-fire-biz/src/main/java/com/usky/fire/service/config/rabbitmq/RabbitMQConfig.java

@@ -0,0 +1,70 @@
+package com.usky.fire.service.config.rabbitmq;
+
+import com.rabbitmq.client.AMQP;
+import org.springframework.amqp.core.*;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+public class RabbitMQConfig {
+    //点对点
+    //队列
+    public String patrolEventQueue = "Patrol_QEvent";
+    //交换机
+    public String patrolEventExchange = "Patrol_EEvent";
+    //路由
+    public String patrolEventRoute = "Patrol_REvent";
+
+    //注册一个队列
+    @Bean
+    public Queue patrolQueue(){
+        return QueueBuilder.durable(patrolEventQueue).maxLength(100).build();    //启动的时候,它会根据这个名称先去查找有没有这个队列,如果有什么都不做,如果没有就创建一个新的
+    }
+
+    //注册交换机
+    @Bean
+    public DirectExchange patrolExchange(){
+        return ExchangeBuilder.directExchange(patrolEventExchange).build();
+    }
+
+    //绑定交换机与队列关系
+    @Bean
+    public Binding bindingPatrolExchangeMessage(){
+        return BindingBuilder.bind(patrolQueue()).to(patrolExchange()).with(patrolEventRoute);
+    }
+
+    //广播
+    public String patrolFEventExchange = "Patrol_FEvent";
+
+    @Bean
+    public FanoutExchange patrolFExchange(){
+        return new FanoutExchange(patrolFEventExchange,true,false);
+    }
+
+
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+ 17 - 6
service-fire/service-fire-biz/src/main/java/com/usky/fire/service/impl/PatrolInspectionAttendanceServiceImpl.java

@@ -18,11 +18,14 @@ import com.usky.common.mybatis.core.AbstractCrudService;
 import com.usky.fire.service.PatrolInspectionPersonnelService;
 import com.usky.fire.service.PatrolInspectionTypeService;
 
+import com.usky.fire.service.config.rabbitmq.RabbitMQConfig;
+import org.springframework.amqp.rabbit.core.RabbitTemplate;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 import com.usky.system.RemoteDeptService;
 
+import javax.annotation.Resource;
 import java.time.LocalDateTime;
 import java.time.format.DateTimeFormatter;
 import java.util.ArrayList;
@@ -59,6 +62,12 @@ public class PatrolInspectionAttendanceServiceImpl extends AbstractCrudService<P
     @Value("${agBox.push}")
     private Integer pushFlag;
 
+    @Resource
+    private RabbitTemplate rabbitTemplate;
+
+    @Autowired
+    private RabbitMQConfig rabbitMQConfig;
+
     @Override
     public IPage<Map<String, Object>> pageList(Integer pageNum, Integer pageSize, String operateCode, String operator, LocalDateTime startTime, LocalDateTime endTime) {
         IPage<PatrolInspectionAttendance> page = new Page<>(pageNum, pageSize);
@@ -144,16 +153,18 @@ public class PatrolInspectionAttendanceServiceImpl extends AbstractCrudService<P
         jsonObj.put("triggerTime", formattedTime);
         Integer eventCode = 17;
         if(patrolInspectionAttendance.getSignInType().equals(0)){
-            eventCode=1;
+            eventCode=31;
         }else {
-            eventCode=2;
+            eventCode=32;
         }
-        jsonObj.put("eventCode", eventCode);
+        jsonObj.put("eventType", eventCode);
         jsonObj.put("name", SecurityUtils.getUsername());
         jsonObj.put("certifiedNo", patrolInspectionAttendance.getIdentificationNumber());
-        if (pushFlag.equals(1)){
-            JSONObject a = remotePatrolAgboxService.addEvent(jsonObj.toJSONString());
-        }
+
+        rabbitTemplate.convertAndSend(rabbitMQConfig.patrolFEventExchange,"",jsonObj.toJSONString());
+//        if (pushFlag.equals(1)){
+//            JSONObject a = remotePatrolAgboxService.addEvent(jsonObj.toJSONString());
+//        }
     }
 
     /**

+ 84 - 1
service-fire/service-fire-biz/src/main/java/com/usky/fire/service/impl/PatrolInspectionEventServiceImpl.java

@@ -1,19 +1,35 @@
 package com.usky.fire.service.impl;
 
+import com.alibaba.fastjson.JSONObject;
+import com.alibaba.nacos.shaded.com.google.gson.JsonObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.toolkit.StringUtils;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.usky.common.core.bean.CommonPage;
+import com.usky.common.core.exception.BusinessException;
 import com.usky.common.security.utils.SecurityUtils;
 import com.usky.fire.domain.PatrolInspectionEvent;
+import com.usky.fire.domain.PatrolInspectionPersonnel;
+import com.usky.fire.domain.PatrolInspectionPlanSchedule;
 import com.usky.fire.mapper.PatrolInspectionEventMapper;
 import com.usky.fire.service.PatrolInspectionEventService;
 import com.usky.common.mybatis.core.AbstractCrudService;
+import com.usky.fire.service.PatrolInspectionPersonnelService;
+import com.usky.fire.service.PatrolInspectionPlanScheduleService;
+import com.usky.fire.service.config.rabbitmq.RabbitMQConfig;
 import com.usky.fire.service.vo.PatrolInspectionPlanRequestVO;
+import org.apache.catalina.security.SecurityUtil;
+import org.springframework.amqp.rabbit.core.RabbitTemplate;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.time.LocalDateTime;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
 /**
  * <p>
  * 事件管理表 服务实现类
@@ -24,6 +40,14 @@ import org.springframework.stereotype.Service;
  */
 @Service
 public class PatrolInspectionEventServiceImpl extends AbstractCrudService<PatrolInspectionEventMapper, PatrolInspectionEvent> implements PatrolInspectionEventService {
+    @Autowired
+    private PatrolInspectionPlanScheduleService patrolInspectionPlanScheduleService;
+    @Autowired
+    private PatrolInspectionPersonnelService patrolInspectionPersonnelService;
+    @Autowired
+    private RabbitTemplate rabbitTemplate;
+    @Autowired
+    private RabbitMQConfig rabbitMQConfig;
 
     @Override
     public CommonPage<PatrolInspectionEvent> patrolInspectionEventList(PatrolInspectionPlanRequestVO requestVO){
@@ -31,7 +55,11 @@ public class PatrolInspectionEventServiceImpl extends AbstractCrudService<Patrol
         Integer size = requestVO.getPageSize();
         IPage<PatrolInspectionEvent> page = new Page<>(current,size);
         LambdaQueryWrapper<PatrolInspectionEvent> queryWrapper = Wrappers.lambdaQuery();
-        queryWrapper.eq(StringUtils.isNotBlank(requestVO.getDeviceId()),PatrolInspectionEvent::getDeviceId,requestVO.getDeviceId())
+        queryWrapper.eq(requestVO.getId() != null,PatrolInspectionEvent::getId,requestVO.getId())
+                .like(StringUtils.isNotBlank(requestVO.getPersonnelName()),PatrolInspectionEvent::getPersonnelName,requestVO.getPersonnelName())
+                .like(StringUtils.isNotBlank(requestVO.getEventName()),PatrolInspectionEvent::getEventName,requestVO.getEventName())
+                .eq(requestVO.getHandleStatus() != null,PatrolInspectionEvent::getHandleStatus,requestVO.getHandleStatus())
+                .eq(StringUtils.isNotBlank(requestVO.getDeviceId()),PatrolInspectionEvent::getDeviceId,requestVO.getDeviceId())
                 .eq(requestVO.getEventLevel() != null,PatrolInspectionEvent::getEventLevel,requestVO.getEventLevel())
                 .eq(PatrolInspectionEvent::getTenantId, SecurityUtils.getTenantId())
                 .orderByDesc(PatrolInspectionEvent::getId);
@@ -43,10 +71,65 @@ public class PatrolInspectionEventServiceImpl extends AbstractCrudService<Patrol
     @Override
     public void add(PatrolInspectionEvent patrolInspectionEvent){
 
+        Map<Object,Object> map = new HashMap<>();
+
+        if(null != patrolInspectionEvent.getPlanId()){
+            Integer planId = patrolInspectionEvent.getPlanId();
+            LambdaQueryWrapper<PatrolInspectionPlanSchedule> queryWrapper = Wrappers.lambdaQuery();
+            queryWrapper.eq(PatrolInspectionPlanSchedule::getPlanId,planId);
+            List<PatrolInspectionPlanSchedule> list = patrolInspectionPlanScheduleService.list(queryWrapper);
+            if(list.size() > 0){
+                Integer personnelId = list.get(0).getPersonnelId();
+                LambdaQueryWrapper<PatrolInspectionPersonnel> queryWrapper1 = Wrappers.lambdaQuery();
+                queryWrapper1.eq(PatrolInspectionPersonnel::getId,personnelId);
+                PatrolInspectionPersonnel one = patrolInspectionPersonnelService.getOne(queryWrapper1);
+
+                patrolInspectionEvent.setPersonnelId(personnelId);
+                patrolInspectionEvent.setPersonnelName(one.getFullName());
+                map.put("idCard",one.getIdCard());
+            }
+        }else{
+            Long userId = SecurityUtils.getUserId();
+            patrolInspectionEvent.setPersonnelId(userId.intValue());
+            patrolInspectionEvent.setPersonnelName(SecurityUtils.getUsername());
+        }
+
+        patrolInspectionEvent.setHandleStatus(0);
+        patrolInspectionEvent.setTenantId(SecurityUtils.getTenantId());
+        patrolInspectionEvent.setCreateBy(SecurityUtils.getUsername());
+        patrolInspectionEvent.setCreateTime(LocalDateTime.now());
+
+        map.put("deviceId",patrolInspectionEvent.getDeviceId());
+        map.put("personnelId",patrolInspectionEvent.getPersonnelId());
+        map.put("personnelName",patrolInspectionEvent.getPersonnelName());
+        map.put("eventName",patrolInspectionEvent.getEventName());
+        map.put("eventType",patrolInspectionEvent.getEventType());
+        map.put("eventCategory",patrolInspectionEvent.getEventCategory());
+        map.put("eventImage",patrolInspectionEvent.getEventImage());
+        map.put("handleStatus",patrolInspectionEvent.getHandleStatus());
+        map.put("handleName",patrolInspectionEvent.getHandleName());
+        map.put("handleTime",patrolInspectionEvent.getHandleTime());
+        map.put("remark",patrolInspectionEvent.getRemark());
+        map.put("createBy",patrolInspectionEvent.getCreateBy());
+        map.put("createTime",patrolInspectionEvent.getCreateTime());
+
+//        rabbitTemplate.convertAndSend(rabbitMQConfig.patrolEventExchange,rabbitMQConfig.patrolEventRoute,map);
+        rabbitTemplate.convertAndSend(rabbitMQConfig.patrolFEventExchange,"", JSONObject.toJSONString(map));
+
+        this.save(patrolInspectionEvent);
     }
 
     @Override
     public void edit(PatrolInspectionEvent patrolInspectionEvent){
+        PatrolInspectionEvent one = this.getById(patrolInspectionEvent.getId());
+        if(one == null){
+            throw new BusinessException("没有对应记录数据");
+        }
+
+        patrolInspectionEvent.setHandleStatus(1);
+        patrolInspectionEvent.setHandleName(SecurityUtils.getUsername());
+        patrolInspectionEvent.setHandleTime(LocalDateTime.now());
+        this.updateById(patrolInspectionEvent);
 
     }
 

+ 35 - 0
service-fire/service-fire-biz/src/main/java/com/usky/fire/service/listener/RabbitMQListener.java

@@ -0,0 +1,35 @@
+package com.usky.fire.service.listener;
+
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.amqp.core.ExchangeTypes;
+import org.springframework.amqp.core.Message;
+import org.springframework.amqp.rabbit.annotation.*;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.util.Map;
+
+@Slf4j
+@Component
+public class RabbitMQListener {
+
+    @RabbitHandler
+    @RabbitListener(queues = "Patrol_QEvent")  //监听名称为Patrol_QEvent队列消息
+    public void process(Map testMessage){
+        System.out.println("DirectReceiver消费者收到消息: " + testMessage.toString());
+    }
+
+    @RabbitHandler
+    @RabbitListener(bindings = @QueueBinding(
+            value = @Queue(),
+            exchange = @Exchange(value = "Patrol_FEvent",type = ExchangeTypes.FANOUT)
+    ))
+    public void getData(Message message){
+        try {
+            String str = new String(message.getBody(),"utf-8");
+            System.out.println("FanoutReceiver消费者收到消息: " + str);
+        } catch (Exception e){
+            e.printStackTrace();
+        }
+    }
+}

+ 17 - 0
service-fire/service-fire-biz/src/main/java/com/usky/fire/service/vo/PatrolInspectionPlanRequestVO.java

@@ -4,6 +4,23 @@ import lombok.Data;
 
 @Data
 public class PatrolInspectionPlanRequestVO {
+    private Integer id;
+
+    /**
+     * 巡检人名称
+     */
+    private String personnelName;
+
+    /**
+     * 事件名称
+     */
+    private String eventName;
+
+    /**
+     * 处置状态
+     */
+    private Integer handleStatus;
+
     /**
      * 设备Id
      */

+ 4 - 0
service-fire/service-fire-biz/src/main/resources/mapper/fire/PatrolInspectionEventMapper.xml

@@ -11,10 +11,14 @@
         <result column="event_type" property="eventType" />
         <result column="event_level" property="eventLevel" />
         <result column="event_category" property="eventCategory" />
+        <result column="event_image" property="eventImage" />
         <result column="handle_status" property="handleStatus" />
         <result column="device_id" property="deviceId" />
         <result column="handle_name" property="handleName" />
         <result column="handle_time" property="handleTime" />
+        <result column="handle_image" property="handleImage" />
+        <result column="handle_content" property="handleContent" />
+        <result column="remark" property="remark" />
         <result column="tenant_id" property="tenantId" />
         <result column="dept_id" property="deptId" />
         <result column="create_by" property="createBy" />

+ 4 - 0
service-iot/service-iot-biz/pom.xml

@@ -71,6 +71,10 @@
             <artifactId>weixin-java-mp</artifactId>
             <version>4.3.0</version>
         </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-amqp</artifactId>
+        </dependency>
 
     </dependencies>
 

+ 2 - 0
service-iot/service-iot-biz/src/main/java/com/usky/iot/RuoYiSystemApplication.java

@@ -11,6 +11,7 @@ import me.chanjar.weixin.mp.config.impl.WxMpMapConfigImpl;
 import org.mybatis.spring.annotation.MapperScan;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.amqp.rabbit.annotation.EnableRabbit;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.cloud.openfeign.EnableFeignClients;
@@ -33,6 +34,7 @@ import java.net.UnknownHostException;
 @MapperScan(value = "com.usky.iot.mapper")
 @ComponentScan("com.usky")
 @SpringBootApplication
+@EnableRabbit
 public class RuoYiSystemApplication
 {
     private static final Logger LOGGER = LoggerFactory.getLogger(RuoYiSystemApplication.class);

+ 44 - 0
service-iot/service-iot-biz/src/main/java/com/usky/iot/service/config/rabbitmq/RabbitMQConfig.java

@@ -0,0 +1,44 @@
+package com.usky.iot.service.config.rabbitmq;
+
+import org.springframework.amqp.core.*;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+public class RabbitMQConfig {
+
+    //心跳广播
+    public String patrolFInfoExchange = "Patrol_FInfo";
+
+    @Bean
+    public FanoutExchange infoFExchange(){
+        return new FanoutExchange(patrolFInfoExchange,true,false);
+    }
+
+
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+ 23 - 5
service-iot/service-iot-biz/src/main/java/com/usky/iot/service/impl/BaseAppInfoServiceImpl.java

@@ -7,6 +7,8 @@ import com.usky.iot.domain.BaseAppInfo;
 import com.usky.iot.mapper.BaseAppInfoMapper;
 import com.usky.iot.service.BaseAppInfoService;
 import com.usky.common.mybatis.core.AbstractCrudService;
+import com.usky.iot.service.config.rabbitmq.RabbitMQConfig;
+import org.springframework.amqp.rabbit.core.RabbitTemplate;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
@@ -14,8 +16,11 @@ import org.springframework.web.context.request.RequestAttributes;
 import org.springframework.web.context.request.RequestContextHolder;
 import org.springframework.web.context.request.ServletRequestAttributes;
 
+import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
 import java.time.LocalDateTime;
+import java.util.HashMap;
+import java.util.Map;
 
 /**
  * <p>
@@ -34,6 +39,12 @@ public class BaseAppInfoServiceImpl extends AbstractCrudService<BaseAppInfoMappe
     @Value("${agBox.push}")
     private Integer pushFlag;
 
+    @Resource
+    private RabbitTemplate rabbitTemplate;
+
+    @Autowired
+    private RabbitMQConfig rabbitMQConfig;
+
     public String getIpAddress(HttpServletRequest request) {
         String ip = request.getHeader("X-Forwarded-For");
         if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
@@ -59,8 +70,8 @@ public class BaseAppInfoServiceImpl extends AbstractCrudService<BaseAppInfoMappe
 
     @Override
     public void add(BaseAppInfo baseAppInfo){
-        JSONObject jsonObj = new JSONObject();
-        jsonObj.put("deviceId", baseAppInfo.getDeviceId());
+//        JSONObject jsonObj = new JSONObject();
+//        jsonObj.put("deviceId", baseAppInfo.getDeviceId());
 //        baseAppInfo.setNetworkService(a.toJSONString());
         HttpServletRequest request = getHttpServletRequest();
         String accessIp = getIpAddress(request);
@@ -68,9 +79,16 @@ public class BaseAppInfoServiceImpl extends AbstractCrudService<BaseAppInfoMappe
         baseAppInfo.setCreateBy(SecurityUtils.getUsername());
         baseAppInfo.setCreateTime(LocalDateTime.now());
         baseAppInfo.setTenantId(SecurityUtils.getTenantId());
+
+        Map<String,Object> map = new HashMap<>();
+        map.put("deviceId",baseAppInfo.getDeviceId());
+        map.put("userName",baseAppInfo.getUserName());
+        map.put("createTime",baseAppInfo.getCreateTime());
+        rabbitTemplate.convertAndSend(rabbitMQConfig.patrolFInfoExchange,"",JSONObject.toJSONString(map));
+
         this.save(baseAppInfo);
-        if (pushFlag.equals(1)){
-            JSONObject a = remotePatrolAgboxService.updateHeart(jsonObj.toJSONString());
-        }
+//        if (pushFlag.equals(1)){
+//            JSONObject a = remotePatrolAgboxService.updateHeart(jsonObj.toJSONString());
+//        }
     }
 }

+ 29 - 0
service-iot/service-iot-biz/src/main/java/com/usky/iot/service/listener/RabbitMQListener.java

@@ -0,0 +1,29 @@
+package com.usky.iot.service.listener;
+
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.amqp.core.ExchangeTypes;
+import org.springframework.amqp.core.Message;
+import org.springframework.amqp.rabbit.annotation.*;
+import org.springframework.stereotype.Component;
+
+import java.util.Map;
+
+@Slf4j
+@Component
+public class RabbitMQListener {
+
+
+    @RabbitHandler
+    @RabbitListener(bindings = @QueueBinding(
+            value = @Queue(),
+            exchange = @Exchange(value = "Patrol_FInfo",type = ExchangeTypes.FANOUT)
+    ))
+    public void getData(Message message){
+        try {
+            String str = new String(message.getBody(),"utf-8");
+            System.out.println("FanoutReceiver消费者收到心跳消息: " + str);
+        } catch (Exception e){
+            e.printStackTrace();
+        }
+    }
+}