jiazx0107@163.com
2023-05-17 620eab6cca2bc9ef9ea6d3067a0a5ba1deadbd1c
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package com.ld.igds.io.notify.impl;
 
import com.ld.igds.constant.BizType;
import com.ld.igds.constant.RedisConst;
import com.ld.igds.inout.dto.InoutApiData;
import com.ld.igds.io.notify.NotifyLprService;
import com.ld.igds.util.ContextUtil;
import com.ld.igds.util.RedisUtil;
import com.ld.igds.websocket.WebSocketPacket;
import com.ld.igds.websocket.WebSocketServer;
 
import lombok.extern.slf4j.Slf4j;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
 
@Slf4j
@Repository(NotifyLprService.BEAN_ID)
public class NotifyLprServiceImpl implements NotifyLprService {
 
    @Autowired
    private WebSocketServer socketServer;
    @Autowired
    private RedisUtil redisUtil;
 
    public static  final String KEY_LPR = "T_LPR";
 
    @SuppressWarnings("static-access")
    @Override
    public void notify(InoutApiData plate) {
        if (null == plate) return;
        WebSocketPacket packet = new WebSocketPacket();
        packet.setCompanyId(ContextUtil.getDefaultCompanyId());
        packet.setBizType(BizType.INOUT_IN.getCode());
        packet.setBizTag(plate.getInoutProgress());
        packet.setUserId(plate.getUserId());
        packet.setBizId("PLATE_NUM");
        
        packet.setData(plate);
        
        log.debug("向前端推送车牌信息={}", plate.toString());
        socketServer.sendByUser(packet);
    }
 
 
 
    @Override
    public InoutApiData getLpr(String key) {
        key = RedisConst.buildKey(ContextUtil.getDefaultCompanyId(),KEY_LPR,key);
        InoutApiData lprDto = (InoutApiData) redisUtil.get(key);
        if(null == lprDto) return null;
        return lprDto;
    }
 
    @Override
    public void remove(String key) {
        key = RedisConst.buildKey(ContextUtil.getDefaultCompanyId(),KEY_LPR,key);
        redisUtil.del(key);
    }
 
    @Override
    public void setLpr(String sn, InoutApiData lprDto) {
        String key = RedisConst.buildKey(ContextUtil.getDefaultCompanyId(),KEY_LPR,sn);
        redisUtil.set(key,lprDto, 60 * 60);
    }
 
}