|
@@ -1,20 +1,35 @@
|
|
|
package com.jpsoft.smart.modules.lapi.service.impl;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.jpsoft.smart.modules.base.entity.CompanyInfo;
|
|
|
import com.jpsoft.smart.modules.base.entity.DeviceInfo;
|
|
|
+import com.jpsoft.smart.modules.base.entity.PersonDeviceRelation;
|
|
|
+import com.jpsoft.smart.modules.base.entity.PersonInfo;
|
|
|
+import com.jpsoft.smart.modules.base.service.CompanyInfoService;
|
|
|
import com.jpsoft.smart.modules.base.service.DeviceInfoService;
|
|
|
-import com.jpsoft.smart.modules.common.utils.IApiUtil;
|
|
|
+import com.jpsoft.smart.modules.base.service.PersonDeviceRelationService;
|
|
|
+import com.jpsoft.smart.modules.base.service.PersonInfoService;
|
|
|
+import com.jpsoft.smart.modules.common.utils.LApiUtil;
|
|
|
+import com.jpsoft.smart.modules.common.utils.OSSUtil;
|
|
|
import com.jpsoft.smart.modules.constant.LApiConstant;
|
|
|
import com.jpsoft.smart.modules.lapi.service.ILapiService;
|
|
|
+import com.jpsoft.smart.modules.lapi.vo.AddPersonVo;
|
|
|
+import com.jpsoft.smart.modules.lapi.vo.IdentificationVo;
|
|
|
+import com.jpsoft.smart.modules.lapi.vo.ImageVo;
|
|
|
+import com.jpsoft.smart.modules.lapi.vo.LapiMsgResult;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import java.util.UUID;
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* @author 墨鱼_mo
|
|
|
* @date 2020-3-15 9:37
|
|
|
*/
|
|
|
+@Slf4j
|
|
|
@Service
|
|
|
public class LapiServiceImpl implements ILapiService {
|
|
|
|
|
@@ -22,11 +37,20 @@ public class LapiServiceImpl implements ILapiService {
|
|
|
@Autowired
|
|
|
private DeviceInfoService deviceInfoService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private PersonInfoService personInfoService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PersonDeviceRelationService personDeviceRelationService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private CompanyInfoService companyInfoService;
|
|
|
+
|
|
|
@Override
|
|
|
public DeviceInfo findByIpAddressAndPort(String ipAddress, String port) throws Exception {
|
|
|
- JSONObject jsonObject = IApiUtil.GetRequest(ipAddress + ":" + port + LApiConstant.DEVICEBASICINFO);
|
|
|
+ JSONObject jsonObject = LApiUtil.GetRequest(ipAddress + ":" + port + LApiConstant.DEVICEBASICINFO);
|
|
|
JSONObject dataJson = jsonObject.getJSONObject("Response");
|
|
|
- JSONObject response = IApiUtil.getResponse(dataJson);
|
|
|
+ JSONObject response = LApiUtil.getResponse(dataJson);
|
|
|
DeviceInfo deviceInfo = new DeviceInfo();
|
|
|
deviceInfo.setId(UUID.randomUUID().toString());
|
|
|
deviceInfo.setIpAddress(ipAddress);
|
|
@@ -43,8 +67,122 @@ public class LapiServiceImpl implements ILapiService {
|
|
|
if (deviceInfo == null){
|
|
|
throw new Exception("设备未绑定");
|
|
|
}
|
|
|
- JSONObject jsonObject = IApiUtil.GetRequest(deviceInfo.getIpAddress()+":" + deviceInfo.getPort()+LApiConstant.KEEPALIVE);
|
|
|
+ JSONObject jsonObject = LApiUtil.GetRequest(deviceInfo.getIpAddress()+":" + deviceInfo.getPort()+LApiConstant.KEEPALIVE);
|
|
|
JSONObject dataJson = jsonObject.getJSONObject("Response");
|
|
|
return true;
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<LapiMsgResult> addPerson(Long id) throws Exception {
|
|
|
+
|
|
|
+ PersonInfo personInfo = personInfoService.get(id);
|
|
|
+ if (personInfo == null){
|
|
|
+ throw new Exception("人员不存在");
|
|
|
+ }
|
|
|
+ List<PersonDeviceRelation> listRelation = personDeviceRelationService.findByPersonId(id);
|
|
|
+ if (listRelation.size()<=0){
|
|
|
+ throw new Exception("人员未绑定设备");
|
|
|
+ }
|
|
|
+ CompanyInfo companyInfo = companyInfoService.get(personInfo.getCompanyId());
|
|
|
+ List<DeviceInfo> deviceList = new ArrayList<>();
|
|
|
+ for (PersonDeviceRelation personDeviceRelation:listRelation){
|
|
|
+ DeviceInfo deviceInfo = deviceInfoService.get(personDeviceRelation.getDeviceId());
|
|
|
+ if (deviceInfo!=null){
|
|
|
+ deviceList.add(deviceInfo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (deviceList.size()<=0){
|
|
|
+ throw new Exception("人员与设备绑定错误");
|
|
|
+ }
|
|
|
+ List<LapiMsgResult> lapiMsgResults = new ArrayList<>();
|
|
|
+ for (DeviceInfo deviceInfo : deviceList){
|
|
|
+ HashMap<String,Object> map = new HashMap<>();
|
|
|
+ map.put("Num",1L);
|
|
|
+ HashMap<String,Object> map1 = new HashMap<>();
|
|
|
+ map1.put("PersonID",personInfo.getId());
|
|
|
+ map1.put("LastChange",new Date().getTime());
|
|
|
+ map1.put("PersonCode",personInfo.getId().toString());
|
|
|
+ map1.put("PersonName",personInfo.getName());
|
|
|
+ map1.put("Remarks",companyInfo.getName());
|
|
|
+
|
|
|
+ //TimeTemplateNum 首字符必须大写
|
|
|
+ map1.put("TimeTemplateNum",0L);
|
|
|
+
|
|
|
+ map1.put("IdentificationNum",1L);
|
|
|
+ HashMap<String,Object> map2 = new HashMap<>();
|
|
|
+ List listMap2 = new ArrayList();
|
|
|
+ listMap2.add(map2);
|
|
|
+ map2.put("Type",0L);
|
|
|
+ map2.put("Number",personInfo.getIdCard());
|
|
|
+ map1.put("IdentificationList",listMap2);
|
|
|
+ map1.put("ImageNum",1L);
|
|
|
+
|
|
|
+ HashMap<String,Object> map3 = new HashMap<>();
|
|
|
+ map3.put("FaceID",personInfo.getId());
|
|
|
+ map3.put("Name",personInfo.getId()+".jpg");
|
|
|
+ map3.put("Size",OSSUtil.downloadToBase64(personInfo.getFaceImageUrl()).length());
|
|
|
+ map3.put("Data",OSSUtil.downloadToBase64(personInfo.getFaceImageUrl()));
|
|
|
+ List listMap3 = new ArrayList();
|
|
|
+ listMap3.add(map3);
|
|
|
+ map1.put("ImageList",listMap3);
|
|
|
+ List listMap1 = new ArrayList();
|
|
|
+ listMap1.add(map1);
|
|
|
+ map.put("PersonInfoList",listMap1);
|
|
|
+
|
|
|
+
|
|
|
+ try{
|
|
|
+ //获取人员人脸库id
|
|
|
+ String faceDbId = getFaceDbId(deviceInfo,companyInfo.getName());
|
|
|
+ JSONObject jsonObject = LApiUtil.PostRequest(deviceInfo.getIpAddress()+":"+deviceInfo.getPort()+LApiConstant.ADDPERSON+faceDbId+"/People",map);
|
|
|
+ JSONObject dataJson = jsonObject.getJSONObject("Response");
|
|
|
+ if (dataJson.getInteger("ResponseCode") ==0 && dataJson.getInteger("StatusCode") == 0){
|
|
|
+ LapiMsgResult lapiMsgResult = new LapiMsgResult();
|
|
|
+ lapiMsgResult.setPersonName(personInfo.getName());
|
|
|
+ lapiMsgResult.setMsg(true);
|
|
|
+ lapiMsgResult.setAliasName(deviceInfo.getAliasName());
|
|
|
+ lapiMsgResults.add(lapiMsgResult);
|
|
|
+ }
|
|
|
+ }catch (Exception e){
|
|
|
+
|
|
|
+ log.error(e.getMessage());
|
|
|
+ LapiMsgResult lapiMsgResult = new LapiMsgResult();
|
|
|
+ lapiMsgResult.setPersonName(personInfo.getName());
|
|
|
+ lapiMsgResult.setMsg(false);
|
|
|
+ lapiMsgResult.setAliasName(deviceInfo.getAliasName());
|
|
|
+ lapiMsgResults.add(lapiMsgResult);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ return lapiMsgResults;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String getFaceDbId(DeviceInfo deviceInfo, String companyName) throws Exception{
|
|
|
+ if (StringUtils.isBlank(companyName)){
|
|
|
+ throw new Exception("公司名称为空");
|
|
|
+ }
|
|
|
+ String faceDbId = "";
|
|
|
+ JSONObject jsonObject = LApiUtil.GetRequest(deviceInfo.getIpAddress()+":" + deviceInfo.getPort()+LApiConstant.GETFACEDB);
|
|
|
+ JSONObject dataJson = jsonObject.getJSONObject("Response");
|
|
|
+ JSONObject response = LApiUtil.getResponse(dataJson);
|
|
|
+ List listData = response.getJSONArray("LibList");
|
|
|
+ if (listData.size()<=0){
|
|
|
+ throw new Exception("设备没有配置人脸库");
|
|
|
+ }
|
|
|
+ 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");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //人员所属的公司库不存在,保存到默认库
|
|
|
+ if (StringUtils.isBlank(faceDbId)){
|
|
|
+ faceDbId = deviceInfo.getDefaultFaceLibraryId();
|
|
|
+ }
|
|
|
+ return faceDbId;
|
|
|
+ }
|
|
|
}
|