package com.sercurityControl.proteam.service.impl; import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSONObject; import com.sercurityControl.proteam.domain.QueryDescriptionInfoEntity; import com.sercurityControl.proteam.domain.QueryImageEntity; import com.sercurityControl.proteam.domain.QueryRecordEntity; import com.sercurityControl.proteam.util.HttpUtils; import org.springframework.stereotype.Service; import java.util.HashMap; import java.util.List; import java.util.UUID; /** * @author bonus * @data 2023/1/5 16:07 * @description 历史视频请求 */ @Service public class VideoRequest { /** * 授权账号 */ private static final String AK = "admin"; /** * 授权密码 */ private static final String SK = "admin"; /** * IP地址 */ private static final String URL = "http://127.0.0.1:8849/uvp"; /** * token验证 */ private static final String VALIDATE_TOKEN = "/uvp-backend-common/api/v1/validateToken"; /** * 设备前端录像查询 */ private static final String SES_QUERY_RECORD = "/uvp-micro-service/ses/api/v1/queryRecord"; /** * 集中存储录像查询 */ private static final String STORAGE_QUERY_RECORD = "/uvp-micro-service/storage/api/v1/queryRecord"; /** * 根据设备编码查询历史图片 */ private static final String QUERY_IMAGE_BY_DEVICE = "/uvp-backend-imagesurveillance/api/v1/image/queryImageByDevice"; /** * 根据设备编码获取设备近期上下线详细信息 */ private static final String QUERY_DEV_STATUS_DESCRIPTION_INFO = "/uvp-backend-maintenance/api/v1/dev/queryDevStatusDescriptionInfo"; /** * 获取token * * @return token */ public String getToken() { HashMap map = new HashMap<>(2); map.put("ak", AK); map.put("sk", SK); String request = HttpUtils.sendRequest(modifyUrl(VALIDATE_TOKEN), map, true); JSONObject jsonObject = JSONObject.parseObject(request); return jsonObject.getString("token"); } /** * 添加参数 * * @param api 接口 * @return 地址 */ private String modifyUrl(String api) { String timeStamp = String.valueOf(System.currentTimeMillis()); String nonce = UUID.randomUUID().toString(); return URL + api + "?ak=" + AK + "&token=" + getToken() + "&timeStamp=" + timeStamp + "&nonce=" + nonce; } /** * 设备前端录像查询 * * @param entity 条件 * @return 集合 */ public List getSesQueryRecord(QueryRecordEntity entity) { try { return getQueryRecordEntities(entity, SES_QUERY_RECORD); } catch (Exception e) { e.printStackTrace(); return null; } } /** * 集中存储录像查询 * * @param entity 条件 * @return 集合 */ public List getStorageQueryRecord(QueryRecordEntity entity) { try { return getQueryRecordEntities(entity, STORAGE_QUERY_RECORD); } catch (Exception e) { e.printStackTrace(); return null; } } /** * @param entity 条件 * @param api 接口 * @return 集合 */ private List getQueryRecordEntities(QueryRecordEntity entity, String api) { HashMap map = new HashMap<>(5); map.put("code", entity.getDeviceCode()); map.put("beginTime", entity.getBeginTime()); map.put("endTime", entity.getEndTime()); map.put("pageNo", entity.getPageNum()); map.put("pageSize", entity.getPageNum()); String request = HttpUtils.sendRequest(modifyUrl(api), map, true); JSONObject jsonObject = JSONObject.parseObject(request); if (("200").equals(jsonObject.getString("resultCode"))) { return JSON.parseArray(jsonObject.toJSONString(), QueryRecordEntity.class); } else { return null; } } /** * 根据设备编码查询历史图片 * * @param entity 条件 * @return 集合 */ public List getQueryImageByDevice(QueryImageEntity entity) { HashMap map = new HashMap<>(5); map.put("devCode", entity.getDeviceCode()); map.put("startDate", entity.getBeginTime()); map.put("endDate", entity.getEndTime()); map.put("pageNo", entity.getPageNum()); map.put("pageSize", entity.getPageNum()); String request = HttpUtils.sendRequest(modifyUrl(QUERY_IMAGE_BY_DEVICE), map, true); JSONObject jsonObject = JSONObject.parseObject(request); if (("200").equals(jsonObject.getString("resultCode"))) { return JSON.parseArray(jsonObject.toJSONString(), QueryImageEntity.class); } else { return null; } } /** * 根据设备编码获取设备近期上下线详细信息 * * @param entity 条件 * @return 集合 */ public List getQueryDevStatusDescriptionInfo(QueryDescriptionInfoEntity entity) { HashMap map = new HashMap<>(5); map.put("devCodes", entity.getDevCodes()); map.put("startTime", entity.getStartTime()); map.put("endTime", entity.getEndTime()); String request = HttpUtils.sendRequest(modifyUrl(QUERY_DEV_STATUS_DESCRIPTION_INFO), map, true); JSONObject jsonObject = JSONObject.parseObject(request); if (("200").equals(jsonObject.getString("resultCode"))) { return JSON.parseArray(jsonObject.toJSONString(), QueryDescriptionInfoEntity.class); } else { return null; } } }