mitao
2025-02-21 31573d6180d15ef65ed0df9c2732495f40b12663
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package com.panzhihua.service_property.message;
 
import cn.hutool.core.date.DateUtil;
import com.panzhihua.service_property.dao.ComPropertyAlarmDao;
import com.panzhihua.service_property.entity.ComPropertyAlarm;
import com.panzhihua.service_property.entity.ComPropertyEquipment;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;
 
import javax.annotation.Resource;
 
/**
 * @author zzj
 */
@Component
@Slf4j
public class AlarmMessage {
 
    private final static String DELAY_QUEUE="delayed.queue";
    @Resource
    private StringRedisTemplate stringRedisTemplate;
    @Resource
    private ComPropertyAlarmDao comPropertyAlarmDao;
 
    @RabbitListener(queues=DELAY_QUEUE)
    public void delayAlarm(ComPropertyEquipment comPropertyEquipment){
        log.info("消息队列开始消费");
        if(!stringRedisTemplate.hasKey(comPropertyEquipment.getSerialNo())){
            ComPropertyAlarm comPropertyAlarm=new ComPropertyAlarm();
            comPropertyAlarm.setCreateTime(DateUtil.date());
            comPropertyAlarm.setPhone(comPropertyEquipment.getPhone());
            comPropertyAlarm.setSerialNo(comPropertyEquipment.getSerialNo());
            comPropertyAlarm.setType(ComPropertyAlarm.type.time);
            comPropertyAlarm.setCommunityId(comPropertyEquipment.getCommunityId());
            comPropertyAlarm.setName(comPropertyEquipment.getUsername());
            comPropertyAlarm.setStatus(ComPropertyAlarm.status.dcl);
            comPropertyAlarmDao.insert(comPropertyAlarm);
        }
    }
 
}