wisdomisite-java/src/main/java/com/zhgd/xmgl/util/HikvisionUtil.java
2024-07-05 19:31:06 +08:00

914 lines
34 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.zhgd.xmgl.util;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.hikvision.artemis.sdk.Client;
import com.hikvision.artemis.sdk.Request;
import com.hikvision.artemis.sdk.Response;
import com.hikvision.artemis.sdk.constant.Constants;
import com.hikvision.artemis.sdk.enums.Method;
import com.zhgd.jeecg.common.execption.OpenAlertException;
import com.zhgd.jeecg.common.execption.OpenPromptException;
import com.zhgd.xmgl.base.HikvisionOrganization;
import com.zhgd.xmgl.base.HikvisionReservationCarInfo;
import com.zhgd.xmgl.call.HikvisionCall;
import com.zhgd.xmgl.call.entity.ChargeDeletionParam;
import com.zhgd.xmgl.modules.project.entity.Project;
import com.zhgd.xmgl.modules.worker.entity.WorkerInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;
/**
* 海康接口
*/
@Slf4j
@Component
public class HikvisionUtil {
public static final String SUC_CODE = "0";
/**
* 获取JSONObject的请求结果
*
* @param host
* @param path
* @param body
* @param querys
* @param appKey
* @param appSecret
* @return
* @throws Exception
*/
public static JSONObject doPostRtObj(String host, String path, String body, Map<String, String> querys, String appKey, String appSecret) throws Exception {
return JSONObject.parseObject(doPost(host, path, body, querys, appKey, appSecret));
}
/**
* 发送Post请求
*
* @param host
* @param path
* @param body
* @param querys
* @param appKey
* @param appSecret
* @return
* @throws Exception
*/
public static String doPost(String host, String path, String body, Map<String, String> querys, String appKey, String appSecret) throws Exception {
log.info("调用海康接口.url:{}", host + path);
log.info("调用海康接口.body:{}", body);
Map<String, String> headers = new HashMap<>(16);
headers.put("Accept", "*/*");
headers.put("Content-Type", "application/json");
Request request = new Request(Method.POST_STRING, host, path, appKey, appSecret, Constants.DEFAULT_TIMEOUT * 30);
request.setHeaders(headers);
request.setQuerys(querys);
request.setStringBody(body);
Response response = Client.execute(request);
String responseStr = getResponseResult(response);
log.info("调用海康接口.getResponseResult:{}", responseStr);
return responseStr;
}
/**
* 获取响应结果
*
* @param response
* @return
*/
private static String getResponseResult(Response response) {
String responseStr = null;
int statusCode = response.getStatusCode();
String prefix2 = "2";
String prefix3 = "3";
if (!String.valueOf(statusCode).startsWith(prefix2) && !String.valueOf(statusCode).startsWith(prefix3)) {
responseStr = response.getBody();
} else {
responseStr = response.getBody();
}
return responseStr;
}
/**
* 成功后获取data结果
*
* @param rs
* @return
*/
public static JSONObject getJsonObjectData(String rs) {
JSONObject rsJo = JSONObject.parseObject(rs);
String code = rsJo.getString("code");
if (Objects.equals(code, SUC_CODE)) {
return rsJo.getJSONObject("data");
} else {
log.error("海康返回错误码:{}", rs);
throw new OpenAlertException("海康返回错误码");
}
}
/**
* 成功后获取data结果
*
* @param rsJo
* @return
*/
public static JSONObject getJsonObjectData(JSONObject rsJo) {
String code = rsJo.getString("code");
if (Objects.equals(code, SUC_CODE)) {
return rsJo.getJSONObject("data");
} else {
log.error("海康返回错误码:{}", rsJo.toJSONString());
throw new OpenAlertException("下发异常:海康返回错误码");
}
}
/**
* 获取响应结果
*
* @param rs
* @return
*/
public static JSONArray getJsonArrayData(String rs) {
JSONObject rsJo = JSONArray.parseObject(rs);
String code = rsJo.getString("code");
if (Objects.equals(code, SUC_CODE)) {
return rsJo.getJSONArray("data");
} else {
log.error("海康返回错误码:{}", rs);
throw new OpenAlertException("海康返回错误码");
}
}
/**
* 是否请求成功
*
* @param rs
* @return
*/
public static boolean isSuccess(String rs) {
JSONObject rsJo = JSONObject.parseObject(rs);
String code = rsJo.getString("code");
if (Objects.equals(code, SUC_CODE)) {
return true;
} else {
return false;
}
}
/**
* 是否请求成功
*
* @param rsJo
* @return
*/
public static boolean isSuccess(JSONObject rsJo) {
String code = rsJo.getString("code");
if (Objects.equals(code, SUC_CODE)) {
return true;
} else {
return false;
}
}
/**
* 是否请求成功
*
* @param rsJo
* @return
*/
public static boolean isFail(JSONObject rsJo) {
String code = rsJo.getString("code");
if (Objects.equals(code, SUC_CODE)) {
return false;
} else {
return true;
}
}
/**
* 添加初始化分页
*
* @param param
* @return
*/
public static JSONObject addPageParamIfAbsent(JSONObject param) {
param.putIfAbsent("pageNo", 1);
param.putIfAbsent("pageSize", 1000);
return param;
}
/**
* 查询车辆列表v2-固定车辆
*
* @param project
* @return
*/
public static JSONObject getFixCarList(Project project, JSONObject param) throws Exception {
if (project == null || !Objects.equals(project.getSyncHikvision(), 1)) {
return null;
}
final String artemisPath = "/artemis";
final String path = artemisPath + "/api/resource/v2/vehicle/advance/vehicleList";
String host = "https://" + project.getArtemisConfigHost();
return doPostRtObj(host, path, param.toJSONString(), null, project.getArtemisConfigAppKey(), project.getArtemisConfigAppSecret());
}
/**
* 查询车辆列表v2-固定车辆
*
* @param carNumber
* @param project
* @param pageNo
* @return
* @throws Exception
*/
public static JSONObject getFixCarListByCarNumber(String carNumber, Project project, Integer pageNo) throws Exception {
JSONObject jo = new JSONObject();
//模糊查询
jo.put("plateNo", carNumber);
jo.put("pageNo", pageNo);
jo.put("pageSize", 1000);
return getFixCarList(project, jo);
}
/**
* 查询车辆分类
*/
public static JSONArray getCategoryList(Project project) throws Exception {
final String artemisPath = "/artemis";
final String path = artemisPath + "/api/pms/v1/car/category/search";
String host = "https://" + project.getArtemisConfigHost();
JSONObject jo = new JSONObject();
String rs = doPost(host, path, jo.toJSONString(), null, project.getArtemisConfigAppKey(), project.getArtemisConfigAppSecret());
return getJsonArrayData(rs);
}
/**
* 车辆群组绑定
*
* @param project
* @param param
* @return
* @throws Exception
*/
public static JSONObject bindCarCategory(Project project, JSONObject param) throws Exception {
if (project == null || !Objects.equals(project.getSyncHikvision(), 1)) {
return null;
}
final String artemisPath = "/artemis";
final String path = artemisPath + "/api/pms/v1/car/categoryBind";
String host = "https://" + project.getArtemisConfigHost();
return doPostRtObj(host, path, param.toJSONString(), null, project.getArtemisConfigAppKey(), project.getArtemisConfigAppSecret());
}
/**
* 删除人脸
*
* @param project
* @param workerFaceId
* @return
*/
public static JSONObject deleteWorkerFace(Project project, String workerFaceId) throws Exception {
final String artemisPath = "/artemis";
final String path = artemisPath + "/api/resource/v1/face/single/delete";
String host = "https://" + project.getArtemisConfigHost();
JSONObject jo = new JSONObject();
jo.put("faceId", workerFaceId);
return JSON.parseObject(doPost(host, path, jo.toJSONString(), null, project.getArtemisConfigAppKey(), project.getArtemisConfigAppSecret()));
}
/**
* 删除人员
*
* @param uniqueId
* @param project
* @return
* @throws Exception
*/
public static JSONObject deleteWorkerById(String uniqueId, Project project) throws Exception {
final String artemisPath = "/artemis";
final String path = artemisPath + "/api/resource/v1/person/batch/delete";
String host = "https://" + project.getArtemisConfigHost();
JSONObject jsonBody = new JSONObject();
jsonBody.put("personIds", Arrays.asList(uniqueId));
String body = jsonBody.toJSONString();
return doPostRtObj(host, path, body, null, project.getArtemisConfigAppKey(), project.getArtemisConfigAppSecret());
}
/**
* 根据人员唯一字段获取人员详细信息
*
* @param project
* @return
* @throws Exception
*/
public static JSONObject queryWorkerByCondition(Project project, JSONObject param) throws Exception {
final String artemisPath = "/artemis";
final String path = artemisPath + "/api/resource/v1/person/condition/personInfo";
String host = "https://" + project.getArtemisConfigHost();
return doPostRtObj(host, path, param.toJSONString(), null, project.getArtemisConfigAppKey(), project.getArtemisConfigAppSecret());
}
/**
* 获取停车库列表
*
* @param project
*/
public static JSONArray getParkList(Project project) throws Exception {
if (project == null || !Objects.equals(project.getSyncHikvision(), 1)) {
return null;
}
final String artemisPath = "/artemis";
final String path = artemisPath + "/api/resource/v1/park/parkList";
String host = "https://" + project.getArtemisConfigHost();
JSONObject jo = new JSONObject();
String rs = doPost(host, path, jo.toJSONString(), null, project.getArtemisConfigAppKey(), project.getArtemisConfigAppSecret());
return getJsonArrayData(rs);
}
/**
* 获取项目名称的停车场的parkIndexCode没有一样名字的就取第一个停车场
*
* @param project
* @return
*/
public static String getProjectParkCode(Project project) throws Exception {
JSONArray parkList = getParkList(project);
if (parkList != null && parkList.size() > 0) {
for (int i = 0; i < parkList.size(); i++) {
JSONObject jo = parkList.getJSONObject(i);
if (Objects.equals(jo.getString("parkName"), project.getProjectName())) {
return jo.getString("parkIndexCode");
}
}
throw new OpenPromptException("未查询到对应项目的停车场信息");
} else {
throw new OpenPromptException("停车场为空");
}
}
/**
* 查询预约记录v2
*
* @param carNumber
* @param project
* @param pageNo
* @param resvState
*/
public static JSONObject getReservationCarInfoList(String carNumber, Project project, int pageNo, int resvState) throws Exception {
final String artemisPath = "/artemis";
final String path = artemisPath + "/api/pms/v2/reserveRecord/page";
String host = "https://" + project.getArtemisConfigHost();
HikvisionReservationCarInfo info = getHikvisionReservationCarInfoObj(carNumber, project, pageNo, resvState);
return doPostRtObj(host, path, JSON.toJSONString(info), null, project.getArtemisConfigAppKey(), project.getArtemisConfigAppSecret());
}
/**
* 获取isc中预约状态为0已预约3已进场并且车辆在有效期内的预约车查询预约记录v2
*
* @param carNumber
* @param project
*/
public static JSONArray getIscActiveReservationCarList(String carNumber, Project project) throws Exception {
long total = 0;
int pageNo = 0;
JSONArray rt = new JSONArray();
do {
pageNo++;
JSONObject rsJo = getReservationCarInfoList(carNumber, project, pageNo, 0);
JSONObject dataJo = getJsonObjectData(rsJo);
total = dataJo.getInteger("total");
if (CollUtil.isNotEmpty(dataJo.getJSONArray("list"))) {
rt.addAll(dataJo.getJSONArray("list"));
}
} while (total > pageNo * 1000L);
total = 0;
pageNo = 0;
do {
pageNo++;
JSONObject rsJo = getReservationCarInfoList(carNumber, project, pageNo, 3);
JSONObject dataJo = getJsonObjectData(rsJo);
total = dataJo.getInteger("total");
if (CollUtil.isNotEmpty(dataJo.getJSONArray("list"))) {
rt.addAll(dataJo.getJSONArray("list"));
}
} while (total > pageNo * 1000L);
Date date = new Date();
//取有效时间内的车辆并去重车牌号
List<Object> list = rt.stream().filter(o -> {
String startTime = ((JSONObject) o).getString("startTime");
String endTime = ((JSONObject) o).getString("endTime");
return DateUtil.compare(DateUtil.parse(endTime), date) >= 0;
}).filter(distinctByKey(o1 -> ((JSONObject) o1).getString("plateNo"))).collect(Collectors.toList());
return JSONArray.parseArray(JSON.toJSONString(list));
}
private static <T> Predicate<T> distinctByKey(Function<? super T, ?> keyExtractor) {
Map<Object, Boolean> seen = new ConcurrentHashMap<>();
return t -> seen.putIfAbsent(keyExtractor.apply(t), Boolean.TRUE) == null;
}
/**
* 映射车辆预约信息
*
* @param carNumber
* @param project
* @param pageNo
* @param resvState
* @return
* @throws Exception
*/
private static HikvisionReservationCarInfo getHikvisionReservationCarInfoObj(String carNumber, Project project, int pageNo, int resvState) throws Exception {
String projectParkCode = HikvisionUtil.getProjectParkCode(project);
HikvisionReservationCarInfo hikvisionReservationCarInfo = new HikvisionReservationCarInfo();
hikvisionReservationCarInfo.setParkSyscode(projectParkCode);
hikvisionReservationCarInfo.setPlateNo(carNumber);
hikvisionReservationCarInfo.setResvState(resvState);
//hikvisionReservationCarInfo.setResvWay();
//hikvisionReservationCarInfo.setAllowTimes();
//hikvisionReservationCarInfo.setIsCharge();
//hikvisionReservationCarInfo.setStartTime();
//hikvisionReservationCarInfo.setEndTime();
hikvisionReservationCarInfo.setPageNo(pageNo);
hikvisionReservationCarInfo.setPageSize(1000L);
return hikvisionReservationCarInfo;
}
/**
* 获取组织列表v2
*
* @param project
* @param jo
*/
public static String getOrgV2(Project project, JSONObject jo) throws Exception {
if (project == null || !Objects.equals(project.getSyncHikvision(), 1)) {
return null;
}
final String artemisPath = "/artemis";
final String path = artemisPath + "/api/resource/v2/org/advance/orgList";
String host = "https://" + project.getArtemisConfigHost();
return doPost(host, path, jo.toJSONString(), null, project.getArtemisConfigAppKey(), project.getArtemisConfigAppSecret());
}
/**
* 批量添加组织
*
* @param project
* @param hikvisionOrganization
* @return
* @throws Exception
*/
public static String addOrg(Project project, HikvisionOrganization hikvisionOrganization) throws Exception {
final String artemisPath = "/artemis";
final String path = artemisPath + "/api/resource/v1/org/batch/add";
String host = "https://" + project.getArtemisConfigHost();
ArrayList<HikvisionOrganization> list = new ArrayList<>();
list.add(hikvisionOrganization);
return doPost(host, path, JSON.toJSONString(list), null, project.getArtemisConfigAppKey(), project.getArtemisConfigAppSecret());
}
/**
* 批量删除组织
*
* @param project
* @param indexCodes
* @return
* @throws Exception
*/
public static String deleteOrgByIndexCodes(Project project, List<String> indexCodes) throws Exception {
final String artemisPath = "/artemis";
final String path = artemisPath + "/api/resource/v1/org/batch/delete";
String host = "https://" + project.getArtemisConfigHost();
JSONObject jo = new JSONObject();
jo.put("indexCodes", indexCodes);
return doPost(host, path, jo.toJSONString(), null, project.getArtemisConfigAppKey(), project.getArtemisConfigAppSecret());
}
/**
* 查询黑名单(布防)车辆
*
* @param project
* @return
*/
public static JSONObject getBlackCarList(Project project, JSONObject param) throws Exception {
if (project == null || !Objects.equals(project.getSyncHikvision(), 1)) {
return null;
}
final String artemisPath = "/artemis";
final String path = artemisPath + "/api/pms/v1/alarmCar/page";
String host = "https://" + project.getArtemisConfigHost();
return JSON.parseObject(doPost(host, path, JSON.toJSONString(param), null, project.getArtemisConfigAppKey(), project.getArtemisConfigAppSecret()));
}
/**
* 获取组织下人员列表v2
*
* @param project
* @return
*/
public static JSONObject getWorkerListByOrg(Project project, JSONObject param) throws Exception {
if (project == null || !Objects.equals(project.getSyncHikvision(), 1)) {
return null;
}
final String artemisPath = "/artemis";
final String path = artemisPath + "/api/resource/v2/person/orgIndexCode/personList";
String host = "https://" + project.getArtemisConfigHost();
return JSON.parseObject(doPost(host, path, JSON.toJSONString(param), null, project.getArtemisConfigAppKey(), project.getArtemisConfigAppSecret()));
}
/**
* 根据组织编号获取组织详细信息
*
* @param project
* @return
*/
public static JSONObject getOrgListByIndex(Project project, JSONObject param) throws Exception {
if (project == null || !Objects.equals(project.getSyncHikvision(), 1)) {
return null;
}
final String artemisPath = "/artemis";
final String path = artemisPath + "/api/resource/v1/org/orgIndexCodes/orgInfo";
String host = "https://" + project.getArtemisConfigHost();
return JSON.parseObject(doPost(host, path, JSON.toJSONString(param), null, project.getArtemisConfigAppKey(), project.getArtemisConfigAppSecret()));
}
/**
* 根据父组织编号获取下级组织列表
*
* @param project
* @return
*/
public static JSONObject getSubOrgListByParentOrg(Project project, JSONObject param) throws Exception {
if (project == null || !Objects.equals(project.getSyncHikvision(), 1)) {
return null;
}
final String artemisPath = "/artemis";
final String path = artemisPath + "/api/resource/v1/org/parentOrgIndexCode/subOrgList";
String host = "https://" + project.getArtemisConfigHost();
return JSON.parseObject(doPost(host, path, JSON.toJSONString(param), null, project.getArtemisConfigAppKey(), project.getArtemisConfigAppSecret()));
}
/**
* 取消车辆包期,调用预约车之前需要调用
*
* @param project
* @return
*/
public static JSONObject chargeDeletion(Project project, ChargeDeletionParam param) throws Exception {
if (project == null || !Objects.equals(project.getSyncHikvision(), 1)) {
return null;
}
final String artemisPath = "/artemis";
final String path = artemisPath + "/api/pms/v1/car/charge/deletion";
String host = "https://" + project.getArtemisConfigHost();
return JSON.parseObject(doPost(host, path, JSON.toJSONString(param), null, project.getArtemisConfigAppKey(), project.getArtemisConfigAppSecret()));
}
/**
* 简单同步权限下载_根据人员与设备通道指定下载
*
* @param project
* @return
*/
public static JSONObject downloadSimple(Project project, String param) throws Exception {
if (project == null || !Objects.equals(project.getSyncHikvision(), 1)) {
return null;
}
final String artemisPath = "/artemis";
final String path = artemisPath + "/api/acps/v1/authDownload/task/simpleDownload";
String host = "https://" + project.getArtemisConfigHost();
return JSON.parseObject(doPost(host, path, param, null, project.getArtemisConfigAppKey(), project.getArtemisConfigAppSecret()));
}
/**
* 添加人员
*
* @param workerInfo
* @param project
* @return
* @throws Exception
*/
public static String addWorker(WorkerInfo workerInfo, Project project) throws Exception {
final String artemisPath = "/artemis";
final String path = artemisPath + "/api/resource/v2/person/single/add";
String host = "https://" + project.getArtemisConfigHost();
String body = HikvisionCall.getWorkerJson(workerInfo);
String rs = doPost(host, path, body, null, project.getArtemisConfigAppKey(), project.getArtemisConfigAppSecret());
return rs;
}
/**
* 编剧人员
*
* @param workerInfo
* @param project
* @return
* @throws Exception
*/
public static String editWorker(WorkerInfo workerInfo, Project project) throws Exception {
final String artemisPath = "/artemis";
final String path = artemisPath + "/api/resource/v1/person/single/update";
String host = "https://" + project.getArtemisConfigHost();
String body = HikvisionCall.getWorkerJson(workerInfo);
return doPost(host, path, body, null, project.getArtemisConfigAppKey(), project.getArtemisConfigAppSecret());
}
/**
* 添加人脸
*
* @param workerInfo
* @param project
* @return
* @throws Exception
*/
public static String addWorkerFace(WorkerInfo workerInfo, Project project) throws Exception {
final String artemisPath = "/artemis";
final String path = artemisPath + "/api/resource/v1/face/single/add";
String host = "https://" + project.getArtemisConfigHost();
JSONObject jo = new JSONObject();
jo.put("personId", String.valueOf(workerInfo.getId()));
jo.put("faceData", Base64Util.convertFileToBase64(PathUtil.reviseSlash(PathUtil.getBasePath() + "/" + workerInfo.getFieldAcquisitionUrl())));
return doPost(host, path, jo.toJSONString(), null, project.getArtemisConfigAppKey(), project.getArtemisConfigAppSecret());
}
/**
* 车辆布防
*
* @param project
* @return
*/
public static JSONObject addAlarmCar(Project project, JSONObject param) throws Exception {
if (project == null || !Objects.equals(project.getSyncHikvision(), 1)) {
return null;
}
final String artemisPath = "/artemis";
final String path = artemisPath + "/api/pms/v1/alarmCar/addition";
String host = "https://" + project.getArtemisConfigHost();
return JSON.parseObject(doPost(host, path, JSON.toJSONString(param), null, project.getArtemisConfigAppKey(), project.getArtemisConfigAppSecret()));
}
/**
* 取消车辆布防
*
* @param project
* @return
*/
public static JSONObject deletionAlarmCar(Project project, JSONObject param) throws Exception {
if (project == null || !Objects.equals(project.getSyncHikvision(), 1)) {
return null;
}
final String artemisPath = "/artemis";
final String path = artemisPath + "/api/pms/v1/alarmCar/deletion";
String host = "https://" + project.getArtemisConfigHost();
return JSON.parseObject(doPost(host, path, JSON.toJSONString(param), null, project.getArtemisConfigAppKey(), project.getArtemisConfigAppSecret()));
}
/**
* 删除车辆
*
* @param carId
* @param project
* @return
* @throws Exception
*/
public static String deleteCarInfoById(String carId, Project project) throws Exception {
final String artemisPath = "/artemis";
final String path = artemisPath + "/api/resource/v1/vehicle/batch/delete";
String host = "https://" + project.getArtemisConfigHost();
JSONObject jo = new JSONObject();
ArrayList<String> list = new ArrayList<>();
list.add(carId);
jo.put("vehicleIds", list);
String rs = doPost(host, path, jo.toJSONString(), null, project.getArtemisConfigAppKey(), project.getArtemisConfigAppSecret());
return rs;
}
/**
* 查询门禁点事件v2
*
* @param project
* @param param
*/
public static String getDoorEvents(Project project, JSONObject param) throws Exception {
if (project == null || !Objects.equals(project.getSyncHikvision(), 1)) {
return null;
}
final String artemisPath = "/artemis";
final String path = artemisPath + "/api/acs/v2/door/events";
String host = "https://" + project.getArtemisConfigHost();
return doPost(host, path, param.toJSONString(), null, project.getArtemisConfigAppKey(), project.getArtemisConfigAppSecret());
}
/**
* 查询过车记录
*
* @param project
* @param param
*/
public static String getCrossRecords(Project project, JSONObject param) throws Exception {
if (project == null || !Objects.equals(project.getSyncHikvision(), 1)) {
return null;
}
final String artemisPath = "/artemis";
final String path = artemisPath + "/api/pms/v1/crossRecords/page";
String host = "https://" + project.getArtemisConfigHost();
JSONObject jo = new JSONObject();
jo.put("pageNo", param.getIntValue("pageNo"));
jo.put("pageSize", 1000);
//ISO8601时间格式
jo.put("startTime", param.getString("startTime"));
jo.put("endTime", param.getString("endTime"));
jo.put("parkSyscode", param.getString("parkSyscode"));
return doPost(host, path, jo.toJSONString(), null, project.getArtemisConfigAppKey(), project.getArtemisConfigAppSecret());
}
/**
* 查询门禁点列表v2
*
* @param project
* @param param
* @return
*/
public static JSONObject getDoorsV2(Project project, JSONObject param) throws Exception {
if (project == null || !Objects.equals(project.getSyncHikvision(), 1)) {
return null;
}
final String artemisPath = "/artemis";
final String path = artemisPath + "/api/resource/v2/door/search";
String host = "https://" + project.getArtemisConfigHost();
return JSON.parseObject(doPost(host, path, param.toJSONString(), null, project.getArtemisConfigAppKey(), project.getArtemisConfigAppSecret()));
}
/**
* 编辑组织
*
* @param project
* @param hikvisionOrganization
* @return
* @throws Exception
*/
public static String editOrg(Project project, HikvisionOrganization hikvisionOrganization) throws Exception {
final String artemisPath = "/artemis";
final String path = artemisPath + "/api/resource/v1/org/single/update";
String host = "https://" + project.getArtemisConfigHost();
String rs = doPost(host, path, JSONArray.toJSONString(hikvisionOrganization), null, project.getArtemisConfigAppKey(), project.getArtemisConfigAppSecret());
return rs;
}
/**
* 添加权限配置
*
* @param project
* @param param
* @return
* @throws Exception
*/
public static JSONObject addAuth(Project project, JSONObject param) throws Exception {
final String artemisPath = "/artemis";
final String path = artemisPath + "/api/acps/v1/auth_config/add";
String host = "https://" + project.getArtemisConfigHost();
return doPostRtObj(host, path, JSONArray.toJSONString(param), null, project.getArtemisConfigAppKey(), project.getArtemisConfigAppSecret());
}
/**
* 删除权限配置
*
* @param project
* @param param
* @return
* @throws Exception
*/
public static JSONObject deleteAuth(Project project, JSONObject param) throws Exception {
final String artemisPath = "/artemis";
final String path = artemisPath + "/api/acps/v1/auth_config/delete";
String host = "https://" + project.getArtemisConfigHost();
return doPostRtObj(host, path, JSONArray.toJSONString(param), null, project.getArtemisConfigAppKey(), project.getArtemisConfigAppSecret());
}
/**
* 根据出入权限配置快捷下载
*
* @param project
* @param param
* @return
* @throws Exception
*/
public static JSONObject downloadAuth(Project project, JSONObject param) throws Exception {
final String artemisPath = "/artemis";
final String path = artemisPath + "/api/acps/v1/authDownload/configuration/shortcut";
String host = "https://" + project.getArtemisConfigHost();
return doPostRtObj(host, path, JSONArray.toJSONString(param), null, project.getArtemisConfigAppKey(), project.getArtemisConfigAppSecret());
}
/**
* 查询下载任务进度
*
* @param project
* @param param
* @return
* @throws Exception
*/
public static JSONObject queryDownloadProgress(Project project, JSONObject param) throws Exception {
final String artemisPath = "/artemis";
final String path = artemisPath + "/api/acps/v1/authDownload/task/progress";
String host = "https://" + project.getArtemisConfigHost();
return doPostRtObj(host, path, JSONArray.toJSONString(param), null, project.getArtemisConfigAppKey(), project.getArtemisConfigAppSecret());
}
/**
* 查询权限条目列表
*
* @param project
* @param param
* @return
* @throws Exception
*/
public static JSONObject queryAuthItem(Project project, JSONObject param) throws Exception {
final String artemisPath = "/artemis";
final String path = artemisPath + "/api/acps/v1/auth_item/list/search";
String host = "https://" + project.getArtemisConfigHost();
return doPostRtObj(host, path, JSONArray.toJSONString(param), null, project.getArtemisConfigAppKey(), project.getArtemisConfigAppSecret());
}
/**
* 查询人员列表v2
*
* @param project
* @param param
* @return
* @throws Exception
*/
public static JSONObject queryPersonList(Project project, JSONObject param) throws Exception {
final String artemisPath = "/artemis";
final String path = artemisPath + "/api/resource/v2/person/advance/personList";
String host = "https://" + project.getArtemisConfigHost();
return doPostRtObj(host, path, JSONArray.toJSONString(param), null, project.getArtemisConfigAppKey(), project.getArtemisConfigAppSecret());
}
/**
* 获取单个劳务人员信息根据人员id
*
* @param uniqueId
* @param project
* @return
*/
public static JSONObject getWorkerInfoByPersonId(String uniqueId, Project project) throws Exception {
final String artemisPath = "/artemis";
final String path = artemisPath + "/api/resource/v1/person/condition/personInfo";
String host = "https://" + project.getArtemisConfigHost();
JSONObject jo = new JSONObject();
jo.put("paramName", "personId");
jo.put("paramValue", Collections.singletonList(uniqueId));
String rs = doPost(host, path, jo.toJSONString(), null, project.getArtemisConfigAppKey(), project.getArtemisConfigAppSecret());
JSONObject joData = getJsonObjectData(rs);
Integer total = joData.getInteger("total");
if (Objects.equals(total, 1)) {
JSONArray jsonArray = joData.getJSONArray("list");
for (int i = 0; i < jsonArray.size(); i++) {
return jsonArray.getJSONObject(i);
}
}
return null;
}
/**
* 获取单个劳务人员信息,根据人员身份证
*
* @param workerInfo
* @param project
* @return
*/
public static JSONObject getWorkerInfoByCertificateNo(WorkerInfo workerInfo, Project project) throws Exception {
final String artemisPath = "/artemis";
final String path = artemisPath + "/api/resource/v1/person/condition/personInfo";
String host = "https://" + project.getArtemisConfigHost();
JSONObject jo = new JSONObject();
jo.put("paramName", "certificateNo");
jo.put("paramValue", Collections.singletonList(String.valueOf(workerInfo.getIdCard())));
String rs = doPost(host, path, jo.toJSONString(), null, project.getArtemisConfigAppKey(), project.getArtemisConfigAppSecret());
JSONObject joData = getJsonObjectData(rs);
Integer total = joData.getInteger("total");
if (Objects.equals(total, 1)) {
JSONArray jsonArray = joData.getJSONArray("list");
for (int i = 0; i < jsonArray.size(); i++) {
return jsonArray.getJSONObject(i);
}
}
return null;
}
}