Pu Zhibing
2025-04-09 b8a3a680f3e6720a8329bfaae571b09659aace52
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
package com.ruoyi.dataInterchange.controller;
 
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.utils.bean.BeanUtils;
import com.ruoyi.dataInterchange.api.vo.UPPlaybackMsgStartupAckVo;
import com.ruoyi.dataInterchange.dao.UPPlaybackMsgControlAckDao;
import com.ruoyi.dataInterchange.dao.UPPlaybackMsgStartupAckDao;
import com.ruoyi.dataInterchange.model.UPPlaybackMsgControlAck;
import com.ruoyi.dataInterchange.model.UPPlaybackMsgStartupAck;
import com.ruoyi.dataInterchange.server.DOWNPlaybackMsgControlService;
import com.ruoyi.dataInterchange.server.DOWNPlaybackMsgStartupService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
 
import javax.annotation.Resource;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
 
/**
 * @author zhibing.pu
 * @Date 2025/3/24 9:45
 */
@RestController
@RequestMapping("/playbackMsg")
public class PlaybackMsgController {
    
    @Resource
    private DOWNPlaybackMsgStartupService downPlaybackMsgStartupService;
    
    @Resource
    private UPPlaybackMsgStartupAckDao upPlaybackMsgStartupAckDao;
    
    @Resource
    private UPPlaybackMsgControlAckDao upPlaybackMsgControlAckDao;
    
    @Resource
    private DOWNPlaybackMsgControlService downPlaybackMsgControlService;
    
    
    /**
     * 远程录像回放请求
     *
     * @param inferiorPlatformId
     * @param vehicleNo
     * @return
     */
    @PostMapping("/playbackMsgStartup")
    public R<UPPlaybackMsgStartupAckVo> playbackMsgStartup(@RequestParam("inferiorPlatformId") Integer inferiorPlatformId, @RequestParam("vehicleNo") String vehicleNo,
                                                           @RequestParam("startTime") Long startTime, @RequestParam("endTime") Long endTime) {
        R<String> r = downPlaybackMsgStartupService.playbackMsgStartup(inferiorPlatformId, vehicleNo, startTime, endTime);
        if (200 != r.getCode()) {
            return R.fail(r.getMsg());
        }
        //发送成功,定时任务获取响应结果
        int num = 0;
        Long now = LocalDateTime.now().toEpochSecond(ZoneOffset.ofHours(8));
        while (true) {
            UPPlaybackMsgStartupAck upPlaybackMsgStartupAck = upPlaybackMsgStartupAckDao.findByInferiorPlatformIdAndVehicleNoAndCreateTimeAfter(inferiorPlatformId, vehicleNo, now);
            if (null == upPlaybackMsgStartupAck) {
                try {
                    Thread.sleep(1000L);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                num++;
                continue;
            }
            if(null != upPlaybackMsgStartupAck){
                int result = upPlaybackMsgStartupAck.getResult();
                switch (result){
                    case 0:
                        UPPlaybackMsgStartupAckVo vo = new UPPlaybackMsgStartupAckVo();
                        BeanUtils.copyProperties(upPlaybackMsgStartupAck, vo);
                        String encode = null;
                        try {
                            encode = URLEncoder.encode(vehicleNo, "UTF-8");
                        } catch (UnsupportedEncodingException e) {
                            throw new RuntimeException(e);
                        }
                        vo.setUrl("http://" + vo.getServerIP() + ":" + vo.getServerPort() + "/" + encode + "." + vo.getVehicleColor() + ".1.0." + r.getData());
                        return R.ok(vo);
                    case 1:
                        return R.fail("失败");
                    case 2:
                        return R.fail("不支持");
                    case 3:
                        return R.fail("会话结束");
                    case 4:
                        return R.fail("失效口令错误");
                    case 5:
                        return R.fail("不满足跨域条件");
                    default:
                        return R.fail("失败");
                }
            }
            if (num >= 30) {
                return R.fail("失败");
            }
        }
    }
    
    
    /**
     * 远程录像回放控制
     *
     * @param inferiorPlatformId 平台唯一码
     * @param vehicleNo          车牌号
     * @param controlType        控制类型
     * @param fastTime           快进快退倍数
     * @return
     */
    @PostMapping("/playbackMsgControl")
    public R playbackMsgControl(@RequestParam("inferiorPlatformId") Integer inferiorPlatformId, @RequestParam("vehicleNo") String vehicleNo,
                                         @RequestParam("controlType") Integer controlType, @RequestParam("fastTime") Integer fastTime) {
        R r = downPlaybackMsgControlService.playbackMsgControl(inferiorPlatformId, vehicleNo, controlType, fastTime);
        if (200 != r.getCode()) {
            return r;
        }
        //发送成功,定时任务获取响应结果
        int num = 0;
        long now = LocalDateTime.now().toEpochSecond(ZoneOffset.ofHours(8));
        while (true) {
            UPPlaybackMsgControlAck upPlaybackMsgControlAck = upPlaybackMsgControlAckDao.findByInferiorPlatformIdAndVehicleNoAndCreateTimeAfter(inferiorPlatformId, vehicleNo, now);
            if (null == upPlaybackMsgControlAck) {
                try {
                    Thread.sleep(1000L);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                num++;
                continue;
            }
            if (null != upPlaybackMsgControlAck) {
                return R.ok(upPlaybackMsgControlAck.getResult());
            }
            if (num >= 30) {
                return R.fail("远程响应失败");
            }
        }
    }
}