소스 검색

Merge remote-tracking branch 'origin/V1' into V1

yanliming 5 년 전
부모
커밋
e4fc7fa540
25개의 변경된 파일497개의 추가작업 그리고 52개의 파일을 삭제
  1. 2 0
      common/src/main/java/com/jpsoft/smart/modules/base/dao/DeviceInfoDAO.java
  2. 5 0
      common/src/main/java/com/jpsoft/smart/modules/base/dao/PersonDeviceRelationDAO.java
  3. 3 0
      common/src/main/java/com/jpsoft/smart/modules/base/entity/DeviceInfo.java
  4. 1 0
      common/src/main/java/com/jpsoft/smart/modules/base/service/DeviceInfoService.java
  5. 2 0
      common/src/main/java/com/jpsoft/smart/modules/base/service/PersonDeviceRelationService.java
  6. 13 6
      common/src/main/java/com/jpsoft/smart/modules/base/service/impl/DeviceInfoServiceImpl.java
  7. 2 2
      common/src/main/java/com/jpsoft/smart/modules/base/service/impl/PersonDeviceLogServiceImpl.java
  8. 12 6
      common/src/main/java/com/jpsoft/smart/modules/base/service/impl/PersonDeviceRelationServiceImpl.java
  9. 35 4
      common/src/main/java/com/jpsoft/smart/modules/common/utils/LApiUtil.java
  10. 37 0
      common/src/main/java/com/jpsoft/smart/modules/common/utils/OSSUtil.java
  11. 11 0
      common/src/main/java/com/jpsoft/smart/modules/constant/LApiConstant.java
  12. 20 0
      common/src/main/java/com/jpsoft/smart/modules/lapi/service/ILapiService.java
  13. 143 5
      common/src/main/java/com/jpsoft/smart/modules/lapi/service/impl/LapiServiceImpl.java
  14. 34 0
      common/src/main/java/com/jpsoft/smart/modules/lapi/vo/AddPersonVo.java
  15. 15 0
      common/src/main/java/com/jpsoft/smart/modules/lapi/vo/IdentificationVo.java
  16. 18 0
      common/src/main/java/com/jpsoft/smart/modules/lapi/vo/ImageVo.java
  17. 17 0
      common/src/main/java/com/jpsoft/smart/modules/lapi/vo/LapiMsgResult.java
  18. 14 5
      common/src/main/resources/mapper/base/DeviceInfo.xml
  19. 18 3
      common/src/main/resources/mapper/base/PersonDeviceRelation.xml
  20. 19 0
      lapi/src/main/java/com/jpsoft/smart/lapi/handler/HeartReportHandler.java
  21. 1 0
      lapi/src/main/java/com/jpsoft/smart/lapi/handler/ParseRequestHandler.java
  22. 7 4
      lapi/src/main/java/com/jpsoft/smart/lapi/handler/PersonVerificationHandler.java
  23. 16 0
      web/src/main/java/com/jpsoft/smart/modules/base/controller/CompanyInfoController.java
  24. 19 17
      web/src/main/java/com/jpsoft/smart/modules/base/controller/PersonInfoController.java
  25. 33 0
      web/src/test/java/com/jpsoft/smart/LApiTest.java

+ 2 - 0
common/src/main/java/com/jpsoft/smart/modules/base/dao/DeviceInfoDAO.java

@@ -16,4 +16,6 @@ public interface DeviceInfoDAO {
 	int delete(String id);
 	List<DeviceInfo> list();
 	List<DeviceInfo> search(Map<String, Object> searchParams, List<Sort> sortList);
+
+	DeviceInfo findByDeviceNo(String deviceNo);
 }

+ 5 - 0
common/src/main/java/com/jpsoft/smart/modules/base/dao/PersonDeviceRelationDAO.java

@@ -1,4 +1,5 @@
 package com.jpsoft.smart.modules.base.dao;
+import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
 import org.springframework.stereotype.Repository;
@@ -18,4 +19,8 @@ public interface PersonDeviceRelationDAO {
     List<PersonDeviceRelation> findByDeviceId(String deviceId);
     PersonDeviceRelation findByDeviceIdAndPersonId(String deviceId,Long personId);
 	List<PersonDeviceRelation> search(Map<String, Object> searchParams, List<Sort> sortList);
+
+//    List<PersonDeviceRelation>  findByPersonId(@Param("personId")Long personId);
+
+
 }

+ 3 - 0
common/src/main/java/com/jpsoft/smart/modules/base/entity/DeviceInfo.java

@@ -140,6 +140,9 @@ public class DeviceInfo {
 	@ApiModelProperty(value = "是否绑定人员(只做查询作用,不写入数据库)")
 	private Boolean isBindPerson;
 
+	@ApiModelProperty(value = "默认人脸库id")
+	private String defaultFaceLibraryId;
+
 	public String getIsOnlineN() {
 		if(isOnline!=null) {
 			if (isOnline) {

+ 1 - 0
common/src/main/java/com/jpsoft/smart/modules/base/service/DeviceInfoService.java

@@ -14,4 +14,5 @@ public interface DeviceInfoService {
 	int delete(String id);
 	List<DeviceInfo> list();
 	Page<DeviceInfo> pageSearch(Map<String, Object> searchParams, int pageNum, int pageSize,boolean count, List<Sort> sortList);
+	int updateByDeviceNo(String deviceNo,String ip);
 }

+ 2 - 0
common/src/main/java/com/jpsoft/smart/modules/base/service/PersonDeviceRelationService.java

@@ -17,4 +17,6 @@ public interface PersonDeviceRelationService {
 	List<PersonDeviceRelation> findByDeviceId(String deviceId);
 	PersonDeviceRelation findByDeviceIdAndPersonId(String deviceId,Long personId);
 	Page<PersonDeviceRelation> pageSearch(Map<String, Object> searchParams, int pageNum, int pageSize,boolean count, List<Sort> sortList);
+
+	//List<PersonDeviceRelation> findByPersonId(Long id);
 }

+ 13 - 6
common/src/main/java/com/jpsoft/smart/modules/base/service/impl/DeviceInfoServiceImpl.java

@@ -29,14 +29,14 @@ public class DeviceInfoServiceImpl implements DeviceInfoService {
 	public int insert(DeviceInfo model) {
 		// TODO Auto-generated method stub
 		//model.setId(UUID.randomUUID().toString());
-		
+
 		return deviceInfoDAO.insert(model);
 	}
 
 	@Override
 	public int update(DeviceInfo model) {
 		// TODO Auto-generated method stub
-		return deviceInfoDAO.update(model);		
+		return deviceInfoDAO.update(model);
 	}
 
 	@Override
@@ -49,22 +49,29 @@ public class DeviceInfoServiceImpl implements DeviceInfoService {
 	public boolean exist(String id) {
 		// TODO Auto-generated method stub
 		int count = deviceInfoDAO.exist(id);
-		
+
 		return count > 0 ? true : false;
 	}
-	
+
 	@Override
 	public List<DeviceInfo> list() {
 		// TODO Auto-generated method stub
 		return deviceInfoDAO.list();
 	}
-		
+
 	@Override
 	public Page<DeviceInfo> pageSearch(Map<String, Object> searchParams, int pageNumber, int pageSize,boolean count,List<Sort> sortList) {
         Page<DeviceInfo> page = PageHelper.startPage(pageNumber,pageSize,count).doSelectPage(()->{
             deviceInfoDAO.search(searchParams,sortList);
         });
-        
+
         return page;
 	}
+
+	@Override
+	public int updateByDeviceNo(String deviceNo, String ip) {
+		DeviceInfo deviceInfo= deviceInfoDAO.findByDeviceNo(deviceNo);
+
+		return 0;
+	}
 }

+ 2 - 2
common/src/main/java/com/jpsoft/smart/modules/base/service/impl/PersonDeviceLogServiceImpl.java

@@ -11,7 +11,7 @@ import com.jpsoft.smart.modules.base.service.PersonDeviceLogService;
 import com.jpsoft.smart.modules.common.dto.Sort;
 import com.jpsoft.smart.modules.common.utils.BASE64DecodedMultipartFile;
 import com.jpsoft.smart.modules.common.utils.Base64;
-import com.jpsoft.smart.modules.common.utils.IApiUtil;
+import com.jpsoft.smart.modules.common.utils.LApiUtil;
 import com.jpsoft.smart.modules.common.utils.OSSUtil;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -98,7 +98,7 @@ public class PersonDeviceLogServiceImpl implements PersonDeviceLogService {
         if (StringUtils.isNotBlank(libMatInfoListJson.getStr("MatchStatus"))){
             System.out.println();
             personDeviceLog.setMatchStatus(libMatInfoListJson.getInt("MatchStatus"));
-            personDeviceLog.setMatchMsg(IApiUtil.getMatchMsg(libMatInfoListJson.getInt("MatchStatus")));
+            personDeviceLog.setMatchMsg(LApiUtil.getMatchMsg(libMatInfoListJson.getInt("MatchStatus")));
             personDeviceLog.setMatchFaceId(libMatInfoListJson.getInt("MatchFaceID"));
         }else {
             personDeviceLog.setMatchStatus(0);

+ 12 - 6
common/src/main/java/com/jpsoft/smart/modules/base/service/impl/PersonDeviceRelationServiceImpl.java

@@ -29,14 +29,14 @@ public class PersonDeviceRelationServiceImpl implements PersonDeviceRelationServ
 	public int insert(PersonDeviceRelation model) {
 		// TODO Auto-generated method stub
 		//model.setId(UUID.randomUUID().toString());
-		
+
 		return personDeviceRelationDAO.insert(model);
 	}
 
 	@Override
 	public int update(PersonDeviceRelation model) {
 		// TODO Auto-generated method stub
-		return personDeviceRelationDAO.update(model);		
+		return personDeviceRelationDAO.update(model);
 	}
 
 	@Override
@@ -49,10 +49,10 @@ public class PersonDeviceRelationServiceImpl implements PersonDeviceRelationServ
 	public boolean exist(String id) {
 		// TODO Auto-generated method stub
 		int count = personDeviceRelationDAO.exist(id);
-		
+
 		return count > 0 ? true : false;
 	}
-	
+
 	@Override
 	public List<PersonDeviceRelation> list() {
 		// TODO Auto-generated method stub
@@ -75,13 +75,19 @@ public class PersonDeviceRelationServiceImpl implements PersonDeviceRelationServ
 	}
 
 
-		
+
 	@Override
 	public Page<PersonDeviceRelation> pageSearch(Map<String, Object> searchParams, int pageNumber, int pageSize,boolean count,List<Sort> sortList) {
         Page<PersonDeviceRelation> page = PageHelper.startPage(pageNumber,pageSize,count).doSelectPage(()->{
             personDeviceRelationDAO.search(searchParams,sortList);
         });
-        
+
         return page;
 	}
+
+//	@Override
+//	public List<PersonDeviceRelation> findByPersonId(Long id) {
+//
+//		return personDeviceRelationDAO.findByPersonId(id);
+//	}
 }

+ 35 - 4
common/src/main/java/com/jpsoft/smart/modules/common/utils/IApiUtil.java → common/src/main/java/com/jpsoft/smart/modules/common/utils/LApiUtil.java

@@ -1,10 +1,13 @@
 package com.jpsoft.smart.modules.common.utils;
 
 import cn.hutool.http.HttpRequest;
+import cn.hutool.http.HttpUtil;
+import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import org.springframework.stereotype.Component;
 import org.springframework.web.multipart.MultipartFile;
 
+import java.util.Date;
 import java.util.HashMap;
 
 /**
@@ -12,17 +15,18 @@ import java.util.HashMap;
  * @date 2020-3-14 16:43
  */
 @Component
-public class IApiUtil {
+public class LApiUtil {
 
 
-   /* public JSONObject PostRequest(String url){
+    public static JSONObject PostRequest(String url,HashMap map){
 
-        String body = HttpRequest.post(url).header("referer",referer).form(map).execute().body();
+
+        String body = HttpRequest.post(url).body(new JSONObject(map).toJSONString()).execute().body();
         JSONObject jsonbody = JSONObject.parseObject(body);
         return jsonbody;
 
 
-    }*/
+    }
 
     public static JSONObject GetRequest(String url) throws Exception{
 
@@ -33,6 +37,8 @@ public class IApiUtil {
 
     }
 
+
+
     public static JSONObject getResponse(JSONObject dataJson) throws Exception{
 
         if (dataJson.getInteger("ResponseCode") == 1){
@@ -101,6 +107,31 @@ public class IApiUtil {
         return matchMsg;
     }
 
+    public static Integer imageSize(String imageBase64Str){
+
+        //1.找到等号,把等号也去掉(=用来填充base64字符串长度用)
+        Integer equalIndex= imageBase64Str.indexOf("=");
+        if(imageBase64Str.indexOf("=")>0) {
+            imageBase64Str=imageBase64Str.substring(0, equalIndex);
+        }
+        //2.原来的字符流大小,单位为字节
+        Integer strLength=imageBase64Str.length();
+     //   System.out.println("imageBase64Str Length = "+strLength);
+        //3.计算后得到的文件流大小,单位为字节
+        Integer size=strLength-(strLength/8)*2;
+        return size;
+    }
+
+
+
+    public static void main(String[] args) {
+        Date date = new Date(1584321770000L);
+    //    Date date = new
+     //   Date date = new Date();
+      // long time = date.getTime();
+        System.out.println(date);
+    }
+
 
 
 }

+ 37 - 0
common/src/main/java/com/jpsoft/smart/modules/common/utils/OSSUtil.java

@@ -1,5 +1,6 @@
 package com.jpsoft.smart.modules.common.utils;
 
+import cn.hutool.core.codec.Base64Encoder;
 import cn.hutool.core.date.DateTime;
 import com.aliyun.oss.HttpMethod;
 import com.aliyun.oss.OSS;
@@ -92,6 +93,42 @@ public class OSSUtil {
 
         return result;
     }
+    public static String  downloadToBase64(String fileUrl){
+            ByteArrayOutputStream data = new ByteArrayOutputStream();;
+        try {
+       //     FileOutputStream output = new FileOutputStream();
+       //     OutputStream outputStream =null;
+
+
+
+            URL url = new URL(encodeFileName(fileUrl));
+        //    URLConnection conn = url.openConnection();
+        //    InputStream input = conn.getInputStream();
+
+            byte[] buffs = new byte[1024 * 10];
+            //创建连接
+            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
+            conn.setRequestMethod("GET");
+            conn.setConnectTimeout(5000);
+            InputStream input = conn.getInputStream();
+            //将内容读到内存中
+            int len = -1;
+            while ((len =input.read(buffs))!=-1){
+                data.write(buffs,0,len);
+            }
+            input.close();
+
+
+
+        } catch (Exception e) {
+
+            log.error(e.getMessage(),e);
+        }
+
+
+        return Base64Encoder.encode(data.toByteArray());
+    }
+
 
     public static void batchDownload(List<Map<String,Object>> fileList, OutputStream output){
         try{

+ 11 - 0
common/src/main/java/com/jpsoft/smart/modules/constant/LApiConstant.java

@@ -16,4 +16,15 @@ public class LApiConstant {
      */
     public static final String KEEPALIVE = "/LAPI/V1.0/System/KeepAlive";
 
+
+    /**
+     * 上传人脸接口url
+     */
+    public static final String ADDPERSON = "/LAPI/V1.0/PeopleLibraries/";
+
+    /**
+     * 获取人脸库url
+     */
+    public static final String GETFACEDB = "/LAPI/V1.0/PeopleLibraries/BasicInfo";
+
 }

+ 20 - 0
common/src/main/java/com/jpsoft/smart/modules/lapi/service/ILapiService.java

@@ -1,6 +1,10 @@
 package com.jpsoft.smart.modules.lapi.service;
 
 import com.jpsoft.smart.modules.base.entity.DeviceInfo;
+import com.jpsoft.smart.modules.base.entity.PersonInfo;
+import com.jpsoft.smart.modules.lapi.vo.LapiMsgResult;
+
+import java.util.List;
 
 /**
  * @author 墨鱼_mo
@@ -23,4 +27,20 @@ public interface ILapiService {
      * @return
      */
      Boolean keepAlive(String id) throws Exception;
+
+
+    /**
+     * 平台上传设备人脸信息
+     * @param id
+     * @return
+     * @throws Exception
+     */
+     List<LapiMsgResult> addPerson(Long id) throws Exception;
+
+    /**
+     * 根据公司名称获取人脸库
+     * @param companyName
+     * @return
+     */
+     String getFaceDbId(DeviceInfo deviceInfo, String companyName) throws Exception;
 }

+ 143 - 5
common/src/main/java/com/jpsoft/smart/modules/lapi/service/impl/LapiServiceImpl.java

@@ -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;
+    }
 }

+ 34 - 0
common/src/main/java/com/jpsoft/smart/modules/lapi/vo/AddPersonVo.java

@@ -0,0 +1,34 @@
+package com.jpsoft.smart.modules.lapi.vo;
+
+import lombok.Data;
+
+import java.util.List;
+
+/**
+ * @author 墨鱼_mo
+ * @date 2020-3-16 10:38
+ */
+@Data
+public class AddPersonVo {
+
+    private Long PersonID;
+
+    private Long LastChange;
+
+    private String  PersonCode;
+
+    private String PersonName;
+
+    private String Remarks;
+
+    private Long TimeTemplateNum;
+
+    private Long IdentificationNum;
+
+    private List<IdentificationVo> IdentificationList;
+
+    private Long ImageNum;
+
+    private List<ImageVo> ImageList;
+
+}

+ 15 - 0
common/src/main/java/com/jpsoft/smart/modules/lapi/vo/IdentificationVo.java

@@ -0,0 +1,15 @@
+package com.jpsoft.smart.modules.lapi.vo;
+
+import lombok.Data;
+
+/**
+ * @author 墨鱼_mo
+ * @date 2020-3-16 10:44
+ */
+@Data
+public class IdentificationVo {
+
+    private Long Type;
+
+    private String Number;
+}

+ 18 - 0
common/src/main/java/com/jpsoft/smart/modules/lapi/vo/ImageVo.java

@@ -0,0 +1,18 @@
+package com.jpsoft.smart.modules.lapi.vo;
+
+import lombok.Data;
+
+/**
+ * @author 墨鱼_mo
+ * @date 2020-3-16 10:46
+ */
+@Data
+public class ImageVo {
+    private Long FaceID;
+
+    private String Name;
+
+    private Long Size;
+
+    private String Data;
+}

+ 17 - 0
common/src/main/java/com/jpsoft/smart/modules/lapi/vo/LapiMsgResult.java

@@ -0,0 +1,17 @@
+package com.jpsoft.smart.modules.lapi.vo;
+
+import lombok.Data;
+
+/**
+ * @author 墨鱼_mo
+ * @date 2020-3-16 15:23
+ */
+@Data
+public class LapiMsgResult {
+
+    private String personName;
+
+    private String aliasName;
+
+    private boolean msg;
+}

+ 14 - 5
common/src/main/resources/mapper/base/DeviceInfo.xml

@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8" ?>
-<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" 
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <!-- namespace必须指向DAO接口 -->
 <mapper namespace="com.jpsoft.smart.modules.base.dao.DeviceInfoDAO">
@@ -22,6 +22,7 @@
 			<result property="createTime" column="create_time" />
 			<result property="updateBy" column="update_by" />
 			<result property="updateTime" column="update_time" />
+		    <result property="defaultFaceLibraryId" column="default_face_library_id" />
 			</resultMap>
 	<insert id="insert" parameterType="com.jpsoft.smart.modules.base.entity.DeviceInfo">
 	<!--
@@ -31,7 +32,7 @@
 	-->
 	<![CDATA[
 		insert into base_device_info
-	    (id_,header_,device_no,alias_name,address_,is_online,company_id,unlock_password,code_address,ip_address,port_,type_,is_auto_update,del_flag,create_by,create_time,update_by,update_time)
+	    (id_,header_,device_no,alias_name,address_,is_online,company_id,unlock_password,code_address,ip_address,port_,type_,is_auto_update,del_flag,create_by,create_time,update_by,update_time,default_face_library_id)
 		values
 		(
 #{id,jdbcType=VARCHAR}
@@ -52,6 +53,7 @@
 ,#{createTime,jdbcType= TIMESTAMP }
 ,#{updateBy,jdbcType=VARCHAR}
 ,#{updateTime,jdbcType= TIMESTAMP }
+,#{defaultFaceLibraryId,jdbcType=VARCHAR}
 		)
 	]]>
 	</insert>
@@ -112,16 +114,19 @@
 				<if test="updateTime!=null">
 		update_time=#{updateTime,jdbcType= TIMESTAMP },
 		</if>
+			<if test="defaultFaceLibraryId!=null">
+				default_face_library_id=#{defaultFaceLibraryId,jdbcType= VARCHAR },
+			</if>
 		</set>
 	where id_=#{id}
 	</update>
 	<select id="get" parameterType="string" resultMap="DeviceInfoMap">
-		select 
-id_, header_,device_no,alias_name,address_,is_online,company_id,unlock_password,code_address,ip_address,port_,type_,is_auto_update,del_flag,create_by,create_time,update_by,update_time		from base_device_info where id_=#{0}
+		select
+id_, header_,device_no,alias_name,address_,is_online,company_id,unlock_password,code_address,ip_address,port_,type_,is_auto_update,del_flag,create_by,create_time,update_by,update_time,default_face_library_id		from base_device_info where id_=#{0}
 	</select>
 	<select id="getByDeviceNo" parameterType="string" resultMap="DeviceInfoMap">
 		select
-id_, header_,device_no,alias_name,address_,is_online,company_id,unlock_password,code_address,ip_address,port_,type_,is_auto_update,del_flag,create_by,create_time,update_by,update_time		from base_device_info where device_no=#{0}
+id_, header_,device_no,alias_name,address_,is_online,company_id,unlock_password,code_address,ip_address,port_,type_,is_auto_update,del_flag,create_by,create_time,update_by,update_time,default_face_library_id		from base_device_info where device_no=#{0}
 	</select>
 	<select id="exist" parameterType="string" resultType="int">
 		select count(*) from base_device_info where id_=#{0} and  del_flag=false
@@ -152,4 +157,8 @@ id_, header_,device_no,alias_name,address_,is_online,company_id,unlock_password,
 	        ${sort.name} ${sort.order}
 	 	</foreach>
 	</select>
+	<select id="findByDeviceNo" parameterType="string" resultMap="DeviceInfoMap">
+			select * from base_device_info where device_no = #{0}
+	</select>
+
 </mapper>

+ 18 - 3
common/src/main/resources/mapper/base/PersonDeviceRelation.xml

@@ -1,9 +1,21 @@
 <?xml version="1.0" encoding="UTF-8" ?>
-<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" 
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <!-- namespace必须指向DAO接口 -->
 <mapper namespace="com.jpsoft.smart.modules.base.dao.PersonDeviceRelationDAO">
-	<resultMap id="PersonDeviceRelationMap" type="com.jpsoft.smart.modules.base.entity.PersonDeviceRelation">
+    <sql id="Base_Column_List">
+	id_,
+	device_id,
+	person_id,
+	del_flag,
+	create_by,
+	create_time,
+	update_by,
+	update_time,
+	device_id,
+	person_id
+</sql>
+    <resultMap id="PersonDeviceRelationMap" type="com.jpsoft.smart.modules.base.entity.PersonDeviceRelation">
 		<id property="id" column="id_" />
 			<result property="deviceId" column="device_id" />
 			<result property="personId" column="person_id" />
@@ -70,7 +82,7 @@
 	where id_=#{id}
 	</update>
 	<select id="get" parameterType="string" resultMap="PersonDeviceRelationMap">
-		select 
+		select
 id_,device_id,person_id,del_flag,create_by,create_time,update_by,update_time		from base_person_device_relation where id_=#{0}
 	</select>
 	<select id="exist" parameterType="string" resultType="int">
@@ -105,4 +117,7 @@ id_,device_id,person_id,del_flag,create_by,create_time,update_by,update_time		fr
 	        ${sort.name} ${sort.order}
 	 	</foreach>
 	</select>
+
+
+
 </mapper>

+ 19 - 0
lapi/src/main/java/com/jpsoft/smart/lapi/handler/HeartReportHandler.java

@@ -2,11 +2,14 @@ package com.jpsoft.smart.lapi.handler;
 
 import cn.hutool.json.JSONObject;
 import com.jpsoft.smart.lapi.dto.HeartReportInfo;
+import com.jpsoft.smart.modules.base.service.DeviceInfoService;
+import com.jpsoft.smart.modules.base.service.PersonDeviceLogService;
 import io.netty.channel.ChannelHandler;
 import io.netty.channel.ChannelHandlerContext;
 import io.netty.channel.SimpleChannelInboundHandler;
 import io.netty.handler.codec.http.FullHttpRequest;
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
 import java.text.SimpleDateFormat;
@@ -16,8 +19,24 @@ import java.util.Date;
 @Component
 @ChannelHandler.Sharable
 public class HeartReportHandler extends SimpleChannelInboundHandler<HeartReportInfo> {
+    @Autowired
+    private DeviceInfoService deviceInfoService;
+
     @Override
     protected void channelRead0(ChannelHandlerContext channelHandlerContext, HeartReportInfo heartReportInfo) throws Exception {
+
+        log.warn(String.valueOf(channelHandlerContext.channel().remoteAddress()));
         log.warn(heartReportInfo.toString());
+        String ipAndPort = String.valueOf(channelHandlerContext.channel().remoteAddress());
+        String deviceNo = heartReportInfo.getDeviceCode();
+        String ip = ipAndPort.substring(ipAndPort.indexOf("/")+1,ipAndPort.indexOf(":"));
+        log.warn(deviceNo);
+        log.warn("ip =="+ip);
+
+     //   deviceInfoService.updateByDeviceNo(deviceNo,ip);
+
+
+
+
     }
 }

+ 1 - 0
lapi/src/main/java/com/jpsoft/smart/lapi/handler/ParseRequestHandler.java

@@ -30,6 +30,7 @@ public class ParseRequestHandler extends SimpleChannelInboundHandler<FullHttpReq
         byteBuf.resetReaderIndex();
 
         log.warn(request.uri());
+     //   log.warn(String.valueOf(ctx.channel().remoteAddress()));
 
         String json = new String(buffer,"UTF-8");
 

+ 7 - 4
lapi/src/main/java/com/jpsoft/smart/lapi/handler/PersonVerificationHandler.java

@@ -37,11 +37,16 @@ public class PersonVerificationHandler extends SimpleChannelInboundHandler<Perso
         JSONObject faceJson = new JSONObject(jsonObject.getStr("FaceInfoList").substring(1,jsonObject.getStr("FaceInfoList").length()-1));
       //  log.warn(faceJson.getStr("FaceImage"));
 
-        long timestamp = faceJson.getLong("Timestamp");
+     //   String  timestampStr = faceJson.getStr("Timestamp");
+        Long timestamp = faceJson.getLong("Timestamp");
+        if (timestamp.toString().length()<13){
+             double timestampDouble = timestamp *  Math.pow(10, 13 - timestamp.toString().length());
+             timestamp =new Double(timestampDouble).longValue() ;
+        }
 
+        log.warn(String.valueOf(timestamp));
         Date date = new Date(timestamp);
 
-     //   SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
 
 
 
@@ -55,8 +60,6 @@ public class PersonVerificationHandler extends SimpleChannelInboundHandler<Perso
         //人员抓拍信息
         JSONObject faceImageJson = faceJson.getJSONObject("FaceImage");
 
-        //log.warn("jsonObject========"+jsonObject);
-      //  log.warn("LibMatInfoList:----"+ jsonObject.getStr("LibMatInfoList"));
         //匹配状态信息
         JSONObject libMatInfoListJson = new JSONObject();
         if (StringUtils.isNotBlank(jsonObject.getStr("LibMatInfoList").substring(1,jsonObject.getStr("LibMatInfoList").length()-1))){

+ 16 - 0
web/src/main/java/com/jpsoft/smart/modules/base/controller/CompanyInfoController.java

@@ -105,6 +105,22 @@ public class CompanyInfoController {
 
             if (companyInfo != null) {
                 PojoUtils.map(companyInfo, companyInfoDTO);
+
+                CompanyPosition companyPosition = new CompanyPosition();
+                Map<String,Object> searchParams1 = new HashMap<>();
+                searchParams1.put("companyId",companyInfo.getId());
+                List<Sort> sortList1 = new ArrayList<>();
+                sortList1.add(new Sort("id_","asc"));
+                Page<CompanyPosition> page1 = companyPositionService.pageSearch(searchParams1,1,1,false,sortList1);
+                if(page1.size() > 0) {
+                    companyPosition = page1.get(0);
+                    companyInfoDTO.setPosition1Name(companyPosition.getPosition1Name());
+                    companyInfoDTO.setPosition2Name(companyPosition.getPosition2Name());
+                    companyInfoDTO.setPosition3Name(companyPosition.getPosition3Name());
+                    companyInfoDTO.setPosition4Name(companyPosition.getPosition4Name());
+                    companyInfoDTO.setPosition5Name(companyPosition.getPosition5Name());
+                }
+
                 msgResult.setResult(true);
                 msgResult.setData(companyInfoDTO);
             } else {

+ 19 - 17
web/src/main/java/com/jpsoft/smart/modules/base/controller/PersonInfoController.java

@@ -761,21 +761,23 @@ public class PersonInfoController {
         return msgResult;
     }
 
-//    @ApiOperation(value="导出人员")
-//    @PostMapping("exportXls")
-//    public MessageResult<String> exportXls(@RequestBody List<String> ids){
-//        MessageResult<String> msgResult = new MessageResult<>();
-//
-//        try {
-//
-//        }
-//        catch(Exception ex){
-//            logger.error(ex.getMessage(),ex);
-//
-//            msgResult.setResult(false);
-//            msgResult.setMessage(ex.getMessage());
-//        }
-//
-//        return msgResult;
-//    }
+    @ApiOperation(value="数据同步")
+    @PostMapping("dataSync")
+    public MessageResult<String> dataSync(@RequestBody List<String> ids){
+        MessageResult<String> msgResult = new MessageResult<>();
+
+        try {
+            for(String id : ids){
+
+            }
+        }
+        catch(Exception ex){
+            logger.error(ex.getMessage(),ex);
+
+            msgResult.setResult(false);
+            msgResult.setMessage(ex.getMessage());
+        }
+
+        return msgResult;
+    }
 }

+ 33 - 0
web/src/test/java/com/jpsoft/smart/LApiTest.java

@@ -1,12 +1,16 @@
 package com.jpsoft.smart;
 
+import com.jpsoft.smart.modules.base.entity.DeviceInfo;
 import com.jpsoft.smart.modules.lapi.service.ILapiService;
+import com.jpsoft.smart.modules.lapi.vo.LapiMsgResult;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.test.context.junit4.SpringRunner;
 
+import java.util.List;
+
 /**
  * @author 墨鱼_mo
  * @date 2020-3-15 9:58
@@ -30,4 +34,33 @@ public class LApiTest {
 
     }
 
+    @Test
+    public void testAddPerson(){
+        try {
+
+            List<LapiMsgResult> result = lapiService.addPerson(1111L);
+            System.out.println(result);
+        } catch (Exception e) {
+            e.printStackTrace();
+            String message = e.getMessage();
+        }
+
+    }
+
+    @Test
+    public void testGetFaceDB(){
+        try {
+
+            DeviceInfo deviceInfo = new DeviceInfo();
+            deviceInfo.setIpAddress("192.168.11.13");
+            deviceInfo.setPort("80");
+            lapiService.getFaceDbId(deviceInfo,"荆鹏软件");
+            System.out.println();
+        } catch (Exception e) {
+            e.printStackTrace();
+            String message = e.getMessage();
+        }
+
+    }
+
 }