无关风月
21 小时以前 7cab5bda99ca42188bc15b2dae7d1fa4d1833fd9
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
package com.ruoyi.admin.controller;
 
 
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.admin.entity.Agreement;
import com.ruoyi.admin.entity.MasterWorker;
import com.ruoyi.admin.entity.Notices;
import com.ruoyi.admin.service.AgreementService;
import com.ruoyi.admin.service.MasterWorkerService;
import com.ruoyi.admin.vo.MonitorInfoVO;
import com.ruoyi.common.core.constant.Constants;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.security.annotation.Logical;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Random;
 
/**
 * <p>
 * 监控
 * </p>
 *
 * @author hjl
 * @since 2024-05-29
 */
@RestController
@RequestMapping("/monitor")
@Api(tags = {"大屏-监控"})
public class MonitorController {
    @Autowired
    private MasterWorkerService masterWorkerService;
 
    public static void main(String[] args) {
        HttpRequest post = HttpUtil.createGet("http://8.146.210.16:12056/api/v1/basic/devices?key=zT908g2j9niqrwO6ENIm5MZriXb0ZC%2Fq0hlFOWfm1Qs%3D");
        HttpResponse execute = post.execute();
        if (200 != execute.getStatus()) {
            return;
        }
        System.err.println(execute.body());
        JSONObject jsonObject = JSONObject.parseObject(execute.body());
        JSONArray data = jsonObject.getJSONArray("data");
        // 终端设备id
        List<JSONObject> strings = new ArrayList<>();
        for (Object datum : data) {
            JSONObject jsonObject1 = (JSONObject) datum;
            JSONObject jsonObject2 = new JSONObject();
            jsonObject2.put("terid", jsonObject1.getString("terid"));
            jsonObject2.put("deviceusername", jsonObject1.getString("deviceusername"));
            strings.add(jsonObject2);
        }
        System.err.println(strings);
    }
 
//    /**
//     * 回收员监控列表
//     */
//    @ApiOperation(value = "回收员监控列表")
//    @GetMapping(value = "/monitorList")
//    public R monitorList() {
//
//        // 获取token
//        String token = "";
//        HttpRequest post = HttpUtil.createGet("http://8.146.210.16:12056/api/v1/basic/key?username=dakaer&password=dakaer@888");
//        HttpResponse execute = post.execute();
//        if (200 != execute.getStatus()) {
//            return R.fail("获取三方监控token失败");
//        }
//        System.err.println("获取三方平台授权token响应参数" + execute.body());
//        token = JSONObject.parseObject(execute.body()).getJSONObject("data").getString("key");
//
//        // 获取司机列表
//        HttpRequest post1 = HttpUtil.createGet("http://8.146.210.16:12056/api/v1/basic/devices?key="+token);
//        HttpResponse execute1 = post1.execute();
//        if (200 != execute1.getStatus()) {
//            return R.fail("获取三方监控司机列表失败");
//        }
//        System.err.println(execute1.body());
//        JSONObject jsonObject = JSONObject.parseObject(execute1.body());
//        JSONArray data = jsonObject.getJSONArray("data");
//        // 终端设备id
//        List<JSONObject> strings = new ArrayList<>();
//        List<String> terIds = new ArrayList<>();
//        for (Object datum : data) {
//            JSONObject jsonObject1 = (JSONObject) datum;
//            JSONObject jsonObject2 = new JSONObject();
//            jsonObject2.put("terid",jsonObject1.getString("terid"));
//            jsonObject2.put("deviceusername",jsonObject1.getString("deviceusername"));
//            strings.add(jsonObject2);
//            terIds.add(jsonObject1.getString("terid"));
//        }
//        System.err.println(strings);
//        // 获取司机位置信息
//        HttpRequest post2 = HttpUtil.createPost("http://8.146.210.16:12056/api/v1/basic/gps/last");
//        JSONObject jsonObject4 = new JSONObject();
//        jsonObject4.put("key",token);
//        jsonObject4.put("terid",terIds);
//        post2.body(jsonObject4.toJSONString());
//
//        HttpResponse execute2 = post2.execute();
//        if (200 != execute2.getStatus()) {
//            return R.fail("获取三方监控司机列表失败");
//        }
//        System.err.println(execute2.body());
//        JSONObject jsonObject1 = JSONObject.parseObject(execute2.body());
//        JSONArray data2 = jsonObject1.getJSONArray("data");
//        // 终端设备id
//        List<JSONObject> strings1 = new ArrayList<>();
//        for (Object datum : data2) {
//            JSONObject jsonObject3 = (JSONObject) datum;
//            JSONObject jsonObject2 = new JSONObject();
//            jsonObject2.put("lat",jsonObject3.getString("gpslat"));
//            jsonObject2.put("lng",jsonObject3.getString("gpslng"));
//            jsonObject2.put("terid",jsonObject3.getString("terid"));
//            strings1.add(jsonObject2);
//        }
//        for (JSONObject object : strings1) {
//            String string = object.getString("terid");
//            for (JSONObject string1 : strings) {
//                if (string1.getString("terid").equals(string)){
//                    object.put("name",string1.getString("deviceusername"));
//                    break;
//                }
//            }
//        }
//        System.err.println(strings1);
//        return R.ok(strings1);
//    }
    /**
     * 回收员监控列表
     */
    @ApiOperation(value = "回收员监控详情")
    @GetMapping(value = "/monitorInfo")
 
    public R<MonitorInfoVO> monitorInfo(String terid) {
        MonitorInfoVO monitorInfoVO = new MonitorInfoVO();
        MasterWorker one = masterWorkerService.lambdaQuery().eq(MasterWorker::getTerminalCode, terid).last("limit 1").one();
        if (one==null){
            return R.fail("当前师傅未绑定终端编号");
        }
        // 获取token
        String token = "";
        HttpRequest post = HttpUtil.createGet("http://8.146.210.16:12056/api/v1/basic/key?username=dakaer&password=dakaer@888");
        HttpResponse execute = post.execute();
        if (200 != execute.getStatus()) {
        }
        System.err.println("获取三方平台授权token响应参数" + execute.body());
        token = JSONObject.parseObject(execute.body()).getJSONObject("data").getString("key");
        // 获取端口
        HttpRequest post9 = HttpUtil.createGet("http://8.146.210.16:12056/api/v1/basic/live/port?key="+token);
        HttpResponse execute9 = post9.execute();
        if (200 != execute9.getStatus()) {
        }
        System.err.println(execute9.body());
        JSONObject jsonObject9 = JSONObject.parseObject(execute9.body());
        JSONArray data9 = jsonObject9.getJSONArray("data");
        int i = new Random().nextInt(data9.size());
        Object o = data9.get(i);
        JSONObject temp = (JSONObject) o;
        String port = temp.getString("port");
 
        // 获取司机列表
        HttpRequest post2 = HttpUtil.createGet("http://8.146.210.16:12056/api/v1/basic/devices?key="+token);
        HttpResponse execute2 = post2.execute();
        if (200 != execute2.getStatus()) {
        }
        System.err.println(execute2.body());
        JSONObject jsonObject = JSONObject.parseObject(execute2.body());
        JSONArray data = jsonObject.getJSONArray("data");
        // 终端设备id
        List<JSONObject> strings = new ArrayList<>();
        List<String> terIds = new ArrayList<>();
        for (Object datum : data) {
            JSONObject jsonObject1 = (JSONObject) datum;
            JSONObject jsonObject2 = new JSONObject();
            jsonObject2.put("terid",jsonObject1.getString("terid"));
            jsonObject2.put("deviceusername",jsonObject1.getString("deviceusername"));
            jsonObject2.put("carlicence",jsonObject1.getString("carlicence"));
            strings.add(jsonObject2);
            terIds.add(jsonObject1.getString("terid"));
        }
        System.err.println(strings);
        // 获取url
        HttpRequest post1 = HttpUtil.createGet("http://8.146.210.16:12056/api/v1/basic/live/video?key="+token+"&terid="+terid+"&chl=1&audio=1&st=0&port="+port);
        HttpResponse execute1 = post1.execute();
        if (200 != execute1.getStatus()) {
        }
        System.err.println(execute1.body());
        JSONObject jsonObject3 = JSONObject.parseObject(execute1.body());
        JSONObject data3 = jsonObject3.getJSONObject("data");
        String url = data3.getString("url");
        monitorInfoVO.setUrl(url);
        monitorInfoVO.setCityName(one.getCity());
        monitorInfoVO.setName(one.getRealName());
        monitorInfoVO.setPhone(one.getPhone());
        monitorInfoVO.setProfilePicture(one.getProfilePicture());
        for (JSONObject string : strings) {
            if (string.getString("terid").equals(terid)){
                monitorInfoVO.setLicensePlateNumber(string.getString("carlicence"));
                break;
            }
        }
        return R.ok(monitorInfoVO);
    }
}