529 lines
27 KiB
Java
529 lines
27 KiB
Java
package com.zhgd.xmgl.call;
|
||
|
||
import cn.hutool.core.bean.BeanUtil;
|
||
import cn.hutool.core.date.DateUtil;
|
||
import com.alibaba.fastjson.JSONArray;
|
||
import com.alibaba.fastjson.JSONObject;
|
||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||
import com.google.gson.JsonArray;
|
||
import com.google.gson.JsonObject;
|
||
import com.zhgd.jeecg.common.api.vo.Result;
|
||
import com.zhgd.xmgl.base.HikvisionCarInfo;
|
||
import com.zhgd.xmgl.base.HikvisionEventsPictureRq;
|
||
import com.zhgd.xmgl.base.HikvisionOrganization;
|
||
import com.zhgd.xmgl.base.SubscribeEventQo;
|
||
import com.zhgd.xmgl.modules.car.entity.CarInfo;
|
||
import com.zhgd.xmgl.modules.car.entity.CarPassRecord;
|
||
import com.zhgd.xmgl.modules.car.mapper.CarPassRecordMapper;
|
||
import com.zhgd.xmgl.modules.project.entity.Project;
|
||
import com.zhgd.xmgl.modules.project.mapper.ProjectMapper;
|
||
import com.zhgd.xmgl.modules.worker.entity.DepartmentInfo;
|
||
import com.zhgd.xmgl.modules.worker.entity.EnterpriseInfo;
|
||
import com.zhgd.xmgl.modules.worker.entity.TeamInfo;
|
||
import com.zhgd.xmgl.modules.worker.entity.WorkerInfo;
|
||
import com.zhgd.xmgl.modules.worker.mapper.WorkerInfoMapper;
|
||
import com.zhgd.xmgl.modules.worker.service.IWorkerAttendanceService;
|
||
import com.zhgd.xmgl.util.Base64Util;
|
||
import com.zhgd.xmgl.util.HikvisionUtil;
|
||
import com.zhgd.xmgl.util.PathUtil;
|
||
import io.swagger.annotations.ApiOperation;
|
||
import lombok.extern.slf4j.Slf4j;
|
||
import org.apache.commons.lang3.StringUtils;
|
||
import org.springframework.beans.factory.annotation.Autowired;
|
||
import org.springframework.beans.factory.annotation.Value;
|
||
import org.springframework.context.annotation.Lazy;
|
||
import org.springframework.web.bind.annotation.PostMapping;
|
||
import org.springframework.web.bind.annotation.RequestBody;
|
||
import org.springframework.web.bind.annotation.RequestMapping;
|
||
import org.springframework.web.bind.annotation.RestController;
|
||
import springfox.documentation.annotations.ApiIgnore;
|
||
|
||
import java.util.ArrayList;
|
||
import java.util.Arrays;
|
||
import java.util.HashMap;
|
||
import java.util.Objects;
|
||
|
||
@Slf4j
|
||
@RestController
|
||
@RequestMapping("/xmgl/hikvision")
|
||
public class HikvisionCall {
|
||
@Value("${upload.image.url.prefix:}")
|
||
private String imageUrlPrefix;
|
||
@Autowired
|
||
@Lazy
|
||
private ProjectMapper projectMapper;
|
||
@Autowired
|
||
@Lazy
|
||
private IWorkerAttendanceService workerAttendanceService;
|
||
@Autowired
|
||
@Lazy
|
||
private WorkerInfoMapper workerInfoMapper;
|
||
@Autowired
|
||
@Lazy
|
||
private CarPassRecordMapper carPassRecordMapper;
|
||
|
||
public void addWorkerForHikvision(WorkerInfo workerInfo) {
|
||
Project project = projectMapper.selectOne(new LambdaQueryWrapper<Project>().eq(Project::getProjectSn, workerInfo.getProjectSn()));
|
||
if (project == null || !Objects.equals(project.getSyncHikvision(), 1)) {
|
||
return;
|
||
}
|
||
final String ARTEMIS_PATH = "/artemis";
|
||
final String path = ARTEMIS_PATH + "/api/resource/v2/person/single/add";
|
||
String host = "https://" + project.getArtemisConfigHost();
|
||
String body = getWorkerJson(workerInfo);
|
||
HikvisionUtil.doPost(host, path, body, null, project.getArtemisConfigAppKey(), project.getArtemisConfigAppSecret());
|
||
}
|
||
|
||
private String getWorkerJson(WorkerInfo workerInfo) {
|
||
JSONObject jsonBody = new JSONObject();
|
||
jsonBody.put("personId", workerInfo.getId());
|
||
jsonBody.put("personName", workerInfo.getWorkerName());
|
||
jsonBody.put("gender", workerInfo.getSex());
|
||
jsonBody.put("orgIndexCode", getOrgIndexCode(workerInfo));
|
||
jsonBody.put("birthday", workerInfo.getBirthday());
|
||
jsonBody.put("phoneNo", workerInfo.getPhoneNumber());
|
||
jsonBody.put("email", workerInfo.getPersonMail());
|
||
jsonBody.put("certificateType", "111");
|
||
jsonBody.put("certificateNo", workerInfo.getIdCard());
|
||
jsonBody.put("jobNo", workerInfo.getPersonSn());
|
||
ArrayList<HashMap<String, String>> faceList = new ArrayList<>();
|
||
HashMap<String, String> faceMap = new HashMap<>();
|
||
faceMap.put("faceData", Base64Util.convertFileToBase64(PathUtil.reviseSlash(imageUrlPrefix + "/" + workerInfo.getFieldAcquisitionUrl())));
|
||
faceList.add(faceMap);
|
||
jsonBody.put("faces", faceList);
|
||
String body = jsonBody.toJSONString();
|
||
return body;
|
||
}
|
||
|
||
private String getOrgIndexCode(WorkerInfo workerInfo) {
|
||
if (workerInfo == null) {
|
||
return null;
|
||
}
|
||
if (Objects.equals(workerInfo.getPersonType(), 1)) {
|
||
return String.valueOf(workerInfo.getTeamId());
|
||
} else if (Objects.equals(workerInfo.getPersonType(), 2)) {
|
||
return String.valueOf(workerInfo.getDepartmentId());
|
||
} else if (Objects.equals(workerInfo.getPersonType(), 3)) {
|
||
return String.valueOf(workerInfo.getProjectSn());
|
||
}
|
||
return null;
|
||
}
|
||
|
||
|
||
public void editWorkerForHikvision(WorkerInfo workerInfo) {
|
||
Project project = projectMapper.selectOne(new LambdaQueryWrapper<Project>().eq(Project::getProjectSn, workerInfo.getProjectSn()));
|
||
if (project == null || !Objects.equals(project.getSyncHikvision(), 1)) {
|
||
return;
|
||
}
|
||
final String ARTEMIS_PATH = "/artemis";
|
||
final String path = ARTEMIS_PATH + "/api/resource/v1/person/single/update";
|
||
String host = "https://" + project.getArtemisConfigHost();
|
||
String body = getWorkerJson(workerInfo);
|
||
HikvisionUtil.doPost(host, path, body, null, project.getArtemisConfigAppKey(), project.getArtemisConfigAppSecret());
|
||
}
|
||
|
||
|
||
public void deleteWorkerForHikvision(WorkerInfo workerInfo) {
|
||
Project project = projectMapper.selectOne(new LambdaQueryWrapper<Project>().eq(Project::getProjectSn, workerInfo.getProjectSn()));
|
||
if (project == null || !Objects.equals(project.getSyncHikvision(), 1)) {
|
||
return;
|
||
}
|
||
final String ARTEMIS_PATH = "/artemis";
|
||
final String path = ARTEMIS_PATH + "/api/resource/v1/person/batch/delete";
|
||
String host = "https://" + project.getArtemisConfigHost();
|
||
JSONObject jsonBody = new JSONObject();
|
||
jsonBody.put("personIds", Arrays.asList(workerInfo.getId()));
|
||
String body = jsonBody.toJSONString();
|
||
HikvisionUtil.doPost(host, path, body, null, project.getArtemisConfigAppKey(), project.getArtemisConfigAppSecret());
|
||
}
|
||
|
||
public void addCarInfoForHikvision(CarInfo carInfo) {
|
||
Project project = projectMapper.selectOne(new LambdaQueryWrapper<Project>().eq(Project::getProjectSn, carInfo.getProjectSn()));
|
||
if (project == null || !Objects.equals(project.getSyncHikvision(), 1)) {
|
||
return;
|
||
}
|
||
final String ARTEMIS_PATH = "/artemis";
|
||
final String path = ARTEMIS_PATH + "/api/resource/v1/vehicle/batch/add";
|
||
String host = "https://" + project.getArtemisConfigHost();
|
||
HikvisionCarInfo hikvisionCarInfo = getHikvisionCarInfo(carInfo);
|
||
JsonArray array = new JsonArray();
|
||
array.add(BeanUtil.toBean(hikvisionCarInfo, JsonObject.class));
|
||
String body = array.toString();
|
||
HikvisionUtil.doPost(host, path, body, null, project.getArtemisConfigAppKey(), project.getArtemisConfigAppSecret());
|
||
}
|
||
|
||
private HikvisionCarInfo getHikvisionCarInfo(CarInfo carInfo) {
|
||
HikvisionCarInfo hikvisionCarInfo = new HikvisionCarInfo();
|
||
hikvisionCarInfo.setClientId(carInfo.getId());
|
||
hikvisionCarInfo.setPlateNo(carInfo.getCarNumber());
|
||
hikvisionCarInfo.setPersonId(carInfo.getDriverName());
|
||
hikvisionCarInfo.setPlateType(null);
|
||
hikvisionCarInfo.setPlateColor(null);
|
||
hikvisionCarInfo.setVehicleType(null);
|
||
hikvisionCarInfo.setVehicleColor(getVehicleColor(carInfo.getCarColor()));
|
||
hikvisionCarInfo.setDescription(null);
|
||
return hikvisionCarInfo;
|
||
}
|
||
|
||
private String getVehicleColor(String carColor) {
|
||
if (StringUtils.isBlank(carColor)) {
|
||
return null;
|
||
}
|
||
switch (carColor) {
|
||
case "其他颜色":
|
||
return "0";
|
||
case "白色":
|
||
return "1";
|
||
case "银色":
|
||
return "2";
|
||
case "灰色":
|
||
return "3";
|
||
case "黑色":
|
||
return "4";
|
||
case "红色":
|
||
return "5";
|
||
case "深蓝色":
|
||
return "6";
|
||
case "蓝色":
|
||
return "7";
|
||
case "黄色":
|
||
return "8";
|
||
case "绿色":
|
||
return "9";
|
||
case "棕色":
|
||
return "10";
|
||
case "粉色":
|
||
return "11";
|
||
case "紫色":
|
||
return "12";
|
||
case "深灰":
|
||
return "13";
|
||
case "杏色":
|
||
return "14";
|
||
case "未识别的车辆颜色":
|
||
return "255";
|
||
default:
|
||
return null;
|
||
}
|
||
}
|
||
|
||
public void editCarInfoForHikvision(CarInfo carInfo) {
|
||
Project project = projectMapper.selectOne(new LambdaQueryWrapper<Project>().eq(Project::getProjectSn, carInfo.getProjectSn()));
|
||
if (project == null || !Objects.equals(project.getSyncHikvision(), 1)) {
|
||
return;
|
||
}
|
||
final String ARTEMIS_PATH = "/artemis";
|
||
final String path = ARTEMIS_PATH + "/api/resource/v1/vehicle/single/update";
|
||
String host = "https://" + project.getArtemisConfigHost();
|
||
HikvisionCarInfo hikvisionCarInfo = getHikvisionCarInfo(carInfo);
|
||
JsonArray array = new JsonArray();
|
||
array.add(BeanUtil.toBean(hikvisionCarInfo, JsonObject.class));
|
||
String body = array.toString();
|
||
HikvisionUtil.doPost(host, path, body, null, project.getArtemisConfigAppKey(), project.getArtemisConfigAppSecret());
|
||
}
|
||
|
||
public void deleteCarInfoForHikvision(CarInfo carInfo) {
|
||
Project project = projectMapper.selectOne(new LambdaQueryWrapper<Project>().eq(Project::getProjectSn, carInfo.getProjectSn()));
|
||
if (project == null || !Objects.equals(project.getSyncHikvision(), 1)) {
|
||
return;
|
||
}
|
||
final String ARTEMIS_PATH = "/artemis";
|
||
final String path = ARTEMIS_PATH + "/api/resource/v1/vehicle/single/update";
|
||
String host = "https://" + project.getArtemisConfigHost();
|
||
JSONObject jo = new JSONObject();
|
||
JsonArray array = new JsonArray();
|
||
String body = array.toString();
|
||
array.add(carInfo.getId());
|
||
jo.put("vehicleIds", array);
|
||
HikvisionUtil.doPost(host, path, body, null, project.getArtemisConfigAppKey(), project.getArtemisConfigAppSecret());
|
||
}
|
||
|
||
@ApiOperation(value = "海康事件回调", notes = "海康事件回调", httpMethod = "POST")
|
||
@PostMapping(value = "/eventCallback")
|
||
public Result eventCallback(@ApiIgnore @RequestBody JSONObject jsonObject) {
|
||
String method = jsonObject.getString("method");
|
||
if (Objects.equals(method, "OnEventNotify")) {
|
||
JSONObject paramsJo = jsonObject.getJSONObject("params");
|
||
String ability = paramsJo.getString("ability");
|
||
//人员通行记录
|
||
if (Objects.equals(ability, "event_acs")) {
|
||
JSONArray eventsJa = paramsJo.getJSONArray("events");
|
||
if (eventsJa != null) {
|
||
for (int i = 0; i < eventsJa.size(); i++) {
|
||
JSONObject jo1 = eventsJa.getJSONObject(i);
|
||
JSONObject dataJo = jo1.getJSONObject("data");
|
||
JSONObject extEventIdentityCardInfoJo = dataJo.getJSONObject("ExtEventIdentityCardInfo");
|
||
String idNum = extEventIdentityCardInfoJo.getString("IdNum");
|
||
String extEventPictureURL = extEventIdentityCardInfoJo.getString("ExtEventPictureURL");
|
||
String svrIndexCode = extEventIdentityCardInfoJo.getString("svrIndexCode");
|
||
String extEventCardNo = dataJo.getString("ExtEventCardNo");
|
||
WorkerInfo workerInfo = workerInfoMapper.selectOne(new LambdaQueryWrapper<WorkerInfo>().eq(WorkerInfo::getIdCard, idNum)
|
||
.or().eq(WorkerInfo::getIdCard, extEventCardNo).last("limit 1"));
|
||
if (workerInfo == null) {
|
||
log.info("未找到该人员信息,idCard:{},extEventCardNo:{}", idNum, extEventCardNo);
|
||
return null;
|
||
}
|
||
Project project = projectMapper.selectOne(new LambdaQueryWrapper<Project>().eq(Project::getProjectSn, workerInfo.getProjectSn()));
|
||
if (project == null || !Objects.equals(project.getSyncHikvision(), 1)) {
|
||
log.info("未配置,idCard:{},extEventCardNo:{}", idNum, extEventCardNo);
|
||
return null;
|
||
}
|
||
HikvisionEventsPictureRq rq = new HikvisionEventsPictureRq();
|
||
rq.setPicUri(extEventPictureURL);
|
||
rq.setSvrIndexCode(svrIndexCode);
|
||
HashMap<String, Object> map = new HashMap<>();
|
||
map.put("passTime", null);
|
||
map.put("idCard", idNum);
|
||
map.put("attendanceNumber", extEventCardNo);
|
||
map.put("direction", getDirection(dataJo));
|
||
map.put("passType", 2);
|
||
map.put("projectCode", workerInfo.getProjectSn());
|
||
map.put("devCode", null);
|
||
map.put("faceUrl", getHikvisionEventsPicture(rq, project.getArtemisConfigHost(), project.getArtemisConfigAppKey(), project.getArtemisConfigAppSecret()));
|
||
workerAttendanceService.saveExternalPassRecord(map);
|
||
}
|
||
}
|
||
} else if (Objects.equals(ability, "event_mpc")) {
|
||
JSONArray eventsJa = paramsJo.getJSONArray("events");
|
||
if (eventsJa != null) {
|
||
for (int i = 0; i < eventsJa.size(); i++) {
|
||
JSONObject jo1 = eventsJa.getJSONObject(i);
|
||
JSONObject dataJo = jo1.getJSONObject("data");
|
||
CarPassRecord entity = new CarPassRecord();
|
||
entity.setCarNumber(dataJo.getString("plateNo"));
|
||
String imageIndexCode = dataJo.getString("imageIndexCode");
|
||
entity.setType(null);
|
||
entity.setPassTime(DateUtil.formatDateTime(DateUtil.parse(dataJo.getString("crossTime"))));
|
||
JSONObject picUrlJo = dataJo.getJSONObject("picUrl");
|
||
String vehiclePicUrl = picUrlJo.getString("vehiclePicUrl");
|
||
HikvisionEventsPictureRq rq = new HikvisionEventsPictureRq();
|
||
rq.setPicUri(vehiclePicUrl);
|
||
rq.setSvrIndexCode(imageIndexCode);
|
||
//entity.setImageUrl(getHikvisionEventsPicture(rq, project.getArtemisConfigHost(), project.getArtemisConfigAppKey(), project.getArtemisConfigAppSecret()));//todo
|
||
//entity.setPanoramaUrl();
|
||
//entity.setCarColor();
|
||
//entity.setLocation();
|
||
//entity.setProjectSn();
|
||
//entity.setCarLogo();
|
||
//entity.setColor();
|
||
//entity.setCameraId();
|
||
JSONObject personJo = dataJo.getJSONObject("person");
|
||
entity.setDriverData(personJo.getString("personName"));
|
||
entity.setIsOpen(1);
|
||
carPassRecordMapper.insert(entity);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
return Result.ok();
|
||
}
|
||
|
||
private Integer getDirection(JSONObject dataJo) {
|
||
Integer extEventInOut = dataJo.getInteger("ExtEventInOut");
|
||
if (Objects.equals(extEventInOut, 0)) {
|
||
return 2;
|
||
} else if (Objects.equals(extEventInOut, 1)) {
|
||
return 1;
|
||
} else {
|
||
return null;
|
||
}
|
||
}
|
||
|
||
public static String getHikvisionEventsPicture(HikvisionEventsPictureRq rq, String artemisConfigHost, String artemisConfigAppKey, String artemisConfigAppSecret) {//获取视频事件的图片
|
||
final String ARTEMIS_PATH = "/artemis";
|
||
final String path = ARTEMIS_PATH + "/api/video/v1/events/picture";
|
||
String host = "https://" + artemisConfigHost;
|
||
String body = JSONObject.toJSONString(rq);
|
||
String rs = HikvisionUtil.doPost(host, path, body, null, artemisConfigAppKey, artemisConfigAppSecret);
|
||
JSONObject rsJo = JSONObject.parseObject(rs);
|
||
Integer code = rsJo.getInteger("code");
|
||
if (code == 0) {
|
||
return rsJo.getJSONObject("data").getString("picUrl");
|
||
}
|
||
return null;
|
||
}
|
||
|
||
@ApiOperation(value = "按事件类型订阅事件", notes = "按事件类型订阅事件", httpMethod = "POST")
|
||
@PostMapping(value = "/subscribeEvent")
|
||
public Result subscribeEvent(@ApiIgnore @RequestBody SubscribeEventQo qo) {
|
||
final String ARTEMIS_PATH = "/artemis";
|
||
final String path = ARTEMIS_PATH + "/api/eventService/v1/eventSubscriptionByEventTypes";
|
||
String host = "https://" + qo.getArtemisConfigHost();
|
||
JSONObject jo = new JSONObject();
|
||
String rs = HikvisionUtil.doPost(host, path, jo.toJSONString(), null, qo.getArtemisConfigAppKey(), qo.getArtemisConfigAppSecret());
|
||
return Result.ok();
|
||
}
|
||
|
||
public void addEnterpriseInfoForHikvision(EnterpriseInfo enterpriseInfo) {
|
||
Project project = projectMapper.selectOne(new LambdaQueryWrapper<Project>().eq(Project::getProjectSn, enterpriseInfo.getProjectSn()));
|
||
if (project == null || !Objects.equals(project.getSyncHikvision(), 1)) {
|
||
return;
|
||
}
|
||
final String ARTEMIS_PATH = "/artemis";
|
||
final String path = ARTEMIS_PATH + "/api/resource/v1/org/batch/add";
|
||
String host = "https://" + project.getArtemisConfigHost();
|
||
HikvisionOrganization hikvisionOrganization = getHikvisionOrganization(enterpriseInfo);
|
||
JsonArray array = new JsonArray();
|
||
array.add(BeanUtil.toBean(hikvisionOrganization, JsonObject.class));
|
||
String body = array.toString();
|
||
HikvisionUtil.doPost(host, path, body, null, project.getArtemisConfigAppKey(), project.getArtemisConfigAppSecret());
|
||
}
|
||
|
||
private HikvisionOrganization getHikvisionOrganization(EnterpriseInfo enterpriseInfo) {
|
||
HikvisionOrganization hikvisionOrganization = new HikvisionOrganization();
|
||
hikvisionOrganization.setClientId(null);
|
||
hikvisionOrganization.setOrgIndexCode(String.valueOf(enterpriseInfo.getId()));
|
||
hikvisionOrganization.setOrgName(enterpriseInfo.getEnterpriseName());
|
||
hikvisionOrganization.setParentIndexCode(enterpriseInfo.getProjectSn());
|
||
return hikvisionOrganization;
|
||
}
|
||
|
||
public void editEnterpriseInfoForHikvision(EnterpriseInfo enterpriseInfo) {
|
||
Project project = projectMapper.selectOne(new LambdaQueryWrapper<Project>().eq(Project::getProjectSn, enterpriseInfo.getProjectSn()));
|
||
if (project == null || !Objects.equals(project.getSyncHikvision(), 1)) {
|
||
return;
|
||
}
|
||
final String ARTEMIS_PATH = "/artemis";
|
||
final String path = ARTEMIS_PATH + "/api/resource/v1/org/single/update";
|
||
String host = "https://" + project.getArtemisConfigHost();
|
||
HikvisionOrganization hikvisionOrganization = getHikvisionOrganization(enterpriseInfo);
|
||
HikvisionUtil.doPost(host, path, JSONArray.toJSONString(hikvisionOrganization), null, project.getArtemisConfigAppKey(), project.getArtemisConfigAppSecret());
|
||
}
|
||
|
||
|
||
public void deleteEnterpriseInfoForHikvision(String enterpriseInfo, String projectSn) {
|
||
Project project = projectMapper.selectOne(new LambdaQueryWrapper<Project>().eq(Project::getProjectSn, projectSn));
|
||
if (project == null || !Objects.equals(project.getSyncHikvision(), 1)) {
|
||
return;
|
||
}
|
||
final String ARTEMIS_PATH = "/artemis";
|
||
final String path = ARTEMIS_PATH + "/api/resource/v1/org/batch/delete";
|
||
String host = "https://" + project.getArtemisConfigHost();
|
||
JSONObject jo = new JSONObject();
|
||
jo.put("indexCodes", Arrays.asList(enterpriseInfo));
|
||
HikvisionUtil.doPost(host, path, jo.toJSONString(), null, project.getArtemisConfigAppKey(), project.getArtemisConfigAppSecret());
|
||
|
||
}
|
||
|
||
public void addTeamInfoForHikvision(TeamInfo teamInfo) {
|
||
Project project = projectMapper.selectOne(new LambdaQueryWrapper<Project>().eq(Project::getProjectSn, teamInfo.getProjectSn()));
|
||
if (project == null || !Objects.equals(project.getSyncHikvision(), 1)) {
|
||
return;
|
||
}
|
||
final String ARTEMIS_PATH = "/artemis";
|
||
final String path = ARTEMIS_PATH + "/api/resource/v1/org/batch/add";
|
||
String host = "https://" + project.getArtemisConfigHost();
|
||
HikvisionOrganization hikvisionOrganization = getHikvisionOrganization(teamInfo);
|
||
JsonArray array = new JsonArray();
|
||
array.add(BeanUtil.toBean(hikvisionOrganization, JsonObject.class));
|
||
String body = array.toString();
|
||
HikvisionUtil.doPost(host, path, body, null, project.getArtemisConfigAppKey(), project.getArtemisConfigAppSecret());
|
||
}
|
||
|
||
private HikvisionOrganization getHikvisionOrganization(TeamInfo teamInfo) {
|
||
HikvisionOrganization hikvisionOrganization = new HikvisionOrganization();
|
||
hikvisionOrganization.setClientId(null);
|
||
hikvisionOrganization.setOrgIndexCode(String.valueOf(teamInfo.getId()));
|
||
hikvisionOrganization.setOrgName(teamInfo.getTeamName());
|
||
hikvisionOrganization.setParentIndexCode(String.valueOf(teamInfo.getEnterpriseId()));
|
||
return hikvisionOrganization;
|
||
}
|
||
|
||
public void editTeamInfoForHikvision(TeamInfo teamInfo) {
|
||
Project project = projectMapper.selectOne(new LambdaQueryWrapper<Project>().eq(Project::getProjectSn, teamInfo.getProjectSn()));
|
||
if (project == null || !Objects.equals(project.getSyncHikvision(), 1)) {
|
||
return;
|
||
}
|
||
final String ARTEMIS_PATH = "/artemis";
|
||
final String path = ARTEMIS_PATH + "/api/resource/v1/org/single/update";
|
||
String host = "https://" + project.getArtemisConfigHost();
|
||
HikvisionOrganization hikvisionOrganization = getHikvisionOrganization(teamInfo);
|
||
HikvisionUtil.doPost(host, path, JSONArray.toJSONString(hikvisionOrganization), null, project.getArtemisConfigAppKey(), project.getArtemisConfigAppSecret());
|
||
}
|
||
|
||
public void deleteTeamInfoForHikvision(TeamInfo teamInfo) {
|
||
Project project = projectMapper.selectOne(new LambdaQueryWrapper<Project>().eq(Project::getProjectSn, teamInfo.getProjectSn()));
|
||
if (project == null || !Objects.equals(project.getSyncHikvision(), 1)) {
|
||
return;
|
||
}
|
||
final String ARTEMIS_PATH = "/artemis";
|
||
final String path = ARTEMIS_PATH + "/api/resource/v1/org/batch/delete";
|
||
String host = "https://" + project.getArtemisConfigHost();
|
||
JSONObject jo = new JSONObject();
|
||
jo.put("indexCodes", Arrays.asList(teamInfo.getId()));
|
||
HikvisionUtil.doPost(host, path, jo.toJSONString(), null, project.getArtemisConfigAppKey(), project.getArtemisConfigAppSecret());
|
||
}
|
||
|
||
public void addDepartmentInfoForHikvision(DepartmentInfo departmentInfo) {
|
||
Project project = projectMapper.selectOne(new LambdaQueryWrapper<Project>().eq(Project::getProjectSn, departmentInfo.getProjectSn()));
|
||
if (project == null || !Objects.equals(project.getSyncHikvision(), 1)) {
|
||
return;
|
||
}
|
||
final String ARTEMIS_PATH = "/artemis";
|
||
final String path = ARTEMIS_PATH + "/api/resource/v1/org/batch/add";
|
||
String host = "https://" + project.getArtemisConfigHost();
|
||
HikvisionOrganization hikvisionOrganization = getHikvisionOrganization(departmentInfo);
|
||
JsonArray array = new JsonArray();
|
||
array.add(BeanUtil.toBean(hikvisionOrganization, JsonObject.class));
|
||
String body = array.toString();
|
||
HikvisionUtil.doPost(host, path, body, null, project.getArtemisConfigAppKey(), project.getArtemisConfigAppSecret());
|
||
}
|
||
|
||
private HikvisionOrganization getHikvisionOrganization(DepartmentInfo departmentInfo) {
|
||
HikvisionOrganization hikvisionOrganization = new HikvisionOrganization();
|
||
hikvisionOrganization.setClientId(null);
|
||
hikvisionOrganization.setOrgIndexCode(String.valueOf(departmentInfo.getId()));
|
||
hikvisionOrganization.setOrgName(departmentInfo.getDepartmentName());
|
||
hikvisionOrganization.setParentIndexCode(String.valueOf(departmentInfo.getEnterpriseId()));
|
||
return hikvisionOrganization;
|
||
}
|
||
|
||
public void editDepartmentInfoForHikvision(DepartmentInfo departmentInfo) {
|
||
Project project = projectMapper.selectOne(new LambdaQueryWrapper<Project>().eq(Project::getProjectSn, departmentInfo.getProjectSn()));
|
||
if (project == null || !Objects.equals(project.getSyncHikvision(), 1)) {
|
||
return;
|
||
}
|
||
final String ARTEMIS_PATH = "/artemis";
|
||
final String path = ARTEMIS_PATH + "/api/resource/v1/org/single/update";
|
||
String host = "https://" + project.getArtemisConfigHost();
|
||
HikvisionOrganization hikvisionOrganization = getHikvisionOrganization(departmentInfo);
|
||
HikvisionUtil.doPost(host, path, JSONArray.toJSONString(hikvisionOrganization), null, project.getArtemisConfigAppKey(), project.getArtemisConfigAppSecret());
|
||
}
|
||
|
||
public void deleteDepartmentInfoForHikvision(DepartmentInfo departmentInfo) {
|
||
Project project = projectMapper.selectOne(new LambdaQueryWrapper<Project>().eq(Project::getProjectSn, departmentInfo.getProjectSn()));
|
||
if (project == null || !Objects.equals(project.getSyncHikvision(), 1)) {
|
||
return;
|
||
}
|
||
final String ARTEMIS_PATH = "/artemis";
|
||
final String path = ARTEMIS_PATH + "/api/resource/v1/org/batch/delete";
|
||
String host = "https://" + project.getArtemisConfigHost();
|
||
JSONObject jo = new JSONObject();
|
||
jo.put("indexCodes", Arrays.asList(departmentInfo.getId()));
|
||
HikvisionUtil.doPost(host, path, jo.toJSONString(), null, project.getArtemisConfigAppKey(), project.getArtemisConfigAppSecret());
|
||
}
|
||
|
||
public void editProjectForHikvision(Project project) {
|
||
if (project == null || !Objects.equals(project.getSyncHikvision(), 1)) {
|
||
return;
|
||
}
|
||
final String ARTEMIS_PATH = "/artemis";
|
||
final String path = ARTEMIS_PATH + "/api/resource/v1/org/batch/add";
|
||
String host = "https://" + project.getArtemisConfigHost();
|
||
HikvisionOrganization hikvisionOrganization = getHikvisionOrganization(project);
|
||
JsonArray array = new JsonArray();
|
||
array.add(BeanUtil.toBean(hikvisionOrganization, JsonObject.class));
|
||
String body = array.toString();
|
||
HikvisionUtil.doPost(host, path, body, null, project.getArtemisConfigAppKey(), project.getArtemisConfigAppSecret());
|
||
}
|
||
|
||
private HikvisionOrganization getHikvisionOrganization(Project project) {
|
||
HikvisionOrganization hikvisionOrganization = new HikvisionOrganization();
|
||
hikvisionOrganization.setClientId(null);
|
||
hikvisionOrganization.setOrgIndexCode(project.getProjectSn());
|
||
hikvisionOrganization.setOrgName(project.getProjectName());
|
||
hikvisionOrganization.setParentIndexCode(null);
|
||
return hikvisionOrganization;
|
||
}
|
||
}
|