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; /** *

* 监控 *

* * @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 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 strings = new ArrayList<>(); // List 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 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 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 strings = new ArrayList<>(); List 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); } }