|
@@ -92,7 +92,7 @@ public class LapiServiceImpl implements ILapiService {
|
|
|
throw new Exception("人员与设备绑定错误");
|
|
|
}
|
|
|
String base64Data = OSSUtil.downloadToBase64(personInfo.getFaceImageUrl());
|
|
|
- if (base64Data.length()>512*1024 || base64Data.length()<10*1024){
|
|
|
+ if (base64Data.length() > 512 * 1024 || base64Data.length() < 10 * 1024) {
|
|
|
throw new Exception("人员照片大小限定为10k~512k");
|
|
|
}
|
|
|
List<LapiMsgResult> lapiMsgResults = new ArrayList<>();
|
|
@@ -170,19 +170,32 @@ public class LapiServiceImpl implements ILapiService {
|
|
|
JSONObject response = LApiUtil.getResponse(dataJson);
|
|
|
List listData = response.getJSONArray("LibList");
|
|
|
if (listData.size() <= 0) {
|
|
|
- throw new Exception(deviceInfo.getAliasName()+"设备没有配置人脸库");
|
|
|
+ throw new Exception(deviceInfo.getAliasName() + "设备没有配置人脸库");
|
|
|
}
|
|
|
for (int i = 0; i < listData.size(); i++) {
|
|
|
JSONObject jsonObject1 = (JSONObject) JSONArray.toJSON(listData.get(i));
|
|
|
String name = jsonObject1.getString("Name");
|
|
|
if (StringUtils.isNotBlank(name) && companyName.equals(name)) {
|
|
|
faceDbId = jsonObject1.getString("ID");
|
|
|
+ break;
|
|
|
}
|
|
|
}
|
|
|
//人员所属的公司库不存在,保存到默认库
|
|
|
if (StringUtils.isBlank(faceDbId)) {
|
|
|
- throw new Exception(deviceInfo.getAliasName()+"设备中未配置"+companyName+"人脸库");
|
|
|
- // faceDbId = deviceInfo.getDefaultFaceLibraryId();
|
|
|
+ for (int i = 0; i < listData.size(); i++) {
|
|
|
+ JSONObject jsonObject1 = (JSONObject) JSONArray.toJSON(listData.get(i));
|
|
|
+ String name = jsonObject1.getString("Name");
|
|
|
+ if ("默认员工库".equals(name)) {
|
|
|
+ faceDbId = jsonObject1.getString("ID");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (StringUtils.isBlank(faceDbId)){
|
|
|
+ faceDbId = getDefaultLib(deviceInfo.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
return faceDbId;
|
|
|
}
|
|
@@ -255,7 +268,7 @@ public class LapiServiceImpl implements ILapiService {
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
- log.error(e.getMessage(),e);
|
|
|
+ log.error(e.getMessage(), e);
|
|
|
LapiMsgResult lapiMsgResult = new LapiMsgResult();
|
|
|
lapiMsgResult.setPersonName(personInfo.getName());
|
|
|
lapiMsgResult.setSuccess(false);
|
|
@@ -272,23 +285,23 @@ public class LapiServiceImpl implements ILapiService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<LapiMsgResult> deleteDevicePerson(Long id,String deviceIds) throws Exception {
|
|
|
- if (StringUtils.isBlank(deviceIds)){
|
|
|
+ public List<LapiMsgResult> deleteDevicePerson(Long id, String deviceIds) throws Exception {
|
|
|
+ if (StringUtils.isBlank(deviceIds)) {
|
|
|
throw new Exception("相关设备不能为空");
|
|
|
}
|
|
|
PersonInfo personInfo = personInfoService.get(id);
|
|
|
- if (personInfo == null){
|
|
|
+ if (personInfo == null) {
|
|
|
throw new Exception("人员信息不存在");
|
|
|
}
|
|
|
CompanyInfo companyInfo = companyInfoService.get(personInfo.getCompanyId());
|
|
|
- if (companyInfo == null){
|
|
|
+ if (companyInfo == null) {
|
|
|
throw new Exception("人员没有相应公司");
|
|
|
}
|
|
|
List<LapiMsgResult> lapiMsgResults = new ArrayList<>();
|
|
|
List<String> deviceIdList = Arrays.asList(deviceIds.split(","));
|
|
|
- for (String deviceId:deviceIdList ){
|
|
|
+ for (String deviceId : deviceIdList) {
|
|
|
DeviceInfo deviceInfo = deviceInfoService.get(deviceId);
|
|
|
- try{
|
|
|
+ try {
|
|
|
String faceDbId = getFaceDbId(deviceInfo, companyInfo.getName());
|
|
|
JSONObject jsonObject = LApiUtil.DeleteRequest(deviceInfo.getIpAddress() + ":" + deviceInfo.getPort() + LApiConstant.DELETEPERSON + faceDbId + "/People/" + personInfo.getId() + "?LastChange=" + new Date().getTime());
|
|
|
JSONObject dataJson = jsonObject.getJSONObject("Response");
|
|
@@ -300,8 +313,8 @@ public class LapiServiceImpl implements ILapiService {
|
|
|
lapiMsgResult.setAliasName(deviceInfo.getAliasName());
|
|
|
lapiMsgResults.add(lapiMsgResult);
|
|
|
}
|
|
|
- }catch (Exception e){
|
|
|
- log.error(e.getMessage(),e);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(e.getMessage(), e);
|
|
|
LapiMsgResult lapiMsgResult = new LapiMsgResult();
|
|
|
lapiMsgResult.setPersonName(personInfo.getName());
|
|
|
lapiMsgResult.setSuccess(false);
|
|
@@ -384,7 +397,7 @@ public class LapiServiceImpl implements ILapiService {
|
|
|
HashMap dataMap = new HashMap<>();
|
|
|
dataMap.put("CompanyId", companyInfoId);
|
|
|
dataMap.put("CompanyName", companyInfo.getName());
|
|
|
- dataMap.put("deviceId",deviceInfoId);
|
|
|
+ dataMap.put("deviceId", deviceInfoId);
|
|
|
dataMap.put("LibraryId", response.getString("ID"));
|
|
|
lapiResult.setData(dataMap);
|
|
|
|
|
@@ -404,6 +417,37 @@ public class LapiServiceImpl implements ILapiService {
|
|
|
return lapiResultList;
|
|
|
}
|
|
|
|
|
|
+ public String getDefaultLib(String deviceInfoId) throws Exception {
|
|
|
+
|
|
|
+ if (StringUtils.isBlank(deviceInfoId)) {
|
|
|
+ throw new Exception("请选择设备");
|
|
|
+ }
|
|
|
+ DeviceInfo deviceInfo = deviceInfoService.get(deviceInfoId);
|
|
|
+ try {
|
|
|
+ if (deviceInfo == null) {
|
|
|
+ throw new Exception("设备不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ HashMap map = new HashMap();
|
|
|
+ map.put("BelongIndex", "");
|
|
|
+ map.put("LastChange", new Date().getTime());
|
|
|
+ map.put("MemberNum", 0);
|
|
|
+ map.put("Name", "默认员工库");
|
|
|
+ map.put("Type", 3);
|
|
|
+ JSONObject jsonObject = LApiUtil.PostRequest(deviceInfo.getIpAddress() + ":" + deviceInfo.getPort() + LApiConstant.ADDLIBRARY, map);
|
|
|
+ JSONObject dataJson = jsonObject.getJSONObject("Response");
|
|
|
+ JSONObject response = LApiUtil.getResponse(dataJson);
|
|
|
+ return response.getString("ID");
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(e.getMessage());
|
|
|
+
|
|
|
+ }
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public LapiResult deleteCompanyLib(String deviceInfoId, String libraryId) throws Exception {
|
|
|
if (StringUtils.isBlank(deviceInfoId)) {
|