فهرست منبع

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

James 10 ماه پیش
والد
کامیت
17dfdeb801

+ 21 - 13
service-fire/service-fire-biz/src/main/java/com/usky/fire/service/impl/PatrolInspectionEventServiceImpl.java

@@ -20,6 +20,7 @@ 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;
@@ -72,20 +73,27 @@ public class PatrolInspectionEventServiceImpl extends AbstractCrudService<Patrol
 
         Map<Object,Object> map = new HashMap<>();
 
-        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());
+        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());

+ 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);
+    }
+
+
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+ 18 - 0
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)) {
@@ -68,6 +79,13 @@ 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());

+ 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();
+        }
+    }
+}