102 lines
4.8 KiB
Java
102 lines
4.8 KiB
Java
package com.zhgd.xmgl.util;
|
||
|
||
import cn.hutool.http.HttpUtil;
|
||
import cn.hutool.json.JSONObject;
|
||
import com.zhgd.xmgl.modules.project.entity.ProjectUfaceConfig;
|
||
import com.zhgd.xmgl.modules.worker.entity.UfaceDev;
|
||
import com.zhgd.xmgl.modules.worker.entity.WorkerInfo;
|
||
import lombok.extern.slf4j.Slf4j;
|
||
import org.apache.commons.lang3.StringUtils;
|
||
|
||
import java.util.HashMap;
|
||
import java.util.Map;
|
||
|
||
/**
|
||
* @program: wisdomSite
|
||
* @description: 佳信捷新人脸设备
|
||
* @author: Mr.Peng
|
||
* @create: 2021-01-20 11:24
|
||
**/
|
||
@Slf4j
|
||
public class JxjNewUfaceDevUtil {
|
||
|
||
public static void addUfaceDev(UfaceDev ufaceDev, ProjectUfaceConfig projectUfaceConfig){
|
||
JSONObject jsonObject=new JSONObject();
|
||
jsonObject.put("deviceSn",ufaceDev.getDevSn());
|
||
jsonObject.put("deviceName",ufaceDev.getDevName());
|
||
jsonObject.put("projectId",projectUfaceConfig.getAppId());
|
||
log.info("----添加新JXJ设备URL:"+projectUfaceConfig.getServiceUrl()+"/api/device/addDevice");
|
||
log.info("----添加新JXJ设备数据:"+jsonObject.toString());
|
||
String result=HttpUtil.post(projectUfaceConfig.getServiceUrl()+"/api/device/addDevice",jsonObject.toString());
|
||
log.info("----添加新JXJ设备结果:"+result);
|
||
}
|
||
public static void deleteUfaceDev(UfaceDev ufaceDev, ProjectUfaceConfig projectUfaceConfig){
|
||
JSONObject jsonObject=new JSONObject();
|
||
jsonObject.put("deviceSn",ufaceDev.getDevSn());
|
||
jsonObject.put("projectId",projectUfaceConfig.getAppId());
|
||
String result=HttpUtil.post(projectUfaceConfig.getServiceUrl()+"/api/device/deleteDevice",jsonObject.toString());
|
||
log.info("-------删除新JXJ设备结果:"+result);
|
||
}
|
||
|
||
public static void addOrUpdatePerson(WorkerInfo workerInfo, ProjectUfaceConfig projectUfaceConfig,String basePath,String deviceKeys,Integer jxjDevImageType) {
|
||
JSONObject jsonObject = new JSONObject();
|
||
jsonObject.put("personName", workerInfo.getWorkerName());
|
||
jsonObject.put("projectId", projectUfaceConfig.getAppId());
|
||
jsonObject.put("personSn", workerInfo.getPersonSn());
|
||
if (StringUtils.isNotEmpty(workerInfo.getFieldAcquisitionUrl()) && workerInfo.getFieldAcquisitionUrl().startsWith("http")) {
|
||
if (jxjDevImageType == 2) {
|
||
jsonObject.put("image", workerInfo.getFieldAcquisitionUrl());
|
||
} else {
|
||
jsonObject.put("image", Base64Util.getFileToBase64(workerInfo.getFieldAcquisitionUrl()));
|
||
}
|
||
|
||
} else {
|
||
if (jxjDevImageType == 2) {
|
||
jsonObject.put("image", workerInfo.getFieldAcquisitionUrl());
|
||
} else {
|
||
jsonObject.put("image", Base64Util.getFileToBase64(basePath + "/" + workerInfo.getFieldAcquisitionUrl()));
|
||
}
|
||
}
|
||
jsonObject.put("idNum", workerInfo.getIdCard());
|
||
jsonObject.put("cardNum", workerInfo.getAttendanceNumber());
|
||
jsonObject.put("deviceKeys", deviceKeys);
|
||
String url = projectUfaceConfig.getServiceUrl() + "/api/person/addOrUpdatePerson";
|
||
String body = jsonObject.toString();
|
||
log.info("url:{},body:{}", url, body);
|
||
String result = null;
|
||
try {
|
||
result = HttpUtil.post(url, body);
|
||
} catch (Exception e) {
|
||
log.error("err:", e);
|
||
}
|
||
log.info("-----新JXJ设备添加或编辑人员结果:" + result);
|
||
}
|
||
|
||
public static void deleteWorkerInfo(WorkerInfo workerInfo, ProjectUfaceConfig projectUfaceConfig) {
|
||
JSONObject jsonObject=new JSONObject();
|
||
jsonObject.put("personSn",workerInfo.getPersonSn());
|
||
jsonObject.put("projectId",projectUfaceConfig.getAppId());
|
||
String result=HttpUtil.post(projectUfaceConfig.getServiceUrl()+"/api/person/deletePerson",jsonObject.toString());
|
||
log.info("--------新JXJ设备删除人员结果:"+result);
|
||
}
|
||
|
||
public static void retransmitPersonAttendanceData(String startTime,String endTime,String projectSn,String idcard,ProjectUfaceConfig projectUfaceConfig) {
|
||
Map<String,Object> data=new HashMap<>();
|
||
data.put("startTime",startTime);
|
||
data.put("endTime",endTime);
|
||
data.put("sn",projectSn);
|
||
data.put("idcard",idcard);
|
||
String result=HttpUtil.get(projectUfaceConfig.getServiceUrl()+"/xmgl/identificationRecord/retransmitPersonAttendanceData",data);
|
||
log.info("--------新JXJ设备重传结果:"+result);
|
||
}
|
||
|
||
public static void main(String[] args) {
|
||
JSONObject jsonObject=new JSONObject();
|
||
jsonObject.put("deviceSn","111111111");
|
||
jsonObject.put("deviceName","测试");
|
||
jsonObject.put("projectId","f6bed14ec8495e2b9988637fc2fd84c9");
|
||
String result=HttpUtil.post("http://120.236.247.200:20248/api/device/addDevice",jsonObject.toString());
|
||
log.info("添加设备结果:"+result);
|
||
}
|
||
}
|