You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
114 lines
3.3 KiB
Java
114 lines
3.3 KiB
Java
package com.ruoyi.common.utils;
|
|
|
|
import com.ruoyi.common.exception.ServiceException;
|
|
|
|
import java.io.UnsupportedEncodingException;
|
|
import java.lang.reflect.Field;
|
|
import java.net.URLEncoder;
|
|
import java.util.*;
|
|
|
|
public class RequestParamsUtil
|
|
{
|
|
/**
|
|
* http
|
|
*/
|
|
public final static String HTTP = "http://";
|
|
|
|
/**
|
|
* 分隔符
|
|
*/
|
|
public final static String SEPARATOR = ":";
|
|
|
|
/**
|
|
* 历史遥测
|
|
*/
|
|
public final static String HISTORY_TELEMETRY = "/ipark-device-management/device/history-telemetry/list";
|
|
|
|
/**
|
|
* 预览url
|
|
*/
|
|
public final static String PREVIEW_URLS = "/ipark-video/video/service/api/cameras/previewURLs";
|
|
|
|
/**
|
|
* 控制
|
|
*/
|
|
public final static String CONTROLLING = "/ipark-video/video/service/api/ptzs/controlling";
|
|
|
|
public final static String CAMERA_SEARCH = "/ipark-video/video/resource/api/camera/search";
|
|
|
|
/**
|
|
* 设备信息
|
|
*/
|
|
public final static String DEVICE_INFO = "/ipark-device-management/device-external/devices/list";
|
|
|
|
/**
|
|
* 设备模型
|
|
*/
|
|
public final static String DEVICE_MODEL = "/ipark-device-management/device-external/models/{id}";
|
|
|
|
/**
|
|
* 设备分页列表
|
|
*/
|
|
public final static String DEVICE_PAGE_LIST = "/ipark-device-management/device-external/devices/page";
|
|
|
|
/**
|
|
* 查询简明设备列表
|
|
*/
|
|
public final static String BRIEF_DEVICE = "/ipark-device-management/device/brief-device/list";
|
|
|
|
/**
|
|
* 查询简明设备列表
|
|
*/
|
|
public final static String DEVICE_TYPE = "/ipark-device-management/device/brief-device-type/list";
|
|
|
|
/**
|
|
* 手动抓图
|
|
*/
|
|
public final static String MANUAL_CAPTURE = "/api/video/v1/manualCapture";
|
|
|
|
private RequestParamsUtil() {
|
|
}
|
|
|
|
public static String buildParams(Object param) {
|
|
Map<String, Object> map = new HashMap<>();
|
|
Field[] fields = param.getClass().getDeclaredFields();
|
|
for (Field field : fields) {
|
|
field.setAccessible(true);
|
|
try {
|
|
if (field.get(param) == null) {
|
|
continue;
|
|
}
|
|
map.put(field.getName(), field.get(param));
|
|
} catch (Exception e) {
|
|
throw new ServiceException("构建请求参数异常...");
|
|
}
|
|
}
|
|
String params;
|
|
try {
|
|
params = createLinkStringByGet(map);
|
|
} catch (UnsupportedEncodingException e) {
|
|
throw new ServiceException("构建请求参数异常...");
|
|
}
|
|
return params;
|
|
}
|
|
|
|
|
|
|
|
private static String createLinkStringByGet(Map<String, Object> params) throws UnsupportedEncodingException {
|
|
List<String> keys = new ArrayList<>(params.keySet());
|
|
Collections.sort(keys);
|
|
StringBuilder stringBuilder = new StringBuilder();
|
|
for (int i = 0; i < keys.size(); i++) {
|
|
String key = keys.get(i);
|
|
Object value = params.get(key);
|
|
if (i == keys.size() - 1) {
|
|
stringBuilder.append(key).append("=").append(URLEncoder.encode(String.valueOf(value), "utf-8"));
|
|
} else {
|
|
stringBuilder.append(key).append("=").append(URLEncoder.encode(String.valueOf(value), "utf-8")).append("&");
|
|
}
|
|
|
|
}
|
|
return stringBuilder.toString();
|
|
}
|
|
}
|