diff --git a/casic-face-sync/pom.xml b/casic-face-sync/pom.xml new file mode 100644 index 0000000..24dc884 --- /dev/null +++ b/casic-face-sync/pom.xml @@ -0,0 +1,74 @@ + + + 4.0.0 + + com.casic + casic-iris-parent + 1.0.0-SNAPSHOT + ../pom.xml + + + + casic-face-sync + ${pro.version} + jar + casic-face-sync + + + + + + com.casic + casic-core + ${core.version} + + + + com.casic + casic-admin-support + ${admin.version} + + + com.casic + casic-iris-support + ${pro.version} + + + + org.apache.httpcomponents + httpclient + 4.5.3 + + + + org.apache.httpcomponents + httpcore + 4.4.8 + + + + org.apache.httpcomponents + httpmime + 4.5.3 + + + + com.google.code.gson + gson + + + + + + + + src/main/java + + **/*.xml + + + + + \ No newline at end of file diff --git a/casic-face-sync/pom.xml b/casic-face-sync/pom.xml new file mode 100644 index 0000000..24dc884 --- /dev/null +++ b/casic-face-sync/pom.xml @@ -0,0 +1,74 @@ + + + 4.0.0 + + com.casic + casic-iris-parent + 1.0.0-SNAPSHOT + ../pom.xml + + + + casic-face-sync + ${pro.version} + jar + casic-face-sync + + + + + + com.casic + casic-core + ${core.version} + + + + com.casic + casic-admin-support + ${admin.version} + + + com.casic + casic-iris-support + ${pro.version} + + + + org.apache.httpcomponents + httpclient + 4.5.3 + + + + org.apache.httpcomponents + httpcore + 4.4.8 + + + + org.apache.httpcomponents + httpmime + 4.5.3 + + + + com.google.code.gson + gson + + + + + + + + src/main/java + + **/*.xml + + + + + \ No newline at end of file diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/constant/FaceSyncConst.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/constant/FaceSyncConst.java new file mode 100644 index 0000000..352d47d --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/constant/FaceSyncConst.java @@ -0,0 +1,29 @@ +package com.casic.missiles.modular.system.constant; + +public class FaceSyncConst { + + /** + * 单次最大批量上传人员数 + */ + public static final int UPLOAD_MAX_PERSON = 6; + + /** + * 上传人员库 + */ + public static final String UPLOAD_STAFF_LIB = "3"; + public static final String UPLOAD_VISITOR_LIB = "4"; + + public static final String UPLOAD_URL_PREFIX = "/LAPI/V1.0/PeopleLibraries/"; + + public static final String UPLOAD_URL_SUFFIX = "/People"; + + public static final int UPLOAD_PERSONCODE_MAXLENGTH = 15; + + public static final int UPLOAD_REMARK_MAXLENGTH = 63; + + public static final String SUBSCRIBE_URL = "/LAPI/V1.0/System/Event/Subscription/"; + + public static final String STAFF_PERSON_TYPE = "1"; + + public static final String VISITOR_PERSON_TYPE = "0"; +} diff --git a/casic-face-sync/pom.xml b/casic-face-sync/pom.xml new file mode 100644 index 0000000..24dc884 --- /dev/null +++ b/casic-face-sync/pom.xml @@ -0,0 +1,74 @@ + + + 4.0.0 + + com.casic + casic-iris-parent + 1.0.0-SNAPSHOT + ../pom.xml + + + + casic-face-sync + ${pro.version} + jar + casic-face-sync + + + + + + com.casic + casic-core + ${core.version} + + + + com.casic + casic-admin-support + ${admin.version} + + + com.casic + casic-iris-support + ${pro.version} + + + + org.apache.httpcomponents + httpclient + 4.5.3 + + + + org.apache.httpcomponents + httpcore + 4.4.8 + + + + org.apache.httpcomponents + httpmime + 4.5.3 + + + + com.google.code.gson + gson + + + + + + + + src/main/java + + **/*.xml + + + + + \ No newline at end of file diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/constant/FaceSyncConst.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/constant/FaceSyncConst.java new file mode 100644 index 0000000..352d47d --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/constant/FaceSyncConst.java @@ -0,0 +1,29 @@ +package com.casic.missiles.modular.system.constant; + +public class FaceSyncConst { + + /** + * 单次最大批量上传人员数 + */ + public static final int UPLOAD_MAX_PERSON = 6; + + /** + * 上传人员库 + */ + public static final String UPLOAD_STAFF_LIB = "3"; + public static final String UPLOAD_VISITOR_LIB = "4"; + + public static final String UPLOAD_URL_PREFIX = "/LAPI/V1.0/PeopleLibraries/"; + + public static final String UPLOAD_URL_SUFFIX = "/People"; + + public static final int UPLOAD_PERSONCODE_MAXLENGTH = 15; + + public static final int UPLOAD_REMARK_MAXLENGTH = 63; + + public static final String SUBSCRIBE_URL = "/LAPI/V1.0/System/Event/Subscription/"; + + public static final String STAFF_PERSON_TYPE = "1"; + + public static final String VISITOR_PERSON_TYPE = "0"; +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/controller/FaceSyncController.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/controller/FaceSyncController.java new file mode 100644 index 0000000..1b35431 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/controller/FaceSyncController.java @@ -0,0 +1,117 @@ +package com.casic.missiles.modular.system.controller; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson.serializer.SerializerFeature; +import com.casic.missiles.core.base.response.ResponseData; +import com.casic.missiles.core.common.service.ICommonPermissionService; +import com.casic.missiles.core.common.service.ICommonPersonService; +import com.casic.missiles.core.datascope.DataScope; +import com.casic.missiles.core.util.ToolUtil; +import com.casic.missiles.modular.system.request.PersonInfo; +import com.casic.missiles.modular.system.response.RecordNotification; +import com.casic.missiles.modular.system.service.IFaceSyncService; +import com.casic.missiles.modular.system.service.IIrisPersonSupportService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.*; +import com.casic.missiles.modular.system.constant.FaceSyncConst; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + + + +@Controller +public class FaceSyncController { + private final static Logger logger = LoggerFactory.getLogger(FaceSyncController.class); + + @Autowired + private IFaceSyncService syncService; + @Autowired + private ICommonPersonService commonPersonService; + @Autowired + private IIrisPersonSupportService personSupportService; + @Autowired + private ICommonPermissionService permissionService; + + @RequestMapping("/face/upload") + @ResponseBody + public Object upload(@RequestParam("personIds") List personIds, + @RequestParam("deviceIds") List deviceIds, + @RequestParam("personType")String personType ){ + // 检查数量 +// if(personIds.size()>FaceSyncConst.UPLOAD_MAX_PERSON){ +// return ResponseData.error(String.format("每次最多上传%s个人",FaceSyncConst.UPLOAD_MAX_PERSON)); +// } + // 检查照片格式及大小 + String photoCheck = syncService.checkPersonPhoto(personIds); + if(ToolUtil.isNotEmpty(photoCheck)){ + return ResponseData.error(photoCheck); + } + else{ + // 上传数据 + String error = syncService.uploadPerson(personIds,deviceIds,personType); + if(ToolUtil.isNotEmpty(error)){ + return ResponseData.error(error); + } + } + return ResponseData.success(); + } + + @RequestMapping("/face/uploadAll") + @ResponseBody + public Object uploadAll(@RequestParam("deviceIds") List deviceIds){ + DataScope dataScope = permissionService.getCurrUserDataScope(); + + List staffPersonIds = personSupportService.listIdsByType(dataScope,FaceSyncConst.STAFF_PERSON_TYPE); + List visitorPersonIds = personSupportService.listIdsByType(dataScope,FaceSyncConst.VISITOR_PERSON_TYPE); + // 1.检查照片,分别检查员工、访客 + String staffPhotoCheck = syncService.checkPersonPhoto(staffPersonIds); + if(ToolUtil.isNotEmpty(staffPhotoCheck)){ + return ResponseData.error(staffPhotoCheck); + } + String visitorPhotoCheck = syncService.checkPersonPhoto(visitorPersonIds); + if(ToolUtil.isNotEmpty(visitorPhotoCheck)){ + return ResponseData.error(visitorPhotoCheck); + } + + // 2. 下发数据 + String staffError = syncService.uploadPerson(staffPersonIds,deviceIds,FaceSyncConst.STAFF_PERSON_TYPE); + if(ToolUtil.isNotEmpty(staffError)){ + return ResponseData.error(staffError); + } + String visitorError = syncService.uploadPerson(visitorPersonIds,deviceIds,FaceSyncConst.VISITOR_PERSON_TYPE); + if(ToolUtil.isNotEmpty(visitorError)){ + return ResponseData.error(visitorError); + } + + return ResponseData.success(); + } + + // 错误信息返回 + @RequestMapping("/subsrcibe/init") + @ResponseBody + public Object upload(@RequestParam("deviceIds") List deviceIds){ + String errorMsg = syncService.initSubscription(deviceIds); + if(ToolUtil.isNotEmpty(errorMsg)){ + return ResponseData.error(errorMsg); + } + return ResponseData.success(); + } + + + @RequestMapping(value = "/LAPI/V1.0/System/Event/Notification/PersonVerification", method = RequestMethod.POST) + @ResponseBody + public void verification(@RequestBody String recordNotification){ + logger.info(recordNotification); + RecordNotification record = JSONObject.parseObject(recordNotification,RecordNotification.class); + syncService.receiveRecord(record); + //return ResponseData.success(); + } + + +} diff --git a/casic-face-sync/pom.xml b/casic-face-sync/pom.xml new file mode 100644 index 0000000..24dc884 --- /dev/null +++ b/casic-face-sync/pom.xml @@ -0,0 +1,74 @@ + + + 4.0.0 + + com.casic + casic-iris-parent + 1.0.0-SNAPSHOT + ../pom.xml + + + + casic-face-sync + ${pro.version} + jar + casic-face-sync + + + + + + com.casic + casic-core + ${core.version} + + + + com.casic + casic-admin-support + ${admin.version} + + + com.casic + casic-iris-support + ${pro.version} + + + + org.apache.httpcomponents + httpclient + 4.5.3 + + + + org.apache.httpcomponents + httpcore + 4.4.8 + + + + org.apache.httpcomponents + httpmime + 4.5.3 + + + + com.google.code.gson + gson + + + + + + + + src/main/java + + **/*.xml + + + + + \ No newline at end of file diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/constant/FaceSyncConst.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/constant/FaceSyncConst.java new file mode 100644 index 0000000..352d47d --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/constant/FaceSyncConst.java @@ -0,0 +1,29 @@ +package com.casic.missiles.modular.system.constant; + +public class FaceSyncConst { + + /** + * 单次最大批量上传人员数 + */ + public static final int UPLOAD_MAX_PERSON = 6; + + /** + * 上传人员库 + */ + public static final String UPLOAD_STAFF_LIB = "3"; + public static final String UPLOAD_VISITOR_LIB = "4"; + + public static final String UPLOAD_URL_PREFIX = "/LAPI/V1.0/PeopleLibraries/"; + + public static final String UPLOAD_URL_SUFFIX = "/People"; + + public static final int UPLOAD_PERSONCODE_MAXLENGTH = 15; + + public static final int UPLOAD_REMARK_MAXLENGTH = 63; + + public static final String SUBSCRIBE_URL = "/LAPI/V1.0/System/Event/Subscription/"; + + public static final String STAFF_PERSON_TYPE = "1"; + + public static final String VISITOR_PERSON_TYPE = "0"; +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/controller/FaceSyncController.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/controller/FaceSyncController.java new file mode 100644 index 0000000..1b35431 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/controller/FaceSyncController.java @@ -0,0 +1,117 @@ +package com.casic.missiles.modular.system.controller; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson.serializer.SerializerFeature; +import com.casic.missiles.core.base.response.ResponseData; +import com.casic.missiles.core.common.service.ICommonPermissionService; +import com.casic.missiles.core.common.service.ICommonPersonService; +import com.casic.missiles.core.datascope.DataScope; +import com.casic.missiles.core.util.ToolUtil; +import com.casic.missiles.modular.system.request.PersonInfo; +import com.casic.missiles.modular.system.response.RecordNotification; +import com.casic.missiles.modular.system.service.IFaceSyncService; +import com.casic.missiles.modular.system.service.IIrisPersonSupportService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.*; +import com.casic.missiles.modular.system.constant.FaceSyncConst; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + + + +@Controller +public class FaceSyncController { + private final static Logger logger = LoggerFactory.getLogger(FaceSyncController.class); + + @Autowired + private IFaceSyncService syncService; + @Autowired + private ICommonPersonService commonPersonService; + @Autowired + private IIrisPersonSupportService personSupportService; + @Autowired + private ICommonPermissionService permissionService; + + @RequestMapping("/face/upload") + @ResponseBody + public Object upload(@RequestParam("personIds") List personIds, + @RequestParam("deviceIds") List deviceIds, + @RequestParam("personType")String personType ){ + // 检查数量 +// if(personIds.size()>FaceSyncConst.UPLOAD_MAX_PERSON){ +// return ResponseData.error(String.format("每次最多上传%s个人",FaceSyncConst.UPLOAD_MAX_PERSON)); +// } + // 检查照片格式及大小 + String photoCheck = syncService.checkPersonPhoto(personIds); + if(ToolUtil.isNotEmpty(photoCheck)){ + return ResponseData.error(photoCheck); + } + else{ + // 上传数据 + String error = syncService.uploadPerson(personIds,deviceIds,personType); + if(ToolUtil.isNotEmpty(error)){ + return ResponseData.error(error); + } + } + return ResponseData.success(); + } + + @RequestMapping("/face/uploadAll") + @ResponseBody + public Object uploadAll(@RequestParam("deviceIds") List deviceIds){ + DataScope dataScope = permissionService.getCurrUserDataScope(); + + List staffPersonIds = personSupportService.listIdsByType(dataScope,FaceSyncConst.STAFF_PERSON_TYPE); + List visitorPersonIds = personSupportService.listIdsByType(dataScope,FaceSyncConst.VISITOR_PERSON_TYPE); + // 1.检查照片,分别检查员工、访客 + String staffPhotoCheck = syncService.checkPersonPhoto(staffPersonIds); + if(ToolUtil.isNotEmpty(staffPhotoCheck)){ + return ResponseData.error(staffPhotoCheck); + } + String visitorPhotoCheck = syncService.checkPersonPhoto(visitorPersonIds); + if(ToolUtil.isNotEmpty(visitorPhotoCheck)){ + return ResponseData.error(visitorPhotoCheck); + } + + // 2. 下发数据 + String staffError = syncService.uploadPerson(staffPersonIds,deviceIds,FaceSyncConst.STAFF_PERSON_TYPE); + if(ToolUtil.isNotEmpty(staffError)){ + return ResponseData.error(staffError); + } + String visitorError = syncService.uploadPerson(visitorPersonIds,deviceIds,FaceSyncConst.VISITOR_PERSON_TYPE); + if(ToolUtil.isNotEmpty(visitorError)){ + return ResponseData.error(visitorError); + } + + return ResponseData.success(); + } + + // 错误信息返回 + @RequestMapping("/subsrcibe/init") + @ResponseBody + public Object upload(@RequestParam("deviceIds") List deviceIds){ + String errorMsg = syncService.initSubscription(deviceIds); + if(ToolUtil.isNotEmpty(errorMsg)){ + return ResponseData.error(errorMsg); + } + return ResponseData.success(); + } + + + @RequestMapping(value = "/LAPI/V1.0/System/Event/Notification/PersonVerification", method = RequestMethod.POST) + @ResponseBody + public void verification(@RequestBody String recordNotification){ + logger.info(recordNotification); + RecordNotification record = JSONObject.parseObject(recordNotification,RecordNotification.class); + syncService.receiveRecord(record); + //return ResponseData.success(); + } + + +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FacePersonSyncMapper.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FacePersonSyncMapper.java new file mode 100644 index 0000000..af53702 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FacePersonSyncMapper.java @@ -0,0 +1,17 @@ +package com.casic.missiles.modular.system.dao; + +import com.casic.missiles.modular.system.model.FacePersonSync; +import com.baomidou.mybatisplus.mapper.BaseMapper; + +/** + *

+ * Mapper 接口 + *

+ * + * @author zyj123 + * @since 2020-07-24 + */ +public interface FacePersonSyncMapper extends BaseMapper { + + Long getMaxSyncId(); +} diff --git a/casic-face-sync/pom.xml b/casic-face-sync/pom.xml new file mode 100644 index 0000000..24dc884 --- /dev/null +++ b/casic-face-sync/pom.xml @@ -0,0 +1,74 @@ + + + 4.0.0 + + com.casic + casic-iris-parent + 1.0.0-SNAPSHOT + ../pom.xml + + + + casic-face-sync + ${pro.version} + jar + casic-face-sync + + + + + + com.casic + casic-core + ${core.version} + + + + com.casic + casic-admin-support + ${admin.version} + + + com.casic + casic-iris-support + ${pro.version} + + + + org.apache.httpcomponents + httpclient + 4.5.3 + + + + org.apache.httpcomponents + httpcore + 4.4.8 + + + + org.apache.httpcomponents + httpmime + 4.5.3 + + + + com.google.code.gson + gson + + + + + + + + src/main/java + + **/*.xml + + + + + \ No newline at end of file diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/constant/FaceSyncConst.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/constant/FaceSyncConst.java new file mode 100644 index 0000000..352d47d --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/constant/FaceSyncConst.java @@ -0,0 +1,29 @@ +package com.casic.missiles.modular.system.constant; + +public class FaceSyncConst { + + /** + * 单次最大批量上传人员数 + */ + public static final int UPLOAD_MAX_PERSON = 6; + + /** + * 上传人员库 + */ + public static final String UPLOAD_STAFF_LIB = "3"; + public static final String UPLOAD_VISITOR_LIB = "4"; + + public static final String UPLOAD_URL_PREFIX = "/LAPI/V1.0/PeopleLibraries/"; + + public static final String UPLOAD_URL_SUFFIX = "/People"; + + public static final int UPLOAD_PERSONCODE_MAXLENGTH = 15; + + public static final int UPLOAD_REMARK_MAXLENGTH = 63; + + public static final String SUBSCRIBE_URL = "/LAPI/V1.0/System/Event/Subscription/"; + + public static final String STAFF_PERSON_TYPE = "1"; + + public static final String VISITOR_PERSON_TYPE = "0"; +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/controller/FaceSyncController.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/controller/FaceSyncController.java new file mode 100644 index 0000000..1b35431 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/controller/FaceSyncController.java @@ -0,0 +1,117 @@ +package com.casic.missiles.modular.system.controller; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson.serializer.SerializerFeature; +import com.casic.missiles.core.base.response.ResponseData; +import com.casic.missiles.core.common.service.ICommonPermissionService; +import com.casic.missiles.core.common.service.ICommonPersonService; +import com.casic.missiles.core.datascope.DataScope; +import com.casic.missiles.core.util.ToolUtil; +import com.casic.missiles.modular.system.request.PersonInfo; +import com.casic.missiles.modular.system.response.RecordNotification; +import com.casic.missiles.modular.system.service.IFaceSyncService; +import com.casic.missiles.modular.system.service.IIrisPersonSupportService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.*; +import com.casic.missiles.modular.system.constant.FaceSyncConst; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + + + +@Controller +public class FaceSyncController { + private final static Logger logger = LoggerFactory.getLogger(FaceSyncController.class); + + @Autowired + private IFaceSyncService syncService; + @Autowired + private ICommonPersonService commonPersonService; + @Autowired + private IIrisPersonSupportService personSupportService; + @Autowired + private ICommonPermissionService permissionService; + + @RequestMapping("/face/upload") + @ResponseBody + public Object upload(@RequestParam("personIds") List personIds, + @RequestParam("deviceIds") List deviceIds, + @RequestParam("personType")String personType ){ + // 检查数量 +// if(personIds.size()>FaceSyncConst.UPLOAD_MAX_PERSON){ +// return ResponseData.error(String.format("每次最多上传%s个人",FaceSyncConst.UPLOAD_MAX_PERSON)); +// } + // 检查照片格式及大小 + String photoCheck = syncService.checkPersonPhoto(personIds); + if(ToolUtil.isNotEmpty(photoCheck)){ + return ResponseData.error(photoCheck); + } + else{ + // 上传数据 + String error = syncService.uploadPerson(personIds,deviceIds,personType); + if(ToolUtil.isNotEmpty(error)){ + return ResponseData.error(error); + } + } + return ResponseData.success(); + } + + @RequestMapping("/face/uploadAll") + @ResponseBody + public Object uploadAll(@RequestParam("deviceIds") List deviceIds){ + DataScope dataScope = permissionService.getCurrUserDataScope(); + + List staffPersonIds = personSupportService.listIdsByType(dataScope,FaceSyncConst.STAFF_PERSON_TYPE); + List visitorPersonIds = personSupportService.listIdsByType(dataScope,FaceSyncConst.VISITOR_PERSON_TYPE); + // 1.检查照片,分别检查员工、访客 + String staffPhotoCheck = syncService.checkPersonPhoto(staffPersonIds); + if(ToolUtil.isNotEmpty(staffPhotoCheck)){ + return ResponseData.error(staffPhotoCheck); + } + String visitorPhotoCheck = syncService.checkPersonPhoto(visitorPersonIds); + if(ToolUtil.isNotEmpty(visitorPhotoCheck)){ + return ResponseData.error(visitorPhotoCheck); + } + + // 2. 下发数据 + String staffError = syncService.uploadPerson(staffPersonIds,deviceIds,FaceSyncConst.STAFF_PERSON_TYPE); + if(ToolUtil.isNotEmpty(staffError)){ + return ResponseData.error(staffError); + } + String visitorError = syncService.uploadPerson(visitorPersonIds,deviceIds,FaceSyncConst.VISITOR_PERSON_TYPE); + if(ToolUtil.isNotEmpty(visitorError)){ + return ResponseData.error(visitorError); + } + + return ResponseData.success(); + } + + // 错误信息返回 + @RequestMapping("/subsrcibe/init") + @ResponseBody + public Object upload(@RequestParam("deviceIds") List deviceIds){ + String errorMsg = syncService.initSubscription(deviceIds); + if(ToolUtil.isNotEmpty(errorMsg)){ + return ResponseData.error(errorMsg); + } + return ResponseData.success(); + } + + + @RequestMapping(value = "/LAPI/V1.0/System/Event/Notification/PersonVerification", method = RequestMethod.POST) + @ResponseBody + public void verification(@RequestBody String recordNotification){ + logger.info(recordNotification); + RecordNotification record = JSONObject.parseObject(recordNotification,RecordNotification.class); + syncService.receiveRecord(record); + //return ResponseData.success(); + } + + +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FacePersonSyncMapper.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FacePersonSyncMapper.java new file mode 100644 index 0000000..af53702 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FacePersonSyncMapper.java @@ -0,0 +1,17 @@ +package com.casic.missiles.modular.system.dao; + +import com.casic.missiles.modular.system.model.FacePersonSync; +import com.baomidou.mybatisplus.mapper.BaseMapper; + +/** + *

+ * Mapper 接口 + *

+ * + * @author zyj123 + * @since 2020-07-24 + */ +public interface FacePersonSyncMapper extends BaseMapper { + + Long getMaxSyncId(); +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FaceSubscribeMapper.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FaceSubscribeMapper.java new file mode 100644 index 0000000..0c6374a --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FaceSubscribeMapper.java @@ -0,0 +1,16 @@ +package com.casic.missiles.modular.system.dao; + +import com.casic.missiles.modular.system.model.FaceSubscribe; +import com.baomidou.mybatisplus.mapper.BaseMapper; + +/** + *

+ * Mapper 接口 + *

+ * + * @author zyj123 + * @since 2020-07-25 + */ +public interface FaceSubscribeMapper extends BaseMapper { + +} diff --git a/casic-face-sync/pom.xml b/casic-face-sync/pom.xml new file mode 100644 index 0000000..24dc884 --- /dev/null +++ b/casic-face-sync/pom.xml @@ -0,0 +1,74 @@ + + + 4.0.0 + + com.casic + casic-iris-parent + 1.0.0-SNAPSHOT + ../pom.xml + + + + casic-face-sync + ${pro.version} + jar + casic-face-sync + + + + + + com.casic + casic-core + ${core.version} + + + + com.casic + casic-admin-support + ${admin.version} + + + com.casic + casic-iris-support + ${pro.version} + + + + org.apache.httpcomponents + httpclient + 4.5.3 + + + + org.apache.httpcomponents + httpcore + 4.4.8 + + + + org.apache.httpcomponents + httpmime + 4.5.3 + + + + com.google.code.gson + gson + + + + + + + + src/main/java + + **/*.xml + + + + + \ No newline at end of file diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/constant/FaceSyncConst.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/constant/FaceSyncConst.java new file mode 100644 index 0000000..352d47d --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/constant/FaceSyncConst.java @@ -0,0 +1,29 @@ +package com.casic.missiles.modular.system.constant; + +public class FaceSyncConst { + + /** + * 单次最大批量上传人员数 + */ + public static final int UPLOAD_MAX_PERSON = 6; + + /** + * 上传人员库 + */ + public static final String UPLOAD_STAFF_LIB = "3"; + public static final String UPLOAD_VISITOR_LIB = "4"; + + public static final String UPLOAD_URL_PREFIX = "/LAPI/V1.0/PeopleLibraries/"; + + public static final String UPLOAD_URL_SUFFIX = "/People"; + + public static final int UPLOAD_PERSONCODE_MAXLENGTH = 15; + + public static final int UPLOAD_REMARK_MAXLENGTH = 63; + + public static final String SUBSCRIBE_URL = "/LAPI/V1.0/System/Event/Subscription/"; + + public static final String STAFF_PERSON_TYPE = "1"; + + public static final String VISITOR_PERSON_TYPE = "0"; +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/controller/FaceSyncController.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/controller/FaceSyncController.java new file mode 100644 index 0000000..1b35431 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/controller/FaceSyncController.java @@ -0,0 +1,117 @@ +package com.casic.missiles.modular.system.controller; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson.serializer.SerializerFeature; +import com.casic.missiles.core.base.response.ResponseData; +import com.casic.missiles.core.common.service.ICommonPermissionService; +import com.casic.missiles.core.common.service.ICommonPersonService; +import com.casic.missiles.core.datascope.DataScope; +import com.casic.missiles.core.util.ToolUtil; +import com.casic.missiles.modular.system.request.PersonInfo; +import com.casic.missiles.modular.system.response.RecordNotification; +import com.casic.missiles.modular.system.service.IFaceSyncService; +import com.casic.missiles.modular.system.service.IIrisPersonSupportService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.*; +import com.casic.missiles.modular.system.constant.FaceSyncConst; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + + + +@Controller +public class FaceSyncController { + private final static Logger logger = LoggerFactory.getLogger(FaceSyncController.class); + + @Autowired + private IFaceSyncService syncService; + @Autowired + private ICommonPersonService commonPersonService; + @Autowired + private IIrisPersonSupportService personSupportService; + @Autowired + private ICommonPermissionService permissionService; + + @RequestMapping("/face/upload") + @ResponseBody + public Object upload(@RequestParam("personIds") List personIds, + @RequestParam("deviceIds") List deviceIds, + @RequestParam("personType")String personType ){ + // 检查数量 +// if(personIds.size()>FaceSyncConst.UPLOAD_MAX_PERSON){ +// return ResponseData.error(String.format("每次最多上传%s个人",FaceSyncConst.UPLOAD_MAX_PERSON)); +// } + // 检查照片格式及大小 + String photoCheck = syncService.checkPersonPhoto(personIds); + if(ToolUtil.isNotEmpty(photoCheck)){ + return ResponseData.error(photoCheck); + } + else{ + // 上传数据 + String error = syncService.uploadPerson(personIds,deviceIds,personType); + if(ToolUtil.isNotEmpty(error)){ + return ResponseData.error(error); + } + } + return ResponseData.success(); + } + + @RequestMapping("/face/uploadAll") + @ResponseBody + public Object uploadAll(@RequestParam("deviceIds") List deviceIds){ + DataScope dataScope = permissionService.getCurrUserDataScope(); + + List staffPersonIds = personSupportService.listIdsByType(dataScope,FaceSyncConst.STAFF_PERSON_TYPE); + List visitorPersonIds = personSupportService.listIdsByType(dataScope,FaceSyncConst.VISITOR_PERSON_TYPE); + // 1.检查照片,分别检查员工、访客 + String staffPhotoCheck = syncService.checkPersonPhoto(staffPersonIds); + if(ToolUtil.isNotEmpty(staffPhotoCheck)){ + return ResponseData.error(staffPhotoCheck); + } + String visitorPhotoCheck = syncService.checkPersonPhoto(visitorPersonIds); + if(ToolUtil.isNotEmpty(visitorPhotoCheck)){ + return ResponseData.error(visitorPhotoCheck); + } + + // 2. 下发数据 + String staffError = syncService.uploadPerson(staffPersonIds,deviceIds,FaceSyncConst.STAFF_PERSON_TYPE); + if(ToolUtil.isNotEmpty(staffError)){ + return ResponseData.error(staffError); + } + String visitorError = syncService.uploadPerson(visitorPersonIds,deviceIds,FaceSyncConst.VISITOR_PERSON_TYPE); + if(ToolUtil.isNotEmpty(visitorError)){ + return ResponseData.error(visitorError); + } + + return ResponseData.success(); + } + + // 错误信息返回 + @RequestMapping("/subsrcibe/init") + @ResponseBody + public Object upload(@RequestParam("deviceIds") List deviceIds){ + String errorMsg = syncService.initSubscription(deviceIds); + if(ToolUtil.isNotEmpty(errorMsg)){ + return ResponseData.error(errorMsg); + } + return ResponseData.success(); + } + + + @RequestMapping(value = "/LAPI/V1.0/System/Event/Notification/PersonVerification", method = RequestMethod.POST) + @ResponseBody + public void verification(@RequestBody String recordNotification){ + logger.info(recordNotification); + RecordNotification record = JSONObject.parseObject(recordNotification,RecordNotification.class); + syncService.receiveRecord(record); + //return ResponseData.success(); + } + + +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FacePersonSyncMapper.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FacePersonSyncMapper.java new file mode 100644 index 0000000..af53702 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FacePersonSyncMapper.java @@ -0,0 +1,17 @@ +package com.casic.missiles.modular.system.dao; + +import com.casic.missiles.modular.system.model.FacePersonSync; +import com.baomidou.mybatisplus.mapper.BaseMapper; + +/** + *

+ * Mapper 接口 + *

+ * + * @author zyj123 + * @since 2020-07-24 + */ +public interface FacePersonSyncMapper extends BaseMapper { + + Long getMaxSyncId(); +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FaceSubscribeMapper.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FaceSubscribeMapper.java new file mode 100644 index 0000000..0c6374a --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FaceSubscribeMapper.java @@ -0,0 +1,16 @@ +package com.casic.missiles.modular.system.dao; + +import com.casic.missiles.modular.system.model.FaceSubscribe; +import com.baomidou.mybatisplus.mapper.BaseMapper; + +/** + *

+ * Mapper 接口 + *

+ * + * @author zyj123 + * @since 2020-07-25 + */ +public interface FaceSubscribeMapper extends BaseMapper { + +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FacePersonSyncMapper.xml b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FacePersonSyncMapper.xml new file mode 100644 index 0000000..ac46ad0 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FacePersonSyncMapper.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + PERSON_ID AS personId, SYNC_ID AS syncId + + + + + diff --git a/casic-face-sync/pom.xml b/casic-face-sync/pom.xml new file mode 100644 index 0000000..24dc884 --- /dev/null +++ b/casic-face-sync/pom.xml @@ -0,0 +1,74 @@ + + + 4.0.0 + + com.casic + casic-iris-parent + 1.0.0-SNAPSHOT + ../pom.xml + + + + casic-face-sync + ${pro.version} + jar + casic-face-sync + + + + + + com.casic + casic-core + ${core.version} + + + + com.casic + casic-admin-support + ${admin.version} + + + com.casic + casic-iris-support + ${pro.version} + + + + org.apache.httpcomponents + httpclient + 4.5.3 + + + + org.apache.httpcomponents + httpcore + 4.4.8 + + + + org.apache.httpcomponents + httpmime + 4.5.3 + + + + com.google.code.gson + gson + + + + + + + + src/main/java + + **/*.xml + + + + + \ No newline at end of file diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/constant/FaceSyncConst.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/constant/FaceSyncConst.java new file mode 100644 index 0000000..352d47d --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/constant/FaceSyncConst.java @@ -0,0 +1,29 @@ +package com.casic.missiles.modular.system.constant; + +public class FaceSyncConst { + + /** + * 单次最大批量上传人员数 + */ + public static final int UPLOAD_MAX_PERSON = 6; + + /** + * 上传人员库 + */ + public static final String UPLOAD_STAFF_LIB = "3"; + public static final String UPLOAD_VISITOR_LIB = "4"; + + public static final String UPLOAD_URL_PREFIX = "/LAPI/V1.0/PeopleLibraries/"; + + public static final String UPLOAD_URL_SUFFIX = "/People"; + + public static final int UPLOAD_PERSONCODE_MAXLENGTH = 15; + + public static final int UPLOAD_REMARK_MAXLENGTH = 63; + + public static final String SUBSCRIBE_URL = "/LAPI/V1.0/System/Event/Subscription/"; + + public static final String STAFF_PERSON_TYPE = "1"; + + public static final String VISITOR_PERSON_TYPE = "0"; +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/controller/FaceSyncController.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/controller/FaceSyncController.java new file mode 100644 index 0000000..1b35431 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/controller/FaceSyncController.java @@ -0,0 +1,117 @@ +package com.casic.missiles.modular.system.controller; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson.serializer.SerializerFeature; +import com.casic.missiles.core.base.response.ResponseData; +import com.casic.missiles.core.common.service.ICommonPermissionService; +import com.casic.missiles.core.common.service.ICommonPersonService; +import com.casic.missiles.core.datascope.DataScope; +import com.casic.missiles.core.util.ToolUtil; +import com.casic.missiles.modular.system.request.PersonInfo; +import com.casic.missiles.modular.system.response.RecordNotification; +import com.casic.missiles.modular.system.service.IFaceSyncService; +import com.casic.missiles.modular.system.service.IIrisPersonSupportService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.*; +import com.casic.missiles.modular.system.constant.FaceSyncConst; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + + + +@Controller +public class FaceSyncController { + private final static Logger logger = LoggerFactory.getLogger(FaceSyncController.class); + + @Autowired + private IFaceSyncService syncService; + @Autowired + private ICommonPersonService commonPersonService; + @Autowired + private IIrisPersonSupportService personSupportService; + @Autowired + private ICommonPermissionService permissionService; + + @RequestMapping("/face/upload") + @ResponseBody + public Object upload(@RequestParam("personIds") List personIds, + @RequestParam("deviceIds") List deviceIds, + @RequestParam("personType")String personType ){ + // 检查数量 +// if(personIds.size()>FaceSyncConst.UPLOAD_MAX_PERSON){ +// return ResponseData.error(String.format("每次最多上传%s个人",FaceSyncConst.UPLOAD_MAX_PERSON)); +// } + // 检查照片格式及大小 + String photoCheck = syncService.checkPersonPhoto(personIds); + if(ToolUtil.isNotEmpty(photoCheck)){ + return ResponseData.error(photoCheck); + } + else{ + // 上传数据 + String error = syncService.uploadPerson(personIds,deviceIds,personType); + if(ToolUtil.isNotEmpty(error)){ + return ResponseData.error(error); + } + } + return ResponseData.success(); + } + + @RequestMapping("/face/uploadAll") + @ResponseBody + public Object uploadAll(@RequestParam("deviceIds") List deviceIds){ + DataScope dataScope = permissionService.getCurrUserDataScope(); + + List staffPersonIds = personSupportService.listIdsByType(dataScope,FaceSyncConst.STAFF_PERSON_TYPE); + List visitorPersonIds = personSupportService.listIdsByType(dataScope,FaceSyncConst.VISITOR_PERSON_TYPE); + // 1.检查照片,分别检查员工、访客 + String staffPhotoCheck = syncService.checkPersonPhoto(staffPersonIds); + if(ToolUtil.isNotEmpty(staffPhotoCheck)){ + return ResponseData.error(staffPhotoCheck); + } + String visitorPhotoCheck = syncService.checkPersonPhoto(visitorPersonIds); + if(ToolUtil.isNotEmpty(visitorPhotoCheck)){ + return ResponseData.error(visitorPhotoCheck); + } + + // 2. 下发数据 + String staffError = syncService.uploadPerson(staffPersonIds,deviceIds,FaceSyncConst.STAFF_PERSON_TYPE); + if(ToolUtil.isNotEmpty(staffError)){ + return ResponseData.error(staffError); + } + String visitorError = syncService.uploadPerson(visitorPersonIds,deviceIds,FaceSyncConst.VISITOR_PERSON_TYPE); + if(ToolUtil.isNotEmpty(visitorError)){ + return ResponseData.error(visitorError); + } + + return ResponseData.success(); + } + + // 错误信息返回 + @RequestMapping("/subsrcibe/init") + @ResponseBody + public Object upload(@RequestParam("deviceIds") List deviceIds){ + String errorMsg = syncService.initSubscription(deviceIds); + if(ToolUtil.isNotEmpty(errorMsg)){ + return ResponseData.error(errorMsg); + } + return ResponseData.success(); + } + + + @RequestMapping(value = "/LAPI/V1.0/System/Event/Notification/PersonVerification", method = RequestMethod.POST) + @ResponseBody + public void verification(@RequestBody String recordNotification){ + logger.info(recordNotification); + RecordNotification record = JSONObject.parseObject(recordNotification,RecordNotification.class); + syncService.receiveRecord(record); + //return ResponseData.success(); + } + + +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FacePersonSyncMapper.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FacePersonSyncMapper.java new file mode 100644 index 0000000..af53702 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FacePersonSyncMapper.java @@ -0,0 +1,17 @@ +package com.casic.missiles.modular.system.dao; + +import com.casic.missiles.modular.system.model.FacePersonSync; +import com.baomidou.mybatisplus.mapper.BaseMapper; + +/** + *

+ * Mapper 接口 + *

+ * + * @author zyj123 + * @since 2020-07-24 + */ +public interface FacePersonSyncMapper extends BaseMapper { + + Long getMaxSyncId(); +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FaceSubscribeMapper.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FaceSubscribeMapper.java new file mode 100644 index 0000000..0c6374a --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FaceSubscribeMapper.java @@ -0,0 +1,16 @@ +package com.casic.missiles.modular.system.dao; + +import com.casic.missiles.modular.system.model.FaceSubscribe; +import com.baomidou.mybatisplus.mapper.BaseMapper; + +/** + *

+ * Mapper 接口 + *

+ * + * @author zyj123 + * @since 2020-07-25 + */ +public interface FaceSubscribeMapper extends BaseMapper { + +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FacePersonSyncMapper.xml b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FacePersonSyncMapper.xml new file mode 100644 index 0000000..ac46ad0 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FacePersonSyncMapper.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + PERSON_ID AS personId, SYNC_ID AS syncId + + + + + diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FaceSubscribeMapper.xml b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FaceSubscribeMapper.xml new file mode 100644 index 0000000..16024e2 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FaceSubscribeMapper.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + SUBSCRIBE_ID AS subscribeId, DEVICE_CODE AS deviceCode, UPDATE_TIME AS updateTime + + + diff --git a/casic-face-sync/pom.xml b/casic-face-sync/pom.xml new file mode 100644 index 0000000..24dc884 --- /dev/null +++ b/casic-face-sync/pom.xml @@ -0,0 +1,74 @@ + + + 4.0.0 + + com.casic + casic-iris-parent + 1.0.0-SNAPSHOT + ../pom.xml + + + + casic-face-sync + ${pro.version} + jar + casic-face-sync + + + + + + com.casic + casic-core + ${core.version} + + + + com.casic + casic-admin-support + ${admin.version} + + + com.casic + casic-iris-support + ${pro.version} + + + + org.apache.httpcomponents + httpclient + 4.5.3 + + + + org.apache.httpcomponents + httpcore + 4.4.8 + + + + org.apache.httpcomponents + httpmime + 4.5.3 + + + + com.google.code.gson + gson + + + + + + + + src/main/java + + **/*.xml + + + + + \ No newline at end of file diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/constant/FaceSyncConst.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/constant/FaceSyncConst.java new file mode 100644 index 0000000..352d47d --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/constant/FaceSyncConst.java @@ -0,0 +1,29 @@ +package com.casic.missiles.modular.system.constant; + +public class FaceSyncConst { + + /** + * 单次最大批量上传人员数 + */ + public static final int UPLOAD_MAX_PERSON = 6; + + /** + * 上传人员库 + */ + public static final String UPLOAD_STAFF_LIB = "3"; + public static final String UPLOAD_VISITOR_LIB = "4"; + + public static final String UPLOAD_URL_PREFIX = "/LAPI/V1.0/PeopleLibraries/"; + + public static final String UPLOAD_URL_SUFFIX = "/People"; + + public static final int UPLOAD_PERSONCODE_MAXLENGTH = 15; + + public static final int UPLOAD_REMARK_MAXLENGTH = 63; + + public static final String SUBSCRIBE_URL = "/LAPI/V1.0/System/Event/Subscription/"; + + public static final String STAFF_PERSON_TYPE = "1"; + + public static final String VISITOR_PERSON_TYPE = "0"; +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/controller/FaceSyncController.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/controller/FaceSyncController.java new file mode 100644 index 0000000..1b35431 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/controller/FaceSyncController.java @@ -0,0 +1,117 @@ +package com.casic.missiles.modular.system.controller; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson.serializer.SerializerFeature; +import com.casic.missiles.core.base.response.ResponseData; +import com.casic.missiles.core.common.service.ICommonPermissionService; +import com.casic.missiles.core.common.service.ICommonPersonService; +import com.casic.missiles.core.datascope.DataScope; +import com.casic.missiles.core.util.ToolUtil; +import com.casic.missiles.modular.system.request.PersonInfo; +import com.casic.missiles.modular.system.response.RecordNotification; +import com.casic.missiles.modular.system.service.IFaceSyncService; +import com.casic.missiles.modular.system.service.IIrisPersonSupportService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.*; +import com.casic.missiles.modular.system.constant.FaceSyncConst; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + + + +@Controller +public class FaceSyncController { + private final static Logger logger = LoggerFactory.getLogger(FaceSyncController.class); + + @Autowired + private IFaceSyncService syncService; + @Autowired + private ICommonPersonService commonPersonService; + @Autowired + private IIrisPersonSupportService personSupportService; + @Autowired + private ICommonPermissionService permissionService; + + @RequestMapping("/face/upload") + @ResponseBody + public Object upload(@RequestParam("personIds") List personIds, + @RequestParam("deviceIds") List deviceIds, + @RequestParam("personType")String personType ){ + // 检查数量 +// if(personIds.size()>FaceSyncConst.UPLOAD_MAX_PERSON){ +// return ResponseData.error(String.format("每次最多上传%s个人",FaceSyncConst.UPLOAD_MAX_PERSON)); +// } + // 检查照片格式及大小 + String photoCheck = syncService.checkPersonPhoto(personIds); + if(ToolUtil.isNotEmpty(photoCheck)){ + return ResponseData.error(photoCheck); + } + else{ + // 上传数据 + String error = syncService.uploadPerson(personIds,deviceIds,personType); + if(ToolUtil.isNotEmpty(error)){ + return ResponseData.error(error); + } + } + return ResponseData.success(); + } + + @RequestMapping("/face/uploadAll") + @ResponseBody + public Object uploadAll(@RequestParam("deviceIds") List deviceIds){ + DataScope dataScope = permissionService.getCurrUserDataScope(); + + List staffPersonIds = personSupportService.listIdsByType(dataScope,FaceSyncConst.STAFF_PERSON_TYPE); + List visitorPersonIds = personSupportService.listIdsByType(dataScope,FaceSyncConst.VISITOR_PERSON_TYPE); + // 1.检查照片,分别检查员工、访客 + String staffPhotoCheck = syncService.checkPersonPhoto(staffPersonIds); + if(ToolUtil.isNotEmpty(staffPhotoCheck)){ + return ResponseData.error(staffPhotoCheck); + } + String visitorPhotoCheck = syncService.checkPersonPhoto(visitorPersonIds); + if(ToolUtil.isNotEmpty(visitorPhotoCheck)){ + return ResponseData.error(visitorPhotoCheck); + } + + // 2. 下发数据 + String staffError = syncService.uploadPerson(staffPersonIds,deviceIds,FaceSyncConst.STAFF_PERSON_TYPE); + if(ToolUtil.isNotEmpty(staffError)){ + return ResponseData.error(staffError); + } + String visitorError = syncService.uploadPerson(visitorPersonIds,deviceIds,FaceSyncConst.VISITOR_PERSON_TYPE); + if(ToolUtil.isNotEmpty(visitorError)){ + return ResponseData.error(visitorError); + } + + return ResponseData.success(); + } + + // 错误信息返回 + @RequestMapping("/subsrcibe/init") + @ResponseBody + public Object upload(@RequestParam("deviceIds") List deviceIds){ + String errorMsg = syncService.initSubscription(deviceIds); + if(ToolUtil.isNotEmpty(errorMsg)){ + return ResponseData.error(errorMsg); + } + return ResponseData.success(); + } + + + @RequestMapping(value = "/LAPI/V1.0/System/Event/Notification/PersonVerification", method = RequestMethod.POST) + @ResponseBody + public void verification(@RequestBody String recordNotification){ + logger.info(recordNotification); + RecordNotification record = JSONObject.parseObject(recordNotification,RecordNotification.class); + syncService.receiveRecord(record); + //return ResponseData.success(); + } + + +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FacePersonSyncMapper.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FacePersonSyncMapper.java new file mode 100644 index 0000000..af53702 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FacePersonSyncMapper.java @@ -0,0 +1,17 @@ +package com.casic.missiles.modular.system.dao; + +import com.casic.missiles.modular.system.model.FacePersonSync; +import com.baomidou.mybatisplus.mapper.BaseMapper; + +/** + *

+ * Mapper 接口 + *

+ * + * @author zyj123 + * @since 2020-07-24 + */ +public interface FacePersonSyncMapper extends BaseMapper { + + Long getMaxSyncId(); +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FaceSubscribeMapper.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FaceSubscribeMapper.java new file mode 100644 index 0000000..0c6374a --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FaceSubscribeMapper.java @@ -0,0 +1,16 @@ +package com.casic.missiles.modular.system.dao; + +import com.casic.missiles.modular.system.model.FaceSubscribe; +import com.baomidou.mybatisplus.mapper.BaseMapper; + +/** + *

+ * Mapper 接口 + *

+ * + * @author zyj123 + * @since 2020-07-25 + */ +public interface FaceSubscribeMapper extends BaseMapper { + +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FacePersonSyncMapper.xml b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FacePersonSyncMapper.xml new file mode 100644 index 0000000..ac46ad0 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FacePersonSyncMapper.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + PERSON_ID AS personId, SYNC_ID AS syncId + + + + + diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FaceSubscribeMapper.xml b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FaceSubscribeMapper.xml new file mode 100644 index 0000000..16024e2 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FaceSubscribeMapper.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + SUBSCRIBE_ID AS subscribeId, DEVICE_CODE AS deviceCode, UPDATE_TIME AS updateTime + + + diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FacePersonSync.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FacePersonSync.java new file mode 100644 index 0000000..7cdb821 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FacePersonSync.java @@ -0,0 +1,68 @@ +package com.casic.missiles.modular.system.model; + +import java.io.Serializable; + +import com.baomidou.mybatisplus.annotations.TableId; +import com.baomidou.mybatisplus.annotations.TableField; +import com.baomidou.mybatisplus.activerecord.Model; +import com.baomidou.mybatisplus.annotations.TableName; +import java.io.Serializable; + +/** + *

+ * + *

+ * + * @author zyj123 + * @since 2020-07-24 + */ +@TableName("face_person_sync") +public class FacePersonSync extends Model { + + private static final long serialVersionUID = 1L; + + /** + * 人员id + */ + @TableId("PERSON_ID") + private Long personId; + /** + * 人员同步id + */ + @TableField("SYNC_ID") + private Long syncId; + + public FacePersonSync(Long personId, Long syncId) { + this.personId = personId; + this.syncId = syncId; + } + + public Long getPersonId() { + return personId; + } + + public void setPersonId(Long personId) { + this.personId = personId; + } + + public Long getSyncId() { + return syncId; + } + + public void setSyncId(Long syncId) { + this.syncId = syncId; + } + + @Override + protected Serializable pkVal() { + return this.personId; + } + + @Override + public String toString() { + return "FacePersonSync{" + + "personId=" + personId + + ", syncId=" + syncId + + "}"; + } +} diff --git a/casic-face-sync/pom.xml b/casic-face-sync/pom.xml new file mode 100644 index 0000000..24dc884 --- /dev/null +++ b/casic-face-sync/pom.xml @@ -0,0 +1,74 @@ + + + 4.0.0 + + com.casic + casic-iris-parent + 1.0.0-SNAPSHOT + ../pom.xml + + + + casic-face-sync + ${pro.version} + jar + casic-face-sync + + + + + + com.casic + casic-core + ${core.version} + + + + com.casic + casic-admin-support + ${admin.version} + + + com.casic + casic-iris-support + ${pro.version} + + + + org.apache.httpcomponents + httpclient + 4.5.3 + + + + org.apache.httpcomponents + httpcore + 4.4.8 + + + + org.apache.httpcomponents + httpmime + 4.5.3 + + + + com.google.code.gson + gson + + + + + + + + src/main/java + + **/*.xml + + + + + \ No newline at end of file diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/constant/FaceSyncConst.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/constant/FaceSyncConst.java new file mode 100644 index 0000000..352d47d --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/constant/FaceSyncConst.java @@ -0,0 +1,29 @@ +package com.casic.missiles.modular.system.constant; + +public class FaceSyncConst { + + /** + * 单次最大批量上传人员数 + */ + public static final int UPLOAD_MAX_PERSON = 6; + + /** + * 上传人员库 + */ + public static final String UPLOAD_STAFF_LIB = "3"; + public static final String UPLOAD_VISITOR_LIB = "4"; + + public static final String UPLOAD_URL_PREFIX = "/LAPI/V1.0/PeopleLibraries/"; + + public static final String UPLOAD_URL_SUFFIX = "/People"; + + public static final int UPLOAD_PERSONCODE_MAXLENGTH = 15; + + public static final int UPLOAD_REMARK_MAXLENGTH = 63; + + public static final String SUBSCRIBE_URL = "/LAPI/V1.0/System/Event/Subscription/"; + + public static final String STAFF_PERSON_TYPE = "1"; + + public static final String VISITOR_PERSON_TYPE = "0"; +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/controller/FaceSyncController.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/controller/FaceSyncController.java new file mode 100644 index 0000000..1b35431 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/controller/FaceSyncController.java @@ -0,0 +1,117 @@ +package com.casic.missiles.modular.system.controller; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson.serializer.SerializerFeature; +import com.casic.missiles.core.base.response.ResponseData; +import com.casic.missiles.core.common.service.ICommonPermissionService; +import com.casic.missiles.core.common.service.ICommonPersonService; +import com.casic.missiles.core.datascope.DataScope; +import com.casic.missiles.core.util.ToolUtil; +import com.casic.missiles.modular.system.request.PersonInfo; +import com.casic.missiles.modular.system.response.RecordNotification; +import com.casic.missiles.modular.system.service.IFaceSyncService; +import com.casic.missiles.modular.system.service.IIrisPersonSupportService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.*; +import com.casic.missiles.modular.system.constant.FaceSyncConst; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + + + +@Controller +public class FaceSyncController { + private final static Logger logger = LoggerFactory.getLogger(FaceSyncController.class); + + @Autowired + private IFaceSyncService syncService; + @Autowired + private ICommonPersonService commonPersonService; + @Autowired + private IIrisPersonSupportService personSupportService; + @Autowired + private ICommonPermissionService permissionService; + + @RequestMapping("/face/upload") + @ResponseBody + public Object upload(@RequestParam("personIds") List personIds, + @RequestParam("deviceIds") List deviceIds, + @RequestParam("personType")String personType ){ + // 检查数量 +// if(personIds.size()>FaceSyncConst.UPLOAD_MAX_PERSON){ +// return ResponseData.error(String.format("每次最多上传%s个人",FaceSyncConst.UPLOAD_MAX_PERSON)); +// } + // 检查照片格式及大小 + String photoCheck = syncService.checkPersonPhoto(personIds); + if(ToolUtil.isNotEmpty(photoCheck)){ + return ResponseData.error(photoCheck); + } + else{ + // 上传数据 + String error = syncService.uploadPerson(personIds,deviceIds,personType); + if(ToolUtil.isNotEmpty(error)){ + return ResponseData.error(error); + } + } + return ResponseData.success(); + } + + @RequestMapping("/face/uploadAll") + @ResponseBody + public Object uploadAll(@RequestParam("deviceIds") List deviceIds){ + DataScope dataScope = permissionService.getCurrUserDataScope(); + + List staffPersonIds = personSupportService.listIdsByType(dataScope,FaceSyncConst.STAFF_PERSON_TYPE); + List visitorPersonIds = personSupportService.listIdsByType(dataScope,FaceSyncConst.VISITOR_PERSON_TYPE); + // 1.检查照片,分别检查员工、访客 + String staffPhotoCheck = syncService.checkPersonPhoto(staffPersonIds); + if(ToolUtil.isNotEmpty(staffPhotoCheck)){ + return ResponseData.error(staffPhotoCheck); + } + String visitorPhotoCheck = syncService.checkPersonPhoto(visitorPersonIds); + if(ToolUtil.isNotEmpty(visitorPhotoCheck)){ + return ResponseData.error(visitorPhotoCheck); + } + + // 2. 下发数据 + String staffError = syncService.uploadPerson(staffPersonIds,deviceIds,FaceSyncConst.STAFF_PERSON_TYPE); + if(ToolUtil.isNotEmpty(staffError)){ + return ResponseData.error(staffError); + } + String visitorError = syncService.uploadPerson(visitorPersonIds,deviceIds,FaceSyncConst.VISITOR_PERSON_TYPE); + if(ToolUtil.isNotEmpty(visitorError)){ + return ResponseData.error(visitorError); + } + + return ResponseData.success(); + } + + // 错误信息返回 + @RequestMapping("/subsrcibe/init") + @ResponseBody + public Object upload(@RequestParam("deviceIds") List deviceIds){ + String errorMsg = syncService.initSubscription(deviceIds); + if(ToolUtil.isNotEmpty(errorMsg)){ + return ResponseData.error(errorMsg); + } + return ResponseData.success(); + } + + + @RequestMapping(value = "/LAPI/V1.0/System/Event/Notification/PersonVerification", method = RequestMethod.POST) + @ResponseBody + public void verification(@RequestBody String recordNotification){ + logger.info(recordNotification); + RecordNotification record = JSONObject.parseObject(recordNotification,RecordNotification.class); + syncService.receiveRecord(record); + //return ResponseData.success(); + } + + +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FacePersonSyncMapper.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FacePersonSyncMapper.java new file mode 100644 index 0000000..af53702 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FacePersonSyncMapper.java @@ -0,0 +1,17 @@ +package com.casic.missiles.modular.system.dao; + +import com.casic.missiles.modular.system.model.FacePersonSync; +import com.baomidou.mybatisplus.mapper.BaseMapper; + +/** + *

+ * Mapper 接口 + *

+ * + * @author zyj123 + * @since 2020-07-24 + */ +public interface FacePersonSyncMapper extends BaseMapper { + + Long getMaxSyncId(); +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FaceSubscribeMapper.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FaceSubscribeMapper.java new file mode 100644 index 0000000..0c6374a --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FaceSubscribeMapper.java @@ -0,0 +1,16 @@ +package com.casic.missiles.modular.system.dao; + +import com.casic.missiles.modular.system.model.FaceSubscribe; +import com.baomidou.mybatisplus.mapper.BaseMapper; + +/** + *

+ * Mapper 接口 + *

+ * + * @author zyj123 + * @since 2020-07-25 + */ +public interface FaceSubscribeMapper extends BaseMapper { + +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FacePersonSyncMapper.xml b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FacePersonSyncMapper.xml new file mode 100644 index 0000000..ac46ad0 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FacePersonSyncMapper.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + PERSON_ID AS personId, SYNC_ID AS syncId + + + + + diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FaceSubscribeMapper.xml b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FaceSubscribeMapper.xml new file mode 100644 index 0000000..16024e2 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FaceSubscribeMapper.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + SUBSCRIBE_ID AS subscribeId, DEVICE_CODE AS deviceCode, UPDATE_TIME AS updateTime + + + diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FacePersonSync.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FacePersonSync.java new file mode 100644 index 0000000..7cdb821 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FacePersonSync.java @@ -0,0 +1,68 @@ +package com.casic.missiles.modular.system.model; + +import java.io.Serializable; + +import com.baomidou.mybatisplus.annotations.TableId; +import com.baomidou.mybatisplus.annotations.TableField; +import com.baomidou.mybatisplus.activerecord.Model; +import com.baomidou.mybatisplus.annotations.TableName; +import java.io.Serializable; + +/** + *

+ * + *

+ * + * @author zyj123 + * @since 2020-07-24 + */ +@TableName("face_person_sync") +public class FacePersonSync extends Model { + + private static final long serialVersionUID = 1L; + + /** + * 人员id + */ + @TableId("PERSON_ID") + private Long personId; + /** + * 人员同步id + */ + @TableField("SYNC_ID") + private Long syncId; + + public FacePersonSync(Long personId, Long syncId) { + this.personId = personId; + this.syncId = syncId; + } + + public Long getPersonId() { + return personId; + } + + public void setPersonId(Long personId) { + this.personId = personId; + } + + public Long getSyncId() { + return syncId; + } + + public void setSyncId(Long syncId) { + this.syncId = syncId; + } + + @Override + protected Serializable pkVal() { + return this.personId; + } + + @Override + public String toString() { + return "FacePersonSync{" + + "personId=" + personId + + ", syncId=" + syncId + + "}"; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FaceSubscribe.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FaceSubscribe.java new file mode 100644 index 0000000..ccc7792 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FaceSubscribe.java @@ -0,0 +1,79 @@ +package com.casic.missiles.modular.system.model; + +import java.io.Serializable; + +import java.util.Date; +import com.baomidou.mybatisplus.annotations.TableId; +import com.baomidou.mybatisplus.annotations.TableField; +import com.baomidou.mybatisplus.activerecord.Model; +import com.baomidou.mybatisplus.annotations.TableName; +import java.io.Serializable; + +/** + *

+ * + *

+ * + * @author zyj123 + * @since 2020-07-25 + */ +@TableName("face_subscribe") +public class FaceSubscribe extends Model { + + private static final long serialVersionUID = 1L; + + /** + * 订阅id + */ + @TableId("SUBSCRIBE_ID") + private Long subscribeId; + /** + * 设备编号 + */ + @TableField("DEVICE_CODE") + private String deviceCode; + /** + * 更新时间 + */ + @TableField("UPDATE_TIME") + private Date updateTime; + + + public Long getSubscribeId() { + return subscribeId; + } + + public void setSubscribeId(Long subscribeId) { + this.subscribeId = subscribeId; + } + + public String getDeviceCode() { + return deviceCode; + } + + public void setDeviceCode(String deviceCode) { + this.deviceCode = deviceCode; + } + + public Date getUpdateTime() { + return updateTime; + } + + public void setUpdateTime(Date updateTime) { + this.updateTime = updateTime; + } + + @Override + protected Serializable pkVal() { + return this.subscribeId; + } + + @Override + public String toString() { + return "FaceSubscribe{" + + "subscribeId=" + subscribeId + + ", deviceCode=" + deviceCode + + ", updateTime=" + updateTime + + "}"; + } +} diff --git a/casic-face-sync/pom.xml b/casic-face-sync/pom.xml new file mode 100644 index 0000000..24dc884 --- /dev/null +++ b/casic-face-sync/pom.xml @@ -0,0 +1,74 @@ + + + 4.0.0 + + com.casic + casic-iris-parent + 1.0.0-SNAPSHOT + ../pom.xml + + + + casic-face-sync + ${pro.version} + jar + casic-face-sync + + + + + + com.casic + casic-core + ${core.version} + + + + com.casic + casic-admin-support + ${admin.version} + + + com.casic + casic-iris-support + ${pro.version} + + + + org.apache.httpcomponents + httpclient + 4.5.3 + + + + org.apache.httpcomponents + httpcore + 4.4.8 + + + + org.apache.httpcomponents + httpmime + 4.5.3 + + + + com.google.code.gson + gson + + + + + + + + src/main/java + + **/*.xml + + + + + \ No newline at end of file diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/constant/FaceSyncConst.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/constant/FaceSyncConst.java new file mode 100644 index 0000000..352d47d --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/constant/FaceSyncConst.java @@ -0,0 +1,29 @@ +package com.casic.missiles.modular.system.constant; + +public class FaceSyncConst { + + /** + * 单次最大批量上传人员数 + */ + public static final int UPLOAD_MAX_PERSON = 6; + + /** + * 上传人员库 + */ + public static final String UPLOAD_STAFF_LIB = "3"; + public static final String UPLOAD_VISITOR_LIB = "4"; + + public static final String UPLOAD_URL_PREFIX = "/LAPI/V1.0/PeopleLibraries/"; + + public static final String UPLOAD_URL_SUFFIX = "/People"; + + public static final int UPLOAD_PERSONCODE_MAXLENGTH = 15; + + public static final int UPLOAD_REMARK_MAXLENGTH = 63; + + public static final String SUBSCRIBE_URL = "/LAPI/V1.0/System/Event/Subscription/"; + + public static final String STAFF_PERSON_TYPE = "1"; + + public static final String VISITOR_PERSON_TYPE = "0"; +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/controller/FaceSyncController.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/controller/FaceSyncController.java new file mode 100644 index 0000000..1b35431 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/controller/FaceSyncController.java @@ -0,0 +1,117 @@ +package com.casic.missiles.modular.system.controller; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson.serializer.SerializerFeature; +import com.casic.missiles.core.base.response.ResponseData; +import com.casic.missiles.core.common.service.ICommonPermissionService; +import com.casic.missiles.core.common.service.ICommonPersonService; +import com.casic.missiles.core.datascope.DataScope; +import com.casic.missiles.core.util.ToolUtil; +import com.casic.missiles.modular.system.request.PersonInfo; +import com.casic.missiles.modular.system.response.RecordNotification; +import com.casic.missiles.modular.system.service.IFaceSyncService; +import com.casic.missiles.modular.system.service.IIrisPersonSupportService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.*; +import com.casic.missiles.modular.system.constant.FaceSyncConst; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + + + +@Controller +public class FaceSyncController { + private final static Logger logger = LoggerFactory.getLogger(FaceSyncController.class); + + @Autowired + private IFaceSyncService syncService; + @Autowired + private ICommonPersonService commonPersonService; + @Autowired + private IIrisPersonSupportService personSupportService; + @Autowired + private ICommonPermissionService permissionService; + + @RequestMapping("/face/upload") + @ResponseBody + public Object upload(@RequestParam("personIds") List personIds, + @RequestParam("deviceIds") List deviceIds, + @RequestParam("personType")String personType ){ + // 检查数量 +// if(personIds.size()>FaceSyncConst.UPLOAD_MAX_PERSON){ +// return ResponseData.error(String.format("每次最多上传%s个人",FaceSyncConst.UPLOAD_MAX_PERSON)); +// } + // 检查照片格式及大小 + String photoCheck = syncService.checkPersonPhoto(personIds); + if(ToolUtil.isNotEmpty(photoCheck)){ + return ResponseData.error(photoCheck); + } + else{ + // 上传数据 + String error = syncService.uploadPerson(personIds,deviceIds,personType); + if(ToolUtil.isNotEmpty(error)){ + return ResponseData.error(error); + } + } + return ResponseData.success(); + } + + @RequestMapping("/face/uploadAll") + @ResponseBody + public Object uploadAll(@RequestParam("deviceIds") List deviceIds){ + DataScope dataScope = permissionService.getCurrUserDataScope(); + + List staffPersonIds = personSupportService.listIdsByType(dataScope,FaceSyncConst.STAFF_PERSON_TYPE); + List visitorPersonIds = personSupportService.listIdsByType(dataScope,FaceSyncConst.VISITOR_PERSON_TYPE); + // 1.检查照片,分别检查员工、访客 + String staffPhotoCheck = syncService.checkPersonPhoto(staffPersonIds); + if(ToolUtil.isNotEmpty(staffPhotoCheck)){ + return ResponseData.error(staffPhotoCheck); + } + String visitorPhotoCheck = syncService.checkPersonPhoto(visitorPersonIds); + if(ToolUtil.isNotEmpty(visitorPhotoCheck)){ + return ResponseData.error(visitorPhotoCheck); + } + + // 2. 下发数据 + String staffError = syncService.uploadPerson(staffPersonIds,deviceIds,FaceSyncConst.STAFF_PERSON_TYPE); + if(ToolUtil.isNotEmpty(staffError)){ + return ResponseData.error(staffError); + } + String visitorError = syncService.uploadPerson(visitorPersonIds,deviceIds,FaceSyncConst.VISITOR_PERSON_TYPE); + if(ToolUtil.isNotEmpty(visitorError)){ + return ResponseData.error(visitorError); + } + + return ResponseData.success(); + } + + // 错误信息返回 + @RequestMapping("/subsrcibe/init") + @ResponseBody + public Object upload(@RequestParam("deviceIds") List deviceIds){ + String errorMsg = syncService.initSubscription(deviceIds); + if(ToolUtil.isNotEmpty(errorMsg)){ + return ResponseData.error(errorMsg); + } + return ResponseData.success(); + } + + + @RequestMapping(value = "/LAPI/V1.0/System/Event/Notification/PersonVerification", method = RequestMethod.POST) + @ResponseBody + public void verification(@RequestBody String recordNotification){ + logger.info(recordNotification); + RecordNotification record = JSONObject.parseObject(recordNotification,RecordNotification.class); + syncService.receiveRecord(record); + //return ResponseData.success(); + } + + +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FacePersonSyncMapper.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FacePersonSyncMapper.java new file mode 100644 index 0000000..af53702 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FacePersonSyncMapper.java @@ -0,0 +1,17 @@ +package com.casic.missiles.modular.system.dao; + +import com.casic.missiles.modular.system.model.FacePersonSync; +import com.baomidou.mybatisplus.mapper.BaseMapper; + +/** + *

+ * Mapper 接口 + *

+ * + * @author zyj123 + * @since 2020-07-24 + */ +public interface FacePersonSyncMapper extends BaseMapper { + + Long getMaxSyncId(); +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FaceSubscribeMapper.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FaceSubscribeMapper.java new file mode 100644 index 0000000..0c6374a --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FaceSubscribeMapper.java @@ -0,0 +1,16 @@ +package com.casic.missiles.modular.system.dao; + +import com.casic.missiles.modular.system.model.FaceSubscribe; +import com.baomidou.mybatisplus.mapper.BaseMapper; + +/** + *

+ * Mapper 接口 + *

+ * + * @author zyj123 + * @since 2020-07-25 + */ +public interface FaceSubscribeMapper extends BaseMapper { + +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FacePersonSyncMapper.xml b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FacePersonSyncMapper.xml new file mode 100644 index 0000000..ac46ad0 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FacePersonSyncMapper.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + PERSON_ID AS personId, SYNC_ID AS syncId + + + + + diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FaceSubscribeMapper.xml b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FaceSubscribeMapper.xml new file mode 100644 index 0000000..16024e2 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FaceSubscribeMapper.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + SUBSCRIBE_ID AS subscribeId, DEVICE_CODE AS deviceCode, UPDATE_TIME AS updateTime + + + diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FacePersonSync.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FacePersonSync.java new file mode 100644 index 0000000..7cdb821 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FacePersonSync.java @@ -0,0 +1,68 @@ +package com.casic.missiles.modular.system.model; + +import java.io.Serializable; + +import com.baomidou.mybatisplus.annotations.TableId; +import com.baomidou.mybatisplus.annotations.TableField; +import com.baomidou.mybatisplus.activerecord.Model; +import com.baomidou.mybatisplus.annotations.TableName; +import java.io.Serializable; + +/** + *

+ * + *

+ * + * @author zyj123 + * @since 2020-07-24 + */ +@TableName("face_person_sync") +public class FacePersonSync extends Model { + + private static final long serialVersionUID = 1L; + + /** + * 人员id + */ + @TableId("PERSON_ID") + private Long personId; + /** + * 人员同步id + */ + @TableField("SYNC_ID") + private Long syncId; + + public FacePersonSync(Long personId, Long syncId) { + this.personId = personId; + this.syncId = syncId; + } + + public Long getPersonId() { + return personId; + } + + public void setPersonId(Long personId) { + this.personId = personId; + } + + public Long getSyncId() { + return syncId; + } + + public void setSyncId(Long syncId) { + this.syncId = syncId; + } + + @Override + protected Serializable pkVal() { + return this.personId; + } + + @Override + public String toString() { + return "FacePersonSync{" + + "personId=" + personId + + ", syncId=" + syncId + + "}"; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FaceSubscribe.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FaceSubscribe.java new file mode 100644 index 0000000..ccc7792 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FaceSubscribe.java @@ -0,0 +1,79 @@ +package com.casic.missiles.modular.system.model; + +import java.io.Serializable; + +import java.util.Date; +import com.baomidou.mybatisplus.annotations.TableId; +import com.baomidou.mybatisplus.annotations.TableField; +import com.baomidou.mybatisplus.activerecord.Model; +import com.baomidou.mybatisplus.annotations.TableName; +import java.io.Serializable; + +/** + *

+ * + *

+ * + * @author zyj123 + * @since 2020-07-25 + */ +@TableName("face_subscribe") +public class FaceSubscribe extends Model { + + private static final long serialVersionUID = 1L; + + /** + * 订阅id + */ + @TableId("SUBSCRIBE_ID") + private Long subscribeId; + /** + * 设备编号 + */ + @TableField("DEVICE_CODE") + private String deviceCode; + /** + * 更新时间 + */ + @TableField("UPDATE_TIME") + private Date updateTime; + + + public Long getSubscribeId() { + return subscribeId; + } + + public void setSubscribeId(Long subscribeId) { + this.subscribeId = subscribeId; + } + + public String getDeviceCode() { + return deviceCode; + } + + public void setDeviceCode(String deviceCode) { + this.deviceCode = deviceCode; + } + + public Date getUpdateTime() { + return updateTime; + } + + public void setUpdateTime(Date updateTime) { + this.updateTime = updateTime; + } + + @Override + protected Serializable pkVal() { + return this.subscribeId; + } + + @Override + public String toString() { + return "FaceSubscribe{" + + "subscribeId=" + subscribeId + + ", deviceCode=" + deviceCode + + ", updateTime=" + updateTime + + "}"; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/request/PersonInfo.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/request/PersonInfo.java new file mode 100644 index 0000000..80d9eff --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/request/PersonInfo.java @@ -0,0 +1,271 @@ +package com.casic.missiles.modular.system.request; + +import com.alibaba.fastjson.annotation.JSONField; +import com.baomidou.mybatisplus.annotations.TableField; +import com.google.gson.annotations.SerializedName; + +import java.util.List; + +public class PersonInfo { + + //@JSONField(name = "PersonID") + @SerializedName("PersonID") + private Long personID; + + //@JSONField(name = "LastChange") + @SerializedName("LastChange") + private Long lastChange; + + //@JSONField(name = "PersonCode") + @SerializedName("PersonCode") + private String personCode; + + //@JSONField(name = "PersonName") + @SerializedName("PersonName") + private String personName; + + //@JSONField(name = "Remarks") + @SerializedName("Remarks") + private String remarks; + + //@JSONField(name = "TimeTemplateNum") + @SerializedName("TimeTemplateNum") + private Integer timeTemplateNum; + + //@JSONField(name = "TimeTemplateList") + @SerializedName("TimeTemplateList") + private List timeTemplateList; + + //@JSONField(name = "IdentificationNum") + @SerializedName("IdentificationNum") + private Integer identificationNum; + + //@JSONField(name = "IdentificationList") + @SerializedName("IdentificationList") + private List identificationList; + + //@JSONField(name = "ImageNum") + @SerializedName("ImageNum") + private Integer imageNum; + + //@JSONField(name = "ImageList") + @SerializedName("ImageList") + private List imageList; + + public Long getPersonID() { + return personID; + } + + public void setPersonID(Long personID) { + this.personID = personID; + } + + public Long getLastChange() { + return lastChange; + } + + public void setLastChange(Long lastChange) { + this.lastChange = lastChange; + } + + public String getPersonCode() { + return personCode; + } + + public void setPersonCode(String personCode) { + this.personCode = personCode; + } + + public String getPersonName() { + return personName; + } + + public void setPersonName(String personName) { + this.personName = personName; + } + + public String getRemarks() { + return remarks; + } + + public void setRemarks(String remarks) { + this.remarks = remarks; + } + + public Integer getTimeTemplateNum() { + return timeTemplateNum; + } + + public void setTimeTemplateNum(Integer timeTemplateNum) { + this.timeTemplateNum = timeTemplateNum; + } + + public List getTimeTemplateList() { + return timeTemplateList; + } + + public void setTimeTemplateList(List timeTemplateList) { + this.timeTemplateList = timeTemplateList; + } + + public Integer getIdentificationNum() { + return identificationNum; + } + + public void setIdentificationNum(Integer identificationNum) { + this.identificationNum = identificationNum; + } + + public List getIdentificationList() { + return identificationList; + } + + public void setIdentificationList(List identificationList) { + this.identificationList = identificationList; + } + + public Integer getImageNum() { + return imageNum; + } + + public void setImageNum(Integer imageNum) { + this.imageNum = imageNum; + } + + public List getImageList() { + return imageList; + } + + public void setImageList(List imageList) { + this.imageList = imageList; + } + + public class TimeTemplate{ + @JSONField(name = "BeginTime") + private Long beginTime; + @JSONField(name = "EndTime") + private Long endTime; + @JSONField(name = "Index") + private Long index; + + public TimeTemplate(Long beginTime, Long endTime, Long index) { + this.beginTime = beginTime; + this.endTime = endTime; + this.index = index; + } + + public Long getBeginTime() { + return beginTime; + } + + public void setBeginTime(Long beginTime) { + this.beginTime = beginTime; + } + + public Long getEndTime() { + return endTime; + } + + public void setEndTime(Long endTime) { + this.endTime = endTime; + } + + public Long getIndex() { + return index; + } + + public void setIndex(Long index) { + this.index = index; + } + } + + public TimeTemplate createTimeTemplate(Long beginTime, Long endTime, Long index){ + return new TimeTemplate(beginTime, endTime, index); + } + + public class IdentificationInfo { + @JSONField(name = "Type") + private Integer type; + @JSONField(name = "Number") + private String number; + + public IdentificationInfo(Integer type, String number) { + this.type = type; + this.number = number; + } + + public Integer getType() { + return type; + } + + public void setType(Integer type) { + this.type = type; + } + + public String getNumber() { + return number; + } + + public void setNumber(String number) { + this.number = number; + } + } + + public IdentificationInfo createIdentificationInfo(Integer type, String number){ + return new IdentificationInfo(type,number); + } + + public class ImageInfo{ + @JSONField(name = "FaceID") + private Long faceID; + @JSONField(name = "Name") + private String name; + @JSONField(name = "Size") + private Long size; + @JSONField(name = "Data") + private String data; + + public ImageInfo(Long faceID, String name, Long size, String data) { + this.faceID = faceID; + this.name = name; + this.size = size; + this.data = data; + } + + public Long getFaceID() { + return faceID; + } + + public void setFaceID(Long faceID) { + this.faceID = faceID; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Long getSize() { + return size; + } + + public void setSize(Long size) { + this.size = size; + } + + public String getData() { + return data; + } + + public void setData(String data) { + this.data = data; + } + } + + public ImageInfo createImageInfo(Long faceID, String name, Long size, String data){ + return new ImageInfo(faceID, name, size, data); + } +} diff --git a/casic-face-sync/pom.xml b/casic-face-sync/pom.xml new file mode 100644 index 0000000..24dc884 --- /dev/null +++ b/casic-face-sync/pom.xml @@ -0,0 +1,74 @@ + + + 4.0.0 + + com.casic + casic-iris-parent + 1.0.0-SNAPSHOT + ../pom.xml + + + + casic-face-sync + ${pro.version} + jar + casic-face-sync + + + + + + com.casic + casic-core + ${core.version} + + + + com.casic + casic-admin-support + ${admin.version} + + + com.casic + casic-iris-support + ${pro.version} + + + + org.apache.httpcomponents + httpclient + 4.5.3 + + + + org.apache.httpcomponents + httpcore + 4.4.8 + + + + org.apache.httpcomponents + httpmime + 4.5.3 + + + + com.google.code.gson + gson + + + + + + + + src/main/java + + **/*.xml + + + + + \ No newline at end of file diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/constant/FaceSyncConst.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/constant/FaceSyncConst.java new file mode 100644 index 0000000..352d47d --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/constant/FaceSyncConst.java @@ -0,0 +1,29 @@ +package com.casic.missiles.modular.system.constant; + +public class FaceSyncConst { + + /** + * 单次最大批量上传人员数 + */ + public static final int UPLOAD_MAX_PERSON = 6; + + /** + * 上传人员库 + */ + public static final String UPLOAD_STAFF_LIB = "3"; + public static final String UPLOAD_VISITOR_LIB = "4"; + + public static final String UPLOAD_URL_PREFIX = "/LAPI/V1.0/PeopleLibraries/"; + + public static final String UPLOAD_URL_SUFFIX = "/People"; + + public static final int UPLOAD_PERSONCODE_MAXLENGTH = 15; + + public static final int UPLOAD_REMARK_MAXLENGTH = 63; + + public static final String SUBSCRIBE_URL = "/LAPI/V1.0/System/Event/Subscription/"; + + public static final String STAFF_PERSON_TYPE = "1"; + + public static final String VISITOR_PERSON_TYPE = "0"; +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/controller/FaceSyncController.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/controller/FaceSyncController.java new file mode 100644 index 0000000..1b35431 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/controller/FaceSyncController.java @@ -0,0 +1,117 @@ +package com.casic.missiles.modular.system.controller; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson.serializer.SerializerFeature; +import com.casic.missiles.core.base.response.ResponseData; +import com.casic.missiles.core.common.service.ICommonPermissionService; +import com.casic.missiles.core.common.service.ICommonPersonService; +import com.casic.missiles.core.datascope.DataScope; +import com.casic.missiles.core.util.ToolUtil; +import com.casic.missiles.modular.system.request.PersonInfo; +import com.casic.missiles.modular.system.response.RecordNotification; +import com.casic.missiles.modular.system.service.IFaceSyncService; +import com.casic.missiles.modular.system.service.IIrisPersonSupportService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.*; +import com.casic.missiles.modular.system.constant.FaceSyncConst; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + + + +@Controller +public class FaceSyncController { + private final static Logger logger = LoggerFactory.getLogger(FaceSyncController.class); + + @Autowired + private IFaceSyncService syncService; + @Autowired + private ICommonPersonService commonPersonService; + @Autowired + private IIrisPersonSupportService personSupportService; + @Autowired + private ICommonPermissionService permissionService; + + @RequestMapping("/face/upload") + @ResponseBody + public Object upload(@RequestParam("personIds") List personIds, + @RequestParam("deviceIds") List deviceIds, + @RequestParam("personType")String personType ){ + // 检查数量 +// if(personIds.size()>FaceSyncConst.UPLOAD_MAX_PERSON){ +// return ResponseData.error(String.format("每次最多上传%s个人",FaceSyncConst.UPLOAD_MAX_PERSON)); +// } + // 检查照片格式及大小 + String photoCheck = syncService.checkPersonPhoto(personIds); + if(ToolUtil.isNotEmpty(photoCheck)){ + return ResponseData.error(photoCheck); + } + else{ + // 上传数据 + String error = syncService.uploadPerson(personIds,deviceIds,personType); + if(ToolUtil.isNotEmpty(error)){ + return ResponseData.error(error); + } + } + return ResponseData.success(); + } + + @RequestMapping("/face/uploadAll") + @ResponseBody + public Object uploadAll(@RequestParam("deviceIds") List deviceIds){ + DataScope dataScope = permissionService.getCurrUserDataScope(); + + List staffPersonIds = personSupportService.listIdsByType(dataScope,FaceSyncConst.STAFF_PERSON_TYPE); + List visitorPersonIds = personSupportService.listIdsByType(dataScope,FaceSyncConst.VISITOR_PERSON_TYPE); + // 1.检查照片,分别检查员工、访客 + String staffPhotoCheck = syncService.checkPersonPhoto(staffPersonIds); + if(ToolUtil.isNotEmpty(staffPhotoCheck)){ + return ResponseData.error(staffPhotoCheck); + } + String visitorPhotoCheck = syncService.checkPersonPhoto(visitorPersonIds); + if(ToolUtil.isNotEmpty(visitorPhotoCheck)){ + return ResponseData.error(visitorPhotoCheck); + } + + // 2. 下发数据 + String staffError = syncService.uploadPerson(staffPersonIds,deviceIds,FaceSyncConst.STAFF_PERSON_TYPE); + if(ToolUtil.isNotEmpty(staffError)){ + return ResponseData.error(staffError); + } + String visitorError = syncService.uploadPerson(visitorPersonIds,deviceIds,FaceSyncConst.VISITOR_PERSON_TYPE); + if(ToolUtil.isNotEmpty(visitorError)){ + return ResponseData.error(visitorError); + } + + return ResponseData.success(); + } + + // 错误信息返回 + @RequestMapping("/subsrcibe/init") + @ResponseBody + public Object upload(@RequestParam("deviceIds") List deviceIds){ + String errorMsg = syncService.initSubscription(deviceIds); + if(ToolUtil.isNotEmpty(errorMsg)){ + return ResponseData.error(errorMsg); + } + return ResponseData.success(); + } + + + @RequestMapping(value = "/LAPI/V1.0/System/Event/Notification/PersonVerification", method = RequestMethod.POST) + @ResponseBody + public void verification(@RequestBody String recordNotification){ + logger.info(recordNotification); + RecordNotification record = JSONObject.parseObject(recordNotification,RecordNotification.class); + syncService.receiveRecord(record); + //return ResponseData.success(); + } + + +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FacePersonSyncMapper.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FacePersonSyncMapper.java new file mode 100644 index 0000000..af53702 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FacePersonSyncMapper.java @@ -0,0 +1,17 @@ +package com.casic.missiles.modular.system.dao; + +import com.casic.missiles.modular.system.model.FacePersonSync; +import com.baomidou.mybatisplus.mapper.BaseMapper; + +/** + *

+ * Mapper 接口 + *

+ * + * @author zyj123 + * @since 2020-07-24 + */ +public interface FacePersonSyncMapper extends BaseMapper { + + Long getMaxSyncId(); +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FaceSubscribeMapper.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FaceSubscribeMapper.java new file mode 100644 index 0000000..0c6374a --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FaceSubscribeMapper.java @@ -0,0 +1,16 @@ +package com.casic.missiles.modular.system.dao; + +import com.casic.missiles.modular.system.model.FaceSubscribe; +import com.baomidou.mybatisplus.mapper.BaseMapper; + +/** + *

+ * Mapper 接口 + *

+ * + * @author zyj123 + * @since 2020-07-25 + */ +public interface FaceSubscribeMapper extends BaseMapper { + +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FacePersonSyncMapper.xml b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FacePersonSyncMapper.xml new file mode 100644 index 0000000..ac46ad0 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FacePersonSyncMapper.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + PERSON_ID AS personId, SYNC_ID AS syncId + + + + + diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FaceSubscribeMapper.xml b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FaceSubscribeMapper.xml new file mode 100644 index 0000000..16024e2 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FaceSubscribeMapper.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + SUBSCRIBE_ID AS subscribeId, DEVICE_CODE AS deviceCode, UPDATE_TIME AS updateTime + + + diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FacePersonSync.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FacePersonSync.java new file mode 100644 index 0000000..7cdb821 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FacePersonSync.java @@ -0,0 +1,68 @@ +package com.casic.missiles.modular.system.model; + +import java.io.Serializable; + +import com.baomidou.mybatisplus.annotations.TableId; +import com.baomidou.mybatisplus.annotations.TableField; +import com.baomidou.mybatisplus.activerecord.Model; +import com.baomidou.mybatisplus.annotations.TableName; +import java.io.Serializable; + +/** + *

+ * + *

+ * + * @author zyj123 + * @since 2020-07-24 + */ +@TableName("face_person_sync") +public class FacePersonSync extends Model { + + private static final long serialVersionUID = 1L; + + /** + * 人员id + */ + @TableId("PERSON_ID") + private Long personId; + /** + * 人员同步id + */ + @TableField("SYNC_ID") + private Long syncId; + + public FacePersonSync(Long personId, Long syncId) { + this.personId = personId; + this.syncId = syncId; + } + + public Long getPersonId() { + return personId; + } + + public void setPersonId(Long personId) { + this.personId = personId; + } + + public Long getSyncId() { + return syncId; + } + + public void setSyncId(Long syncId) { + this.syncId = syncId; + } + + @Override + protected Serializable pkVal() { + return this.personId; + } + + @Override + public String toString() { + return "FacePersonSync{" + + "personId=" + personId + + ", syncId=" + syncId + + "}"; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FaceSubscribe.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FaceSubscribe.java new file mode 100644 index 0000000..ccc7792 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FaceSubscribe.java @@ -0,0 +1,79 @@ +package com.casic.missiles.modular.system.model; + +import java.io.Serializable; + +import java.util.Date; +import com.baomidou.mybatisplus.annotations.TableId; +import com.baomidou.mybatisplus.annotations.TableField; +import com.baomidou.mybatisplus.activerecord.Model; +import com.baomidou.mybatisplus.annotations.TableName; +import java.io.Serializable; + +/** + *

+ * + *

+ * + * @author zyj123 + * @since 2020-07-25 + */ +@TableName("face_subscribe") +public class FaceSubscribe extends Model { + + private static final long serialVersionUID = 1L; + + /** + * 订阅id + */ + @TableId("SUBSCRIBE_ID") + private Long subscribeId; + /** + * 设备编号 + */ + @TableField("DEVICE_CODE") + private String deviceCode; + /** + * 更新时间 + */ + @TableField("UPDATE_TIME") + private Date updateTime; + + + public Long getSubscribeId() { + return subscribeId; + } + + public void setSubscribeId(Long subscribeId) { + this.subscribeId = subscribeId; + } + + public String getDeviceCode() { + return deviceCode; + } + + public void setDeviceCode(String deviceCode) { + this.deviceCode = deviceCode; + } + + public Date getUpdateTime() { + return updateTime; + } + + public void setUpdateTime(Date updateTime) { + this.updateTime = updateTime; + } + + @Override + protected Serializable pkVal() { + return this.subscribeId; + } + + @Override + public String toString() { + return "FaceSubscribe{" + + "subscribeId=" + subscribeId + + ", deviceCode=" + deviceCode + + ", updateTime=" + updateTime + + "}"; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/request/PersonInfo.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/request/PersonInfo.java new file mode 100644 index 0000000..80d9eff --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/request/PersonInfo.java @@ -0,0 +1,271 @@ +package com.casic.missiles.modular.system.request; + +import com.alibaba.fastjson.annotation.JSONField; +import com.baomidou.mybatisplus.annotations.TableField; +import com.google.gson.annotations.SerializedName; + +import java.util.List; + +public class PersonInfo { + + //@JSONField(name = "PersonID") + @SerializedName("PersonID") + private Long personID; + + //@JSONField(name = "LastChange") + @SerializedName("LastChange") + private Long lastChange; + + //@JSONField(name = "PersonCode") + @SerializedName("PersonCode") + private String personCode; + + //@JSONField(name = "PersonName") + @SerializedName("PersonName") + private String personName; + + //@JSONField(name = "Remarks") + @SerializedName("Remarks") + private String remarks; + + //@JSONField(name = "TimeTemplateNum") + @SerializedName("TimeTemplateNum") + private Integer timeTemplateNum; + + //@JSONField(name = "TimeTemplateList") + @SerializedName("TimeTemplateList") + private List timeTemplateList; + + //@JSONField(name = "IdentificationNum") + @SerializedName("IdentificationNum") + private Integer identificationNum; + + //@JSONField(name = "IdentificationList") + @SerializedName("IdentificationList") + private List identificationList; + + //@JSONField(name = "ImageNum") + @SerializedName("ImageNum") + private Integer imageNum; + + //@JSONField(name = "ImageList") + @SerializedName("ImageList") + private List imageList; + + public Long getPersonID() { + return personID; + } + + public void setPersonID(Long personID) { + this.personID = personID; + } + + public Long getLastChange() { + return lastChange; + } + + public void setLastChange(Long lastChange) { + this.lastChange = lastChange; + } + + public String getPersonCode() { + return personCode; + } + + public void setPersonCode(String personCode) { + this.personCode = personCode; + } + + public String getPersonName() { + return personName; + } + + public void setPersonName(String personName) { + this.personName = personName; + } + + public String getRemarks() { + return remarks; + } + + public void setRemarks(String remarks) { + this.remarks = remarks; + } + + public Integer getTimeTemplateNum() { + return timeTemplateNum; + } + + public void setTimeTemplateNum(Integer timeTemplateNum) { + this.timeTemplateNum = timeTemplateNum; + } + + public List getTimeTemplateList() { + return timeTemplateList; + } + + public void setTimeTemplateList(List timeTemplateList) { + this.timeTemplateList = timeTemplateList; + } + + public Integer getIdentificationNum() { + return identificationNum; + } + + public void setIdentificationNum(Integer identificationNum) { + this.identificationNum = identificationNum; + } + + public List getIdentificationList() { + return identificationList; + } + + public void setIdentificationList(List identificationList) { + this.identificationList = identificationList; + } + + public Integer getImageNum() { + return imageNum; + } + + public void setImageNum(Integer imageNum) { + this.imageNum = imageNum; + } + + public List getImageList() { + return imageList; + } + + public void setImageList(List imageList) { + this.imageList = imageList; + } + + public class TimeTemplate{ + @JSONField(name = "BeginTime") + private Long beginTime; + @JSONField(name = "EndTime") + private Long endTime; + @JSONField(name = "Index") + private Long index; + + public TimeTemplate(Long beginTime, Long endTime, Long index) { + this.beginTime = beginTime; + this.endTime = endTime; + this.index = index; + } + + public Long getBeginTime() { + return beginTime; + } + + public void setBeginTime(Long beginTime) { + this.beginTime = beginTime; + } + + public Long getEndTime() { + return endTime; + } + + public void setEndTime(Long endTime) { + this.endTime = endTime; + } + + public Long getIndex() { + return index; + } + + public void setIndex(Long index) { + this.index = index; + } + } + + public TimeTemplate createTimeTemplate(Long beginTime, Long endTime, Long index){ + return new TimeTemplate(beginTime, endTime, index); + } + + public class IdentificationInfo { + @JSONField(name = "Type") + private Integer type; + @JSONField(name = "Number") + private String number; + + public IdentificationInfo(Integer type, String number) { + this.type = type; + this.number = number; + } + + public Integer getType() { + return type; + } + + public void setType(Integer type) { + this.type = type; + } + + public String getNumber() { + return number; + } + + public void setNumber(String number) { + this.number = number; + } + } + + public IdentificationInfo createIdentificationInfo(Integer type, String number){ + return new IdentificationInfo(type,number); + } + + public class ImageInfo{ + @JSONField(name = "FaceID") + private Long faceID; + @JSONField(name = "Name") + private String name; + @JSONField(name = "Size") + private Long size; + @JSONField(name = "Data") + private String data; + + public ImageInfo(Long faceID, String name, Long size, String data) { + this.faceID = faceID; + this.name = name; + this.size = size; + this.data = data; + } + + public Long getFaceID() { + return faceID; + } + + public void setFaceID(Long faceID) { + this.faceID = faceID; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Long getSize() { + return size; + } + + public void setSize(Long size) { + this.size = size; + } + + public String getData() { + return data; + } + + public void setData(String data) { + this.data = data; + } + } + + public ImageInfo createImageInfo(Long faceID, String name, Long size, String data){ + return new ImageInfo(faceID, name, size, data); + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceBaseResponse.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceBaseResponse.java new file mode 100644 index 0000000..fe93b8a --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceBaseResponse.java @@ -0,0 +1,90 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; +import com.google.gson.annotations.SerializedName; + +public class FaceBaseResponse { + @JSONField(name = "ResponseURL") + @SerializedName("ResponseURL") + private String responseUrl; + + @JSONField(name = "CreatedID") + @SerializedName("CreatedID") + private int createdId; + + @JSONField(name = "ResponseCode") + @SerializedName("ResponseCode") + private int responseCode; + + @JSONField(name = "ResponseString") + @SerializedName("ResponseString") + private String responseString; + + @JSONField(name = "StatusCode") + @SerializedName("StatusCode") + private int statusCode; + + @JSONField(name = "StatusString") + @SerializedName("StatusString") + private String statusString; + + //@JSONField(name = "Data") + @SerializedName("Data") + private T data; + + public String getResponseUrl() { + return responseUrl; + } + + public void setResponseUrl(String responseUrl) { + this.responseUrl = responseUrl; + } + + public int getCreatedId() { + return createdId; + } + + public void setCreatedId(int createdId) { + this.createdId = createdId; + } + + public int getResponseCode() { + return responseCode; + } + + public void setResponseCode(int responseCode) { + this.responseCode = responseCode; + } + + public String getResponseString() { + return responseString; + } + + public void setResponseString(String responseString) { + this.responseString = responseString; + } + + public int getStatusCode() { + return statusCode; + } + + public void setStatusCode(int statusCode) { + this.statusCode = statusCode; + } + + public String getStatusString() { + return statusString; + } + + public void setStatusString(String statusString) { + this.statusString = statusString; + } + + public T getData() { + return data; + } + + public void setData(T data) { + this.data = data; + } +} diff --git a/casic-face-sync/pom.xml b/casic-face-sync/pom.xml new file mode 100644 index 0000000..24dc884 --- /dev/null +++ b/casic-face-sync/pom.xml @@ -0,0 +1,74 @@ + + + 4.0.0 + + com.casic + casic-iris-parent + 1.0.0-SNAPSHOT + ../pom.xml + + + + casic-face-sync + ${pro.version} + jar + casic-face-sync + + + + + + com.casic + casic-core + ${core.version} + + + + com.casic + casic-admin-support + ${admin.version} + + + com.casic + casic-iris-support + ${pro.version} + + + + org.apache.httpcomponents + httpclient + 4.5.3 + + + + org.apache.httpcomponents + httpcore + 4.4.8 + + + + org.apache.httpcomponents + httpmime + 4.5.3 + + + + com.google.code.gson + gson + + + + + + + + src/main/java + + **/*.xml + + + + + \ No newline at end of file diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/constant/FaceSyncConst.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/constant/FaceSyncConst.java new file mode 100644 index 0000000..352d47d --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/constant/FaceSyncConst.java @@ -0,0 +1,29 @@ +package com.casic.missiles.modular.system.constant; + +public class FaceSyncConst { + + /** + * 单次最大批量上传人员数 + */ + public static final int UPLOAD_MAX_PERSON = 6; + + /** + * 上传人员库 + */ + public static final String UPLOAD_STAFF_LIB = "3"; + public static final String UPLOAD_VISITOR_LIB = "4"; + + public static final String UPLOAD_URL_PREFIX = "/LAPI/V1.0/PeopleLibraries/"; + + public static final String UPLOAD_URL_SUFFIX = "/People"; + + public static final int UPLOAD_PERSONCODE_MAXLENGTH = 15; + + public static final int UPLOAD_REMARK_MAXLENGTH = 63; + + public static final String SUBSCRIBE_URL = "/LAPI/V1.0/System/Event/Subscription/"; + + public static final String STAFF_PERSON_TYPE = "1"; + + public static final String VISITOR_PERSON_TYPE = "0"; +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/controller/FaceSyncController.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/controller/FaceSyncController.java new file mode 100644 index 0000000..1b35431 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/controller/FaceSyncController.java @@ -0,0 +1,117 @@ +package com.casic.missiles.modular.system.controller; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson.serializer.SerializerFeature; +import com.casic.missiles.core.base.response.ResponseData; +import com.casic.missiles.core.common.service.ICommonPermissionService; +import com.casic.missiles.core.common.service.ICommonPersonService; +import com.casic.missiles.core.datascope.DataScope; +import com.casic.missiles.core.util.ToolUtil; +import com.casic.missiles.modular.system.request.PersonInfo; +import com.casic.missiles.modular.system.response.RecordNotification; +import com.casic.missiles.modular.system.service.IFaceSyncService; +import com.casic.missiles.modular.system.service.IIrisPersonSupportService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.*; +import com.casic.missiles.modular.system.constant.FaceSyncConst; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + + + +@Controller +public class FaceSyncController { + private final static Logger logger = LoggerFactory.getLogger(FaceSyncController.class); + + @Autowired + private IFaceSyncService syncService; + @Autowired + private ICommonPersonService commonPersonService; + @Autowired + private IIrisPersonSupportService personSupportService; + @Autowired + private ICommonPermissionService permissionService; + + @RequestMapping("/face/upload") + @ResponseBody + public Object upload(@RequestParam("personIds") List personIds, + @RequestParam("deviceIds") List deviceIds, + @RequestParam("personType")String personType ){ + // 检查数量 +// if(personIds.size()>FaceSyncConst.UPLOAD_MAX_PERSON){ +// return ResponseData.error(String.format("每次最多上传%s个人",FaceSyncConst.UPLOAD_MAX_PERSON)); +// } + // 检查照片格式及大小 + String photoCheck = syncService.checkPersonPhoto(personIds); + if(ToolUtil.isNotEmpty(photoCheck)){ + return ResponseData.error(photoCheck); + } + else{ + // 上传数据 + String error = syncService.uploadPerson(personIds,deviceIds,personType); + if(ToolUtil.isNotEmpty(error)){ + return ResponseData.error(error); + } + } + return ResponseData.success(); + } + + @RequestMapping("/face/uploadAll") + @ResponseBody + public Object uploadAll(@RequestParam("deviceIds") List deviceIds){ + DataScope dataScope = permissionService.getCurrUserDataScope(); + + List staffPersonIds = personSupportService.listIdsByType(dataScope,FaceSyncConst.STAFF_PERSON_TYPE); + List visitorPersonIds = personSupportService.listIdsByType(dataScope,FaceSyncConst.VISITOR_PERSON_TYPE); + // 1.检查照片,分别检查员工、访客 + String staffPhotoCheck = syncService.checkPersonPhoto(staffPersonIds); + if(ToolUtil.isNotEmpty(staffPhotoCheck)){ + return ResponseData.error(staffPhotoCheck); + } + String visitorPhotoCheck = syncService.checkPersonPhoto(visitorPersonIds); + if(ToolUtil.isNotEmpty(visitorPhotoCheck)){ + return ResponseData.error(visitorPhotoCheck); + } + + // 2. 下发数据 + String staffError = syncService.uploadPerson(staffPersonIds,deviceIds,FaceSyncConst.STAFF_PERSON_TYPE); + if(ToolUtil.isNotEmpty(staffError)){ + return ResponseData.error(staffError); + } + String visitorError = syncService.uploadPerson(visitorPersonIds,deviceIds,FaceSyncConst.VISITOR_PERSON_TYPE); + if(ToolUtil.isNotEmpty(visitorError)){ + return ResponseData.error(visitorError); + } + + return ResponseData.success(); + } + + // 错误信息返回 + @RequestMapping("/subsrcibe/init") + @ResponseBody + public Object upload(@RequestParam("deviceIds") List deviceIds){ + String errorMsg = syncService.initSubscription(deviceIds); + if(ToolUtil.isNotEmpty(errorMsg)){ + return ResponseData.error(errorMsg); + } + return ResponseData.success(); + } + + + @RequestMapping(value = "/LAPI/V1.0/System/Event/Notification/PersonVerification", method = RequestMethod.POST) + @ResponseBody + public void verification(@RequestBody String recordNotification){ + logger.info(recordNotification); + RecordNotification record = JSONObject.parseObject(recordNotification,RecordNotification.class); + syncService.receiveRecord(record); + //return ResponseData.success(); + } + + +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FacePersonSyncMapper.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FacePersonSyncMapper.java new file mode 100644 index 0000000..af53702 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FacePersonSyncMapper.java @@ -0,0 +1,17 @@ +package com.casic.missiles.modular.system.dao; + +import com.casic.missiles.modular.system.model.FacePersonSync; +import com.baomidou.mybatisplus.mapper.BaseMapper; + +/** + *

+ * Mapper 接口 + *

+ * + * @author zyj123 + * @since 2020-07-24 + */ +public interface FacePersonSyncMapper extends BaseMapper { + + Long getMaxSyncId(); +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FaceSubscribeMapper.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FaceSubscribeMapper.java new file mode 100644 index 0000000..0c6374a --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FaceSubscribeMapper.java @@ -0,0 +1,16 @@ +package com.casic.missiles.modular.system.dao; + +import com.casic.missiles.modular.system.model.FaceSubscribe; +import com.baomidou.mybatisplus.mapper.BaseMapper; + +/** + *

+ * Mapper 接口 + *

+ * + * @author zyj123 + * @since 2020-07-25 + */ +public interface FaceSubscribeMapper extends BaseMapper { + +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FacePersonSyncMapper.xml b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FacePersonSyncMapper.xml new file mode 100644 index 0000000..ac46ad0 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FacePersonSyncMapper.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + PERSON_ID AS personId, SYNC_ID AS syncId + + + + + diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FaceSubscribeMapper.xml b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FaceSubscribeMapper.xml new file mode 100644 index 0000000..16024e2 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FaceSubscribeMapper.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + SUBSCRIBE_ID AS subscribeId, DEVICE_CODE AS deviceCode, UPDATE_TIME AS updateTime + + + diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FacePersonSync.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FacePersonSync.java new file mode 100644 index 0000000..7cdb821 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FacePersonSync.java @@ -0,0 +1,68 @@ +package com.casic.missiles.modular.system.model; + +import java.io.Serializable; + +import com.baomidou.mybatisplus.annotations.TableId; +import com.baomidou.mybatisplus.annotations.TableField; +import com.baomidou.mybatisplus.activerecord.Model; +import com.baomidou.mybatisplus.annotations.TableName; +import java.io.Serializable; + +/** + *

+ * + *

+ * + * @author zyj123 + * @since 2020-07-24 + */ +@TableName("face_person_sync") +public class FacePersonSync extends Model { + + private static final long serialVersionUID = 1L; + + /** + * 人员id + */ + @TableId("PERSON_ID") + private Long personId; + /** + * 人员同步id + */ + @TableField("SYNC_ID") + private Long syncId; + + public FacePersonSync(Long personId, Long syncId) { + this.personId = personId; + this.syncId = syncId; + } + + public Long getPersonId() { + return personId; + } + + public void setPersonId(Long personId) { + this.personId = personId; + } + + public Long getSyncId() { + return syncId; + } + + public void setSyncId(Long syncId) { + this.syncId = syncId; + } + + @Override + protected Serializable pkVal() { + return this.personId; + } + + @Override + public String toString() { + return "FacePersonSync{" + + "personId=" + personId + + ", syncId=" + syncId + + "}"; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FaceSubscribe.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FaceSubscribe.java new file mode 100644 index 0000000..ccc7792 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FaceSubscribe.java @@ -0,0 +1,79 @@ +package com.casic.missiles.modular.system.model; + +import java.io.Serializable; + +import java.util.Date; +import com.baomidou.mybatisplus.annotations.TableId; +import com.baomidou.mybatisplus.annotations.TableField; +import com.baomidou.mybatisplus.activerecord.Model; +import com.baomidou.mybatisplus.annotations.TableName; +import java.io.Serializable; + +/** + *

+ * + *

+ * + * @author zyj123 + * @since 2020-07-25 + */ +@TableName("face_subscribe") +public class FaceSubscribe extends Model { + + private static final long serialVersionUID = 1L; + + /** + * 订阅id + */ + @TableId("SUBSCRIBE_ID") + private Long subscribeId; + /** + * 设备编号 + */ + @TableField("DEVICE_CODE") + private String deviceCode; + /** + * 更新时间 + */ + @TableField("UPDATE_TIME") + private Date updateTime; + + + public Long getSubscribeId() { + return subscribeId; + } + + public void setSubscribeId(Long subscribeId) { + this.subscribeId = subscribeId; + } + + public String getDeviceCode() { + return deviceCode; + } + + public void setDeviceCode(String deviceCode) { + this.deviceCode = deviceCode; + } + + public Date getUpdateTime() { + return updateTime; + } + + public void setUpdateTime(Date updateTime) { + this.updateTime = updateTime; + } + + @Override + protected Serializable pkVal() { + return this.subscribeId; + } + + @Override + public String toString() { + return "FaceSubscribe{" + + "subscribeId=" + subscribeId + + ", deviceCode=" + deviceCode + + ", updateTime=" + updateTime + + "}"; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/request/PersonInfo.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/request/PersonInfo.java new file mode 100644 index 0000000..80d9eff --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/request/PersonInfo.java @@ -0,0 +1,271 @@ +package com.casic.missiles.modular.system.request; + +import com.alibaba.fastjson.annotation.JSONField; +import com.baomidou.mybatisplus.annotations.TableField; +import com.google.gson.annotations.SerializedName; + +import java.util.List; + +public class PersonInfo { + + //@JSONField(name = "PersonID") + @SerializedName("PersonID") + private Long personID; + + //@JSONField(name = "LastChange") + @SerializedName("LastChange") + private Long lastChange; + + //@JSONField(name = "PersonCode") + @SerializedName("PersonCode") + private String personCode; + + //@JSONField(name = "PersonName") + @SerializedName("PersonName") + private String personName; + + //@JSONField(name = "Remarks") + @SerializedName("Remarks") + private String remarks; + + //@JSONField(name = "TimeTemplateNum") + @SerializedName("TimeTemplateNum") + private Integer timeTemplateNum; + + //@JSONField(name = "TimeTemplateList") + @SerializedName("TimeTemplateList") + private List timeTemplateList; + + //@JSONField(name = "IdentificationNum") + @SerializedName("IdentificationNum") + private Integer identificationNum; + + //@JSONField(name = "IdentificationList") + @SerializedName("IdentificationList") + private List identificationList; + + //@JSONField(name = "ImageNum") + @SerializedName("ImageNum") + private Integer imageNum; + + //@JSONField(name = "ImageList") + @SerializedName("ImageList") + private List imageList; + + public Long getPersonID() { + return personID; + } + + public void setPersonID(Long personID) { + this.personID = personID; + } + + public Long getLastChange() { + return lastChange; + } + + public void setLastChange(Long lastChange) { + this.lastChange = lastChange; + } + + public String getPersonCode() { + return personCode; + } + + public void setPersonCode(String personCode) { + this.personCode = personCode; + } + + public String getPersonName() { + return personName; + } + + public void setPersonName(String personName) { + this.personName = personName; + } + + public String getRemarks() { + return remarks; + } + + public void setRemarks(String remarks) { + this.remarks = remarks; + } + + public Integer getTimeTemplateNum() { + return timeTemplateNum; + } + + public void setTimeTemplateNum(Integer timeTemplateNum) { + this.timeTemplateNum = timeTemplateNum; + } + + public List getTimeTemplateList() { + return timeTemplateList; + } + + public void setTimeTemplateList(List timeTemplateList) { + this.timeTemplateList = timeTemplateList; + } + + public Integer getIdentificationNum() { + return identificationNum; + } + + public void setIdentificationNum(Integer identificationNum) { + this.identificationNum = identificationNum; + } + + public List getIdentificationList() { + return identificationList; + } + + public void setIdentificationList(List identificationList) { + this.identificationList = identificationList; + } + + public Integer getImageNum() { + return imageNum; + } + + public void setImageNum(Integer imageNum) { + this.imageNum = imageNum; + } + + public List getImageList() { + return imageList; + } + + public void setImageList(List imageList) { + this.imageList = imageList; + } + + public class TimeTemplate{ + @JSONField(name = "BeginTime") + private Long beginTime; + @JSONField(name = "EndTime") + private Long endTime; + @JSONField(name = "Index") + private Long index; + + public TimeTemplate(Long beginTime, Long endTime, Long index) { + this.beginTime = beginTime; + this.endTime = endTime; + this.index = index; + } + + public Long getBeginTime() { + return beginTime; + } + + public void setBeginTime(Long beginTime) { + this.beginTime = beginTime; + } + + public Long getEndTime() { + return endTime; + } + + public void setEndTime(Long endTime) { + this.endTime = endTime; + } + + public Long getIndex() { + return index; + } + + public void setIndex(Long index) { + this.index = index; + } + } + + public TimeTemplate createTimeTemplate(Long beginTime, Long endTime, Long index){ + return new TimeTemplate(beginTime, endTime, index); + } + + public class IdentificationInfo { + @JSONField(name = "Type") + private Integer type; + @JSONField(name = "Number") + private String number; + + public IdentificationInfo(Integer type, String number) { + this.type = type; + this.number = number; + } + + public Integer getType() { + return type; + } + + public void setType(Integer type) { + this.type = type; + } + + public String getNumber() { + return number; + } + + public void setNumber(String number) { + this.number = number; + } + } + + public IdentificationInfo createIdentificationInfo(Integer type, String number){ + return new IdentificationInfo(type,number); + } + + public class ImageInfo{ + @JSONField(name = "FaceID") + private Long faceID; + @JSONField(name = "Name") + private String name; + @JSONField(name = "Size") + private Long size; + @JSONField(name = "Data") + private String data; + + public ImageInfo(Long faceID, String name, Long size, String data) { + this.faceID = faceID; + this.name = name; + this.size = size; + this.data = data; + } + + public Long getFaceID() { + return faceID; + } + + public void setFaceID(Long faceID) { + this.faceID = faceID; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Long getSize() { + return size; + } + + public void setSize(Long size) { + this.size = size; + } + + public String getData() { + return data; + } + + public void setData(String data) { + this.data = data; + } + } + + public ImageInfo createImageInfo(Long faceID, String name, Long size, String data){ + return new ImageInfo(faceID, name, size, data); + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceBaseResponse.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceBaseResponse.java new file mode 100644 index 0000000..fe93b8a --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceBaseResponse.java @@ -0,0 +1,90 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; +import com.google.gson.annotations.SerializedName; + +public class FaceBaseResponse { + @JSONField(name = "ResponseURL") + @SerializedName("ResponseURL") + private String responseUrl; + + @JSONField(name = "CreatedID") + @SerializedName("CreatedID") + private int createdId; + + @JSONField(name = "ResponseCode") + @SerializedName("ResponseCode") + private int responseCode; + + @JSONField(name = "ResponseString") + @SerializedName("ResponseString") + private String responseString; + + @JSONField(name = "StatusCode") + @SerializedName("StatusCode") + private int statusCode; + + @JSONField(name = "StatusString") + @SerializedName("StatusString") + private String statusString; + + //@JSONField(name = "Data") + @SerializedName("Data") + private T data; + + public String getResponseUrl() { + return responseUrl; + } + + public void setResponseUrl(String responseUrl) { + this.responseUrl = responseUrl; + } + + public int getCreatedId() { + return createdId; + } + + public void setCreatedId(int createdId) { + this.createdId = createdId; + } + + public int getResponseCode() { + return responseCode; + } + + public void setResponseCode(int responseCode) { + this.responseCode = responseCode; + } + + public String getResponseString() { + return responseString; + } + + public void setResponseString(String responseString) { + this.responseString = responseString; + } + + public int getStatusCode() { + return statusCode; + } + + public void setStatusCode(int statusCode) { + this.statusCode = statusCode; + } + + public String getStatusString() { + return statusString; + } + + public void setStatusString(String statusString) { + this.statusString = statusString; + } + + public T getData() { + return data; + } + + public void setData(T data) { + this.data = data; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceInfo.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceInfo.java new file mode 100644 index 0000000..f128c92 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceInfo.java @@ -0,0 +1,128 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; + +import java.util.List; + +public class FaceInfo { + @JSONField(name = "ID") + private Long id; + @JSONField(name = "Timestamp") + private Long timestamp; + @JSONField(name = "CapSrc") + private Long capSrc; + @JSONField(name = "FeatureNum") + private Long featureNum; + @JSONField(name = "FeatureList") + private List featureList; + @JSONField(name = "FeatureVersion") + private String featureVersion; + @JSONField(name = "Feature") + private String feature; + @JSONField(name = "Temperature") + private Float temperature; + @JSONField(name = "MaskFlag") + private Long maskFlag; + @JSONField(name = "PanoImage") + private Object panoImage; + @JSONField(name = "FaceImage") + private Object faceImage; + @JSONField(name = "FaceArea") + private Object faceArea; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Long getTimestamp() { + return timestamp; + } + + public void setTimestamp(Long timestamp) { + this.timestamp = timestamp; + } + + public Long getCapSrc() { + return capSrc; + } + + public void setCapSrc(Long capSrc) { + this.capSrc = capSrc; + } + + public Long getFeatureNum() { + return featureNum; + } + + public void setFeatureNum(Long featureNum) { + this.featureNum = featureNum; + } + + public List getFeatureList() { + return featureList; + } + + public void setFeatureList(List featureList) { + this.featureList = featureList; + } + + public String getFeatureVersion() { + return featureVersion; + } + + public void setFeatureVersion(String featureVersion) { + this.featureVersion = featureVersion; + } + + public String getFeature() { + return feature; + } + + public void setFeature(String feature) { + this.feature = feature; + } + + public Float getTemperature() { + return temperature; + } + + public void setTemperature(Float temperature) { + this.temperature = temperature; + } + + public Long getMaskFlag() { + return maskFlag; + } + + public void setMaskFlag(Long maskFlag) { + this.maskFlag = maskFlag; + } + + public Object getPanoImage() { + return panoImage; + } + + public void setPanoImage(Object panoImage) { + this.panoImage = panoImage; + } + + public Object getFaceImage() { + return faceImage; + } + + public void setFaceImage(Object faceImage) { + this.faceImage = faceImage; + } + + public Object getFaceArea() { + return faceArea; + } + + public void setFaceArea(Object faceArea) { + this.faceArea = faceArea; + } +} diff --git a/casic-face-sync/pom.xml b/casic-face-sync/pom.xml new file mode 100644 index 0000000..24dc884 --- /dev/null +++ b/casic-face-sync/pom.xml @@ -0,0 +1,74 @@ + + + 4.0.0 + + com.casic + casic-iris-parent + 1.0.0-SNAPSHOT + ../pom.xml + + + + casic-face-sync + ${pro.version} + jar + casic-face-sync + + + + + + com.casic + casic-core + ${core.version} + + + + com.casic + casic-admin-support + ${admin.version} + + + com.casic + casic-iris-support + ${pro.version} + + + + org.apache.httpcomponents + httpclient + 4.5.3 + + + + org.apache.httpcomponents + httpcore + 4.4.8 + + + + org.apache.httpcomponents + httpmime + 4.5.3 + + + + com.google.code.gson + gson + + + + + + + + src/main/java + + **/*.xml + + + + + \ No newline at end of file diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/constant/FaceSyncConst.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/constant/FaceSyncConst.java new file mode 100644 index 0000000..352d47d --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/constant/FaceSyncConst.java @@ -0,0 +1,29 @@ +package com.casic.missiles.modular.system.constant; + +public class FaceSyncConst { + + /** + * 单次最大批量上传人员数 + */ + public static final int UPLOAD_MAX_PERSON = 6; + + /** + * 上传人员库 + */ + public static final String UPLOAD_STAFF_LIB = "3"; + public static final String UPLOAD_VISITOR_LIB = "4"; + + public static final String UPLOAD_URL_PREFIX = "/LAPI/V1.0/PeopleLibraries/"; + + public static final String UPLOAD_URL_SUFFIX = "/People"; + + public static final int UPLOAD_PERSONCODE_MAXLENGTH = 15; + + public static final int UPLOAD_REMARK_MAXLENGTH = 63; + + public static final String SUBSCRIBE_URL = "/LAPI/V1.0/System/Event/Subscription/"; + + public static final String STAFF_PERSON_TYPE = "1"; + + public static final String VISITOR_PERSON_TYPE = "0"; +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/controller/FaceSyncController.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/controller/FaceSyncController.java new file mode 100644 index 0000000..1b35431 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/controller/FaceSyncController.java @@ -0,0 +1,117 @@ +package com.casic.missiles.modular.system.controller; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson.serializer.SerializerFeature; +import com.casic.missiles.core.base.response.ResponseData; +import com.casic.missiles.core.common.service.ICommonPermissionService; +import com.casic.missiles.core.common.service.ICommonPersonService; +import com.casic.missiles.core.datascope.DataScope; +import com.casic.missiles.core.util.ToolUtil; +import com.casic.missiles.modular.system.request.PersonInfo; +import com.casic.missiles.modular.system.response.RecordNotification; +import com.casic.missiles.modular.system.service.IFaceSyncService; +import com.casic.missiles.modular.system.service.IIrisPersonSupportService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.*; +import com.casic.missiles.modular.system.constant.FaceSyncConst; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + + + +@Controller +public class FaceSyncController { + private final static Logger logger = LoggerFactory.getLogger(FaceSyncController.class); + + @Autowired + private IFaceSyncService syncService; + @Autowired + private ICommonPersonService commonPersonService; + @Autowired + private IIrisPersonSupportService personSupportService; + @Autowired + private ICommonPermissionService permissionService; + + @RequestMapping("/face/upload") + @ResponseBody + public Object upload(@RequestParam("personIds") List personIds, + @RequestParam("deviceIds") List deviceIds, + @RequestParam("personType")String personType ){ + // 检查数量 +// if(personIds.size()>FaceSyncConst.UPLOAD_MAX_PERSON){ +// return ResponseData.error(String.format("每次最多上传%s个人",FaceSyncConst.UPLOAD_MAX_PERSON)); +// } + // 检查照片格式及大小 + String photoCheck = syncService.checkPersonPhoto(personIds); + if(ToolUtil.isNotEmpty(photoCheck)){ + return ResponseData.error(photoCheck); + } + else{ + // 上传数据 + String error = syncService.uploadPerson(personIds,deviceIds,personType); + if(ToolUtil.isNotEmpty(error)){ + return ResponseData.error(error); + } + } + return ResponseData.success(); + } + + @RequestMapping("/face/uploadAll") + @ResponseBody + public Object uploadAll(@RequestParam("deviceIds") List deviceIds){ + DataScope dataScope = permissionService.getCurrUserDataScope(); + + List staffPersonIds = personSupportService.listIdsByType(dataScope,FaceSyncConst.STAFF_PERSON_TYPE); + List visitorPersonIds = personSupportService.listIdsByType(dataScope,FaceSyncConst.VISITOR_PERSON_TYPE); + // 1.检查照片,分别检查员工、访客 + String staffPhotoCheck = syncService.checkPersonPhoto(staffPersonIds); + if(ToolUtil.isNotEmpty(staffPhotoCheck)){ + return ResponseData.error(staffPhotoCheck); + } + String visitorPhotoCheck = syncService.checkPersonPhoto(visitorPersonIds); + if(ToolUtil.isNotEmpty(visitorPhotoCheck)){ + return ResponseData.error(visitorPhotoCheck); + } + + // 2. 下发数据 + String staffError = syncService.uploadPerson(staffPersonIds,deviceIds,FaceSyncConst.STAFF_PERSON_TYPE); + if(ToolUtil.isNotEmpty(staffError)){ + return ResponseData.error(staffError); + } + String visitorError = syncService.uploadPerson(visitorPersonIds,deviceIds,FaceSyncConst.VISITOR_PERSON_TYPE); + if(ToolUtil.isNotEmpty(visitorError)){ + return ResponseData.error(visitorError); + } + + return ResponseData.success(); + } + + // 错误信息返回 + @RequestMapping("/subsrcibe/init") + @ResponseBody + public Object upload(@RequestParam("deviceIds") List deviceIds){ + String errorMsg = syncService.initSubscription(deviceIds); + if(ToolUtil.isNotEmpty(errorMsg)){ + return ResponseData.error(errorMsg); + } + return ResponseData.success(); + } + + + @RequestMapping(value = "/LAPI/V1.0/System/Event/Notification/PersonVerification", method = RequestMethod.POST) + @ResponseBody + public void verification(@RequestBody String recordNotification){ + logger.info(recordNotification); + RecordNotification record = JSONObject.parseObject(recordNotification,RecordNotification.class); + syncService.receiveRecord(record); + //return ResponseData.success(); + } + + +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FacePersonSyncMapper.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FacePersonSyncMapper.java new file mode 100644 index 0000000..af53702 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FacePersonSyncMapper.java @@ -0,0 +1,17 @@ +package com.casic.missiles.modular.system.dao; + +import com.casic.missiles.modular.system.model.FacePersonSync; +import com.baomidou.mybatisplus.mapper.BaseMapper; + +/** + *

+ * Mapper 接口 + *

+ * + * @author zyj123 + * @since 2020-07-24 + */ +public interface FacePersonSyncMapper extends BaseMapper { + + Long getMaxSyncId(); +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FaceSubscribeMapper.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FaceSubscribeMapper.java new file mode 100644 index 0000000..0c6374a --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FaceSubscribeMapper.java @@ -0,0 +1,16 @@ +package com.casic.missiles.modular.system.dao; + +import com.casic.missiles.modular.system.model.FaceSubscribe; +import com.baomidou.mybatisplus.mapper.BaseMapper; + +/** + *

+ * Mapper 接口 + *

+ * + * @author zyj123 + * @since 2020-07-25 + */ +public interface FaceSubscribeMapper extends BaseMapper { + +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FacePersonSyncMapper.xml b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FacePersonSyncMapper.xml new file mode 100644 index 0000000..ac46ad0 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FacePersonSyncMapper.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + PERSON_ID AS personId, SYNC_ID AS syncId + + + + + diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FaceSubscribeMapper.xml b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FaceSubscribeMapper.xml new file mode 100644 index 0000000..16024e2 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FaceSubscribeMapper.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + SUBSCRIBE_ID AS subscribeId, DEVICE_CODE AS deviceCode, UPDATE_TIME AS updateTime + + + diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FacePersonSync.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FacePersonSync.java new file mode 100644 index 0000000..7cdb821 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FacePersonSync.java @@ -0,0 +1,68 @@ +package com.casic.missiles.modular.system.model; + +import java.io.Serializable; + +import com.baomidou.mybatisplus.annotations.TableId; +import com.baomidou.mybatisplus.annotations.TableField; +import com.baomidou.mybatisplus.activerecord.Model; +import com.baomidou.mybatisplus.annotations.TableName; +import java.io.Serializable; + +/** + *

+ * + *

+ * + * @author zyj123 + * @since 2020-07-24 + */ +@TableName("face_person_sync") +public class FacePersonSync extends Model { + + private static final long serialVersionUID = 1L; + + /** + * 人员id + */ + @TableId("PERSON_ID") + private Long personId; + /** + * 人员同步id + */ + @TableField("SYNC_ID") + private Long syncId; + + public FacePersonSync(Long personId, Long syncId) { + this.personId = personId; + this.syncId = syncId; + } + + public Long getPersonId() { + return personId; + } + + public void setPersonId(Long personId) { + this.personId = personId; + } + + public Long getSyncId() { + return syncId; + } + + public void setSyncId(Long syncId) { + this.syncId = syncId; + } + + @Override + protected Serializable pkVal() { + return this.personId; + } + + @Override + public String toString() { + return "FacePersonSync{" + + "personId=" + personId + + ", syncId=" + syncId + + "}"; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FaceSubscribe.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FaceSubscribe.java new file mode 100644 index 0000000..ccc7792 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FaceSubscribe.java @@ -0,0 +1,79 @@ +package com.casic.missiles.modular.system.model; + +import java.io.Serializable; + +import java.util.Date; +import com.baomidou.mybatisplus.annotations.TableId; +import com.baomidou.mybatisplus.annotations.TableField; +import com.baomidou.mybatisplus.activerecord.Model; +import com.baomidou.mybatisplus.annotations.TableName; +import java.io.Serializable; + +/** + *

+ * + *

+ * + * @author zyj123 + * @since 2020-07-25 + */ +@TableName("face_subscribe") +public class FaceSubscribe extends Model { + + private static final long serialVersionUID = 1L; + + /** + * 订阅id + */ + @TableId("SUBSCRIBE_ID") + private Long subscribeId; + /** + * 设备编号 + */ + @TableField("DEVICE_CODE") + private String deviceCode; + /** + * 更新时间 + */ + @TableField("UPDATE_TIME") + private Date updateTime; + + + public Long getSubscribeId() { + return subscribeId; + } + + public void setSubscribeId(Long subscribeId) { + this.subscribeId = subscribeId; + } + + public String getDeviceCode() { + return deviceCode; + } + + public void setDeviceCode(String deviceCode) { + this.deviceCode = deviceCode; + } + + public Date getUpdateTime() { + return updateTime; + } + + public void setUpdateTime(Date updateTime) { + this.updateTime = updateTime; + } + + @Override + protected Serializable pkVal() { + return this.subscribeId; + } + + @Override + public String toString() { + return "FaceSubscribe{" + + "subscribeId=" + subscribeId + + ", deviceCode=" + deviceCode + + ", updateTime=" + updateTime + + "}"; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/request/PersonInfo.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/request/PersonInfo.java new file mode 100644 index 0000000..80d9eff --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/request/PersonInfo.java @@ -0,0 +1,271 @@ +package com.casic.missiles.modular.system.request; + +import com.alibaba.fastjson.annotation.JSONField; +import com.baomidou.mybatisplus.annotations.TableField; +import com.google.gson.annotations.SerializedName; + +import java.util.List; + +public class PersonInfo { + + //@JSONField(name = "PersonID") + @SerializedName("PersonID") + private Long personID; + + //@JSONField(name = "LastChange") + @SerializedName("LastChange") + private Long lastChange; + + //@JSONField(name = "PersonCode") + @SerializedName("PersonCode") + private String personCode; + + //@JSONField(name = "PersonName") + @SerializedName("PersonName") + private String personName; + + //@JSONField(name = "Remarks") + @SerializedName("Remarks") + private String remarks; + + //@JSONField(name = "TimeTemplateNum") + @SerializedName("TimeTemplateNum") + private Integer timeTemplateNum; + + //@JSONField(name = "TimeTemplateList") + @SerializedName("TimeTemplateList") + private List timeTemplateList; + + //@JSONField(name = "IdentificationNum") + @SerializedName("IdentificationNum") + private Integer identificationNum; + + //@JSONField(name = "IdentificationList") + @SerializedName("IdentificationList") + private List identificationList; + + //@JSONField(name = "ImageNum") + @SerializedName("ImageNum") + private Integer imageNum; + + //@JSONField(name = "ImageList") + @SerializedName("ImageList") + private List imageList; + + public Long getPersonID() { + return personID; + } + + public void setPersonID(Long personID) { + this.personID = personID; + } + + public Long getLastChange() { + return lastChange; + } + + public void setLastChange(Long lastChange) { + this.lastChange = lastChange; + } + + public String getPersonCode() { + return personCode; + } + + public void setPersonCode(String personCode) { + this.personCode = personCode; + } + + public String getPersonName() { + return personName; + } + + public void setPersonName(String personName) { + this.personName = personName; + } + + public String getRemarks() { + return remarks; + } + + public void setRemarks(String remarks) { + this.remarks = remarks; + } + + public Integer getTimeTemplateNum() { + return timeTemplateNum; + } + + public void setTimeTemplateNum(Integer timeTemplateNum) { + this.timeTemplateNum = timeTemplateNum; + } + + public List getTimeTemplateList() { + return timeTemplateList; + } + + public void setTimeTemplateList(List timeTemplateList) { + this.timeTemplateList = timeTemplateList; + } + + public Integer getIdentificationNum() { + return identificationNum; + } + + public void setIdentificationNum(Integer identificationNum) { + this.identificationNum = identificationNum; + } + + public List getIdentificationList() { + return identificationList; + } + + public void setIdentificationList(List identificationList) { + this.identificationList = identificationList; + } + + public Integer getImageNum() { + return imageNum; + } + + public void setImageNum(Integer imageNum) { + this.imageNum = imageNum; + } + + public List getImageList() { + return imageList; + } + + public void setImageList(List imageList) { + this.imageList = imageList; + } + + public class TimeTemplate{ + @JSONField(name = "BeginTime") + private Long beginTime; + @JSONField(name = "EndTime") + private Long endTime; + @JSONField(name = "Index") + private Long index; + + public TimeTemplate(Long beginTime, Long endTime, Long index) { + this.beginTime = beginTime; + this.endTime = endTime; + this.index = index; + } + + public Long getBeginTime() { + return beginTime; + } + + public void setBeginTime(Long beginTime) { + this.beginTime = beginTime; + } + + public Long getEndTime() { + return endTime; + } + + public void setEndTime(Long endTime) { + this.endTime = endTime; + } + + public Long getIndex() { + return index; + } + + public void setIndex(Long index) { + this.index = index; + } + } + + public TimeTemplate createTimeTemplate(Long beginTime, Long endTime, Long index){ + return new TimeTemplate(beginTime, endTime, index); + } + + public class IdentificationInfo { + @JSONField(name = "Type") + private Integer type; + @JSONField(name = "Number") + private String number; + + public IdentificationInfo(Integer type, String number) { + this.type = type; + this.number = number; + } + + public Integer getType() { + return type; + } + + public void setType(Integer type) { + this.type = type; + } + + public String getNumber() { + return number; + } + + public void setNumber(String number) { + this.number = number; + } + } + + public IdentificationInfo createIdentificationInfo(Integer type, String number){ + return new IdentificationInfo(type,number); + } + + public class ImageInfo{ + @JSONField(name = "FaceID") + private Long faceID; + @JSONField(name = "Name") + private String name; + @JSONField(name = "Size") + private Long size; + @JSONField(name = "Data") + private String data; + + public ImageInfo(Long faceID, String name, Long size, String data) { + this.faceID = faceID; + this.name = name; + this.size = size; + this.data = data; + } + + public Long getFaceID() { + return faceID; + } + + public void setFaceID(Long faceID) { + this.faceID = faceID; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Long getSize() { + return size; + } + + public void setSize(Long size) { + this.size = size; + } + + public String getData() { + return data; + } + + public void setData(String data) { + this.data = data; + } + } + + public ImageInfo createImageInfo(Long faceID, String name, Long size, String data){ + return new ImageInfo(faceID, name, size, data); + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceBaseResponse.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceBaseResponse.java new file mode 100644 index 0000000..fe93b8a --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceBaseResponse.java @@ -0,0 +1,90 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; +import com.google.gson.annotations.SerializedName; + +public class FaceBaseResponse { + @JSONField(name = "ResponseURL") + @SerializedName("ResponseURL") + private String responseUrl; + + @JSONField(name = "CreatedID") + @SerializedName("CreatedID") + private int createdId; + + @JSONField(name = "ResponseCode") + @SerializedName("ResponseCode") + private int responseCode; + + @JSONField(name = "ResponseString") + @SerializedName("ResponseString") + private String responseString; + + @JSONField(name = "StatusCode") + @SerializedName("StatusCode") + private int statusCode; + + @JSONField(name = "StatusString") + @SerializedName("StatusString") + private String statusString; + + //@JSONField(name = "Data") + @SerializedName("Data") + private T data; + + public String getResponseUrl() { + return responseUrl; + } + + public void setResponseUrl(String responseUrl) { + this.responseUrl = responseUrl; + } + + public int getCreatedId() { + return createdId; + } + + public void setCreatedId(int createdId) { + this.createdId = createdId; + } + + public int getResponseCode() { + return responseCode; + } + + public void setResponseCode(int responseCode) { + this.responseCode = responseCode; + } + + public String getResponseString() { + return responseString; + } + + public void setResponseString(String responseString) { + this.responseString = responseString; + } + + public int getStatusCode() { + return statusCode; + } + + public void setStatusCode(int statusCode) { + this.statusCode = statusCode; + } + + public String getStatusString() { + return statusString; + } + + public void setStatusString(String statusString) { + this.statusString = statusString; + } + + public T getData() { + return data; + } + + public void setData(T data) { + this.data = data; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceInfo.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceInfo.java new file mode 100644 index 0000000..f128c92 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceInfo.java @@ -0,0 +1,128 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; + +import java.util.List; + +public class FaceInfo { + @JSONField(name = "ID") + private Long id; + @JSONField(name = "Timestamp") + private Long timestamp; + @JSONField(name = "CapSrc") + private Long capSrc; + @JSONField(name = "FeatureNum") + private Long featureNum; + @JSONField(name = "FeatureList") + private List featureList; + @JSONField(name = "FeatureVersion") + private String featureVersion; + @JSONField(name = "Feature") + private String feature; + @JSONField(name = "Temperature") + private Float temperature; + @JSONField(name = "MaskFlag") + private Long maskFlag; + @JSONField(name = "PanoImage") + private Object panoImage; + @JSONField(name = "FaceImage") + private Object faceImage; + @JSONField(name = "FaceArea") + private Object faceArea; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Long getTimestamp() { + return timestamp; + } + + public void setTimestamp(Long timestamp) { + this.timestamp = timestamp; + } + + public Long getCapSrc() { + return capSrc; + } + + public void setCapSrc(Long capSrc) { + this.capSrc = capSrc; + } + + public Long getFeatureNum() { + return featureNum; + } + + public void setFeatureNum(Long featureNum) { + this.featureNum = featureNum; + } + + public List getFeatureList() { + return featureList; + } + + public void setFeatureList(List featureList) { + this.featureList = featureList; + } + + public String getFeatureVersion() { + return featureVersion; + } + + public void setFeatureVersion(String featureVersion) { + this.featureVersion = featureVersion; + } + + public String getFeature() { + return feature; + } + + public void setFeature(String feature) { + this.feature = feature; + } + + public Float getTemperature() { + return temperature; + } + + public void setTemperature(Float temperature) { + this.temperature = temperature; + } + + public Long getMaskFlag() { + return maskFlag; + } + + public void setMaskFlag(Long maskFlag) { + this.maskFlag = maskFlag; + } + + public Object getPanoImage() { + return panoImage; + } + + public void setPanoImage(Object panoImage) { + this.panoImage = panoImage; + } + + public Object getFaceImage() { + return faceImage; + } + + public void setFaceImage(Object faceImage) { + this.faceImage = faceImage; + } + + public Object getFaceArea() { + return faceArea; + } + + public void setFaceArea(Object faceArea) { + this.faceArea = faceArea; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/LibMatInfo.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/LibMatInfo.java new file mode 100644 index 0000000..ce6dd33 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/LibMatInfo.java @@ -0,0 +1,69 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; + +public class LibMatInfo { + @JSONField(name = "ID") + private Long id; + @JSONField(name = "LibID") + private Long libId; + @JSONField(name = "LibType") + private Long libType; + @JSONField(name = "MatchStatus") + private Long matchStatus; + @JSONField(name = "MatchPersonID") + private Long matchPersonId; + @JSONField(name = "MatchFaceID") + private Long matchFaceId; + + // MatchPersonInfo 暂时忽略不用 + + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Long getLibId() { + return libId; + } + + public void setLibId(Long libId) { + this.libId = libId; + } + + public Long getLibType() { + return libType; + } + + public void setLibType(Long libType) { + this.libType = libType; + } + + public Long getMatchStatus() { + return matchStatus; + } + + public void setMatchStatus(Long matchStatus) { + this.matchStatus = matchStatus; + } + + public Long getMatchPersonId() { + return matchPersonId; + } + + public void setMatchPersonId(Long matchPersonId) { + this.matchPersonId = matchPersonId; + } + + public Long getMatchFaceId() { + return matchFaceId; + } + + public void setMatchFaceId(Long matchFaceId) { + this.matchFaceId = matchFaceId; + } +} diff --git a/casic-face-sync/pom.xml b/casic-face-sync/pom.xml new file mode 100644 index 0000000..24dc884 --- /dev/null +++ b/casic-face-sync/pom.xml @@ -0,0 +1,74 @@ + + + 4.0.0 + + com.casic + casic-iris-parent + 1.0.0-SNAPSHOT + ../pom.xml + + + + casic-face-sync + ${pro.version} + jar + casic-face-sync + + + + + + com.casic + casic-core + ${core.version} + + + + com.casic + casic-admin-support + ${admin.version} + + + com.casic + casic-iris-support + ${pro.version} + + + + org.apache.httpcomponents + httpclient + 4.5.3 + + + + org.apache.httpcomponents + httpcore + 4.4.8 + + + + org.apache.httpcomponents + httpmime + 4.5.3 + + + + com.google.code.gson + gson + + + + + + + + src/main/java + + **/*.xml + + + + + \ No newline at end of file diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/constant/FaceSyncConst.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/constant/FaceSyncConst.java new file mode 100644 index 0000000..352d47d --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/constant/FaceSyncConst.java @@ -0,0 +1,29 @@ +package com.casic.missiles.modular.system.constant; + +public class FaceSyncConst { + + /** + * 单次最大批量上传人员数 + */ + public static final int UPLOAD_MAX_PERSON = 6; + + /** + * 上传人员库 + */ + public static final String UPLOAD_STAFF_LIB = "3"; + public static final String UPLOAD_VISITOR_LIB = "4"; + + public static final String UPLOAD_URL_PREFIX = "/LAPI/V1.0/PeopleLibraries/"; + + public static final String UPLOAD_URL_SUFFIX = "/People"; + + public static final int UPLOAD_PERSONCODE_MAXLENGTH = 15; + + public static final int UPLOAD_REMARK_MAXLENGTH = 63; + + public static final String SUBSCRIBE_URL = "/LAPI/V1.0/System/Event/Subscription/"; + + public static final String STAFF_PERSON_TYPE = "1"; + + public static final String VISITOR_PERSON_TYPE = "0"; +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/controller/FaceSyncController.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/controller/FaceSyncController.java new file mode 100644 index 0000000..1b35431 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/controller/FaceSyncController.java @@ -0,0 +1,117 @@ +package com.casic.missiles.modular.system.controller; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson.serializer.SerializerFeature; +import com.casic.missiles.core.base.response.ResponseData; +import com.casic.missiles.core.common.service.ICommonPermissionService; +import com.casic.missiles.core.common.service.ICommonPersonService; +import com.casic.missiles.core.datascope.DataScope; +import com.casic.missiles.core.util.ToolUtil; +import com.casic.missiles.modular.system.request.PersonInfo; +import com.casic.missiles.modular.system.response.RecordNotification; +import com.casic.missiles.modular.system.service.IFaceSyncService; +import com.casic.missiles.modular.system.service.IIrisPersonSupportService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.*; +import com.casic.missiles.modular.system.constant.FaceSyncConst; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + + + +@Controller +public class FaceSyncController { + private final static Logger logger = LoggerFactory.getLogger(FaceSyncController.class); + + @Autowired + private IFaceSyncService syncService; + @Autowired + private ICommonPersonService commonPersonService; + @Autowired + private IIrisPersonSupportService personSupportService; + @Autowired + private ICommonPermissionService permissionService; + + @RequestMapping("/face/upload") + @ResponseBody + public Object upload(@RequestParam("personIds") List personIds, + @RequestParam("deviceIds") List deviceIds, + @RequestParam("personType")String personType ){ + // 检查数量 +// if(personIds.size()>FaceSyncConst.UPLOAD_MAX_PERSON){ +// return ResponseData.error(String.format("每次最多上传%s个人",FaceSyncConst.UPLOAD_MAX_PERSON)); +// } + // 检查照片格式及大小 + String photoCheck = syncService.checkPersonPhoto(personIds); + if(ToolUtil.isNotEmpty(photoCheck)){ + return ResponseData.error(photoCheck); + } + else{ + // 上传数据 + String error = syncService.uploadPerson(personIds,deviceIds,personType); + if(ToolUtil.isNotEmpty(error)){ + return ResponseData.error(error); + } + } + return ResponseData.success(); + } + + @RequestMapping("/face/uploadAll") + @ResponseBody + public Object uploadAll(@RequestParam("deviceIds") List deviceIds){ + DataScope dataScope = permissionService.getCurrUserDataScope(); + + List staffPersonIds = personSupportService.listIdsByType(dataScope,FaceSyncConst.STAFF_PERSON_TYPE); + List visitorPersonIds = personSupportService.listIdsByType(dataScope,FaceSyncConst.VISITOR_PERSON_TYPE); + // 1.检查照片,分别检查员工、访客 + String staffPhotoCheck = syncService.checkPersonPhoto(staffPersonIds); + if(ToolUtil.isNotEmpty(staffPhotoCheck)){ + return ResponseData.error(staffPhotoCheck); + } + String visitorPhotoCheck = syncService.checkPersonPhoto(visitorPersonIds); + if(ToolUtil.isNotEmpty(visitorPhotoCheck)){ + return ResponseData.error(visitorPhotoCheck); + } + + // 2. 下发数据 + String staffError = syncService.uploadPerson(staffPersonIds,deviceIds,FaceSyncConst.STAFF_PERSON_TYPE); + if(ToolUtil.isNotEmpty(staffError)){ + return ResponseData.error(staffError); + } + String visitorError = syncService.uploadPerson(visitorPersonIds,deviceIds,FaceSyncConst.VISITOR_PERSON_TYPE); + if(ToolUtil.isNotEmpty(visitorError)){ + return ResponseData.error(visitorError); + } + + return ResponseData.success(); + } + + // 错误信息返回 + @RequestMapping("/subsrcibe/init") + @ResponseBody + public Object upload(@RequestParam("deviceIds") List deviceIds){ + String errorMsg = syncService.initSubscription(deviceIds); + if(ToolUtil.isNotEmpty(errorMsg)){ + return ResponseData.error(errorMsg); + } + return ResponseData.success(); + } + + + @RequestMapping(value = "/LAPI/V1.0/System/Event/Notification/PersonVerification", method = RequestMethod.POST) + @ResponseBody + public void verification(@RequestBody String recordNotification){ + logger.info(recordNotification); + RecordNotification record = JSONObject.parseObject(recordNotification,RecordNotification.class); + syncService.receiveRecord(record); + //return ResponseData.success(); + } + + +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FacePersonSyncMapper.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FacePersonSyncMapper.java new file mode 100644 index 0000000..af53702 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FacePersonSyncMapper.java @@ -0,0 +1,17 @@ +package com.casic.missiles.modular.system.dao; + +import com.casic.missiles.modular.system.model.FacePersonSync; +import com.baomidou.mybatisplus.mapper.BaseMapper; + +/** + *

+ * Mapper 接口 + *

+ * + * @author zyj123 + * @since 2020-07-24 + */ +public interface FacePersonSyncMapper extends BaseMapper { + + Long getMaxSyncId(); +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FaceSubscribeMapper.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FaceSubscribeMapper.java new file mode 100644 index 0000000..0c6374a --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FaceSubscribeMapper.java @@ -0,0 +1,16 @@ +package com.casic.missiles.modular.system.dao; + +import com.casic.missiles.modular.system.model.FaceSubscribe; +import com.baomidou.mybatisplus.mapper.BaseMapper; + +/** + *

+ * Mapper 接口 + *

+ * + * @author zyj123 + * @since 2020-07-25 + */ +public interface FaceSubscribeMapper extends BaseMapper { + +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FacePersonSyncMapper.xml b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FacePersonSyncMapper.xml new file mode 100644 index 0000000..ac46ad0 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FacePersonSyncMapper.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + PERSON_ID AS personId, SYNC_ID AS syncId + + + + + diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FaceSubscribeMapper.xml b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FaceSubscribeMapper.xml new file mode 100644 index 0000000..16024e2 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FaceSubscribeMapper.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + SUBSCRIBE_ID AS subscribeId, DEVICE_CODE AS deviceCode, UPDATE_TIME AS updateTime + + + diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FacePersonSync.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FacePersonSync.java new file mode 100644 index 0000000..7cdb821 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FacePersonSync.java @@ -0,0 +1,68 @@ +package com.casic.missiles.modular.system.model; + +import java.io.Serializable; + +import com.baomidou.mybatisplus.annotations.TableId; +import com.baomidou.mybatisplus.annotations.TableField; +import com.baomidou.mybatisplus.activerecord.Model; +import com.baomidou.mybatisplus.annotations.TableName; +import java.io.Serializable; + +/** + *

+ * + *

+ * + * @author zyj123 + * @since 2020-07-24 + */ +@TableName("face_person_sync") +public class FacePersonSync extends Model { + + private static final long serialVersionUID = 1L; + + /** + * 人员id + */ + @TableId("PERSON_ID") + private Long personId; + /** + * 人员同步id + */ + @TableField("SYNC_ID") + private Long syncId; + + public FacePersonSync(Long personId, Long syncId) { + this.personId = personId; + this.syncId = syncId; + } + + public Long getPersonId() { + return personId; + } + + public void setPersonId(Long personId) { + this.personId = personId; + } + + public Long getSyncId() { + return syncId; + } + + public void setSyncId(Long syncId) { + this.syncId = syncId; + } + + @Override + protected Serializable pkVal() { + return this.personId; + } + + @Override + public String toString() { + return "FacePersonSync{" + + "personId=" + personId + + ", syncId=" + syncId + + "}"; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FaceSubscribe.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FaceSubscribe.java new file mode 100644 index 0000000..ccc7792 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FaceSubscribe.java @@ -0,0 +1,79 @@ +package com.casic.missiles.modular.system.model; + +import java.io.Serializable; + +import java.util.Date; +import com.baomidou.mybatisplus.annotations.TableId; +import com.baomidou.mybatisplus.annotations.TableField; +import com.baomidou.mybatisplus.activerecord.Model; +import com.baomidou.mybatisplus.annotations.TableName; +import java.io.Serializable; + +/** + *

+ * + *

+ * + * @author zyj123 + * @since 2020-07-25 + */ +@TableName("face_subscribe") +public class FaceSubscribe extends Model { + + private static final long serialVersionUID = 1L; + + /** + * 订阅id + */ + @TableId("SUBSCRIBE_ID") + private Long subscribeId; + /** + * 设备编号 + */ + @TableField("DEVICE_CODE") + private String deviceCode; + /** + * 更新时间 + */ + @TableField("UPDATE_TIME") + private Date updateTime; + + + public Long getSubscribeId() { + return subscribeId; + } + + public void setSubscribeId(Long subscribeId) { + this.subscribeId = subscribeId; + } + + public String getDeviceCode() { + return deviceCode; + } + + public void setDeviceCode(String deviceCode) { + this.deviceCode = deviceCode; + } + + public Date getUpdateTime() { + return updateTime; + } + + public void setUpdateTime(Date updateTime) { + this.updateTime = updateTime; + } + + @Override + protected Serializable pkVal() { + return this.subscribeId; + } + + @Override + public String toString() { + return "FaceSubscribe{" + + "subscribeId=" + subscribeId + + ", deviceCode=" + deviceCode + + ", updateTime=" + updateTime + + "}"; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/request/PersonInfo.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/request/PersonInfo.java new file mode 100644 index 0000000..80d9eff --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/request/PersonInfo.java @@ -0,0 +1,271 @@ +package com.casic.missiles.modular.system.request; + +import com.alibaba.fastjson.annotation.JSONField; +import com.baomidou.mybatisplus.annotations.TableField; +import com.google.gson.annotations.SerializedName; + +import java.util.List; + +public class PersonInfo { + + //@JSONField(name = "PersonID") + @SerializedName("PersonID") + private Long personID; + + //@JSONField(name = "LastChange") + @SerializedName("LastChange") + private Long lastChange; + + //@JSONField(name = "PersonCode") + @SerializedName("PersonCode") + private String personCode; + + //@JSONField(name = "PersonName") + @SerializedName("PersonName") + private String personName; + + //@JSONField(name = "Remarks") + @SerializedName("Remarks") + private String remarks; + + //@JSONField(name = "TimeTemplateNum") + @SerializedName("TimeTemplateNum") + private Integer timeTemplateNum; + + //@JSONField(name = "TimeTemplateList") + @SerializedName("TimeTemplateList") + private List timeTemplateList; + + //@JSONField(name = "IdentificationNum") + @SerializedName("IdentificationNum") + private Integer identificationNum; + + //@JSONField(name = "IdentificationList") + @SerializedName("IdentificationList") + private List identificationList; + + //@JSONField(name = "ImageNum") + @SerializedName("ImageNum") + private Integer imageNum; + + //@JSONField(name = "ImageList") + @SerializedName("ImageList") + private List imageList; + + public Long getPersonID() { + return personID; + } + + public void setPersonID(Long personID) { + this.personID = personID; + } + + public Long getLastChange() { + return lastChange; + } + + public void setLastChange(Long lastChange) { + this.lastChange = lastChange; + } + + public String getPersonCode() { + return personCode; + } + + public void setPersonCode(String personCode) { + this.personCode = personCode; + } + + public String getPersonName() { + return personName; + } + + public void setPersonName(String personName) { + this.personName = personName; + } + + public String getRemarks() { + return remarks; + } + + public void setRemarks(String remarks) { + this.remarks = remarks; + } + + public Integer getTimeTemplateNum() { + return timeTemplateNum; + } + + public void setTimeTemplateNum(Integer timeTemplateNum) { + this.timeTemplateNum = timeTemplateNum; + } + + public List getTimeTemplateList() { + return timeTemplateList; + } + + public void setTimeTemplateList(List timeTemplateList) { + this.timeTemplateList = timeTemplateList; + } + + public Integer getIdentificationNum() { + return identificationNum; + } + + public void setIdentificationNum(Integer identificationNum) { + this.identificationNum = identificationNum; + } + + public List getIdentificationList() { + return identificationList; + } + + public void setIdentificationList(List identificationList) { + this.identificationList = identificationList; + } + + public Integer getImageNum() { + return imageNum; + } + + public void setImageNum(Integer imageNum) { + this.imageNum = imageNum; + } + + public List getImageList() { + return imageList; + } + + public void setImageList(List imageList) { + this.imageList = imageList; + } + + public class TimeTemplate{ + @JSONField(name = "BeginTime") + private Long beginTime; + @JSONField(name = "EndTime") + private Long endTime; + @JSONField(name = "Index") + private Long index; + + public TimeTemplate(Long beginTime, Long endTime, Long index) { + this.beginTime = beginTime; + this.endTime = endTime; + this.index = index; + } + + public Long getBeginTime() { + return beginTime; + } + + public void setBeginTime(Long beginTime) { + this.beginTime = beginTime; + } + + public Long getEndTime() { + return endTime; + } + + public void setEndTime(Long endTime) { + this.endTime = endTime; + } + + public Long getIndex() { + return index; + } + + public void setIndex(Long index) { + this.index = index; + } + } + + public TimeTemplate createTimeTemplate(Long beginTime, Long endTime, Long index){ + return new TimeTemplate(beginTime, endTime, index); + } + + public class IdentificationInfo { + @JSONField(name = "Type") + private Integer type; + @JSONField(name = "Number") + private String number; + + public IdentificationInfo(Integer type, String number) { + this.type = type; + this.number = number; + } + + public Integer getType() { + return type; + } + + public void setType(Integer type) { + this.type = type; + } + + public String getNumber() { + return number; + } + + public void setNumber(String number) { + this.number = number; + } + } + + public IdentificationInfo createIdentificationInfo(Integer type, String number){ + return new IdentificationInfo(type,number); + } + + public class ImageInfo{ + @JSONField(name = "FaceID") + private Long faceID; + @JSONField(name = "Name") + private String name; + @JSONField(name = "Size") + private Long size; + @JSONField(name = "Data") + private String data; + + public ImageInfo(Long faceID, String name, Long size, String data) { + this.faceID = faceID; + this.name = name; + this.size = size; + this.data = data; + } + + public Long getFaceID() { + return faceID; + } + + public void setFaceID(Long faceID) { + this.faceID = faceID; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Long getSize() { + return size; + } + + public void setSize(Long size) { + this.size = size; + } + + public String getData() { + return data; + } + + public void setData(String data) { + this.data = data; + } + } + + public ImageInfo createImageInfo(Long faceID, String name, Long size, String data){ + return new ImageInfo(faceID, name, size, data); + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceBaseResponse.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceBaseResponse.java new file mode 100644 index 0000000..fe93b8a --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceBaseResponse.java @@ -0,0 +1,90 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; +import com.google.gson.annotations.SerializedName; + +public class FaceBaseResponse { + @JSONField(name = "ResponseURL") + @SerializedName("ResponseURL") + private String responseUrl; + + @JSONField(name = "CreatedID") + @SerializedName("CreatedID") + private int createdId; + + @JSONField(name = "ResponseCode") + @SerializedName("ResponseCode") + private int responseCode; + + @JSONField(name = "ResponseString") + @SerializedName("ResponseString") + private String responseString; + + @JSONField(name = "StatusCode") + @SerializedName("StatusCode") + private int statusCode; + + @JSONField(name = "StatusString") + @SerializedName("StatusString") + private String statusString; + + //@JSONField(name = "Data") + @SerializedName("Data") + private T data; + + public String getResponseUrl() { + return responseUrl; + } + + public void setResponseUrl(String responseUrl) { + this.responseUrl = responseUrl; + } + + public int getCreatedId() { + return createdId; + } + + public void setCreatedId(int createdId) { + this.createdId = createdId; + } + + public int getResponseCode() { + return responseCode; + } + + public void setResponseCode(int responseCode) { + this.responseCode = responseCode; + } + + public String getResponseString() { + return responseString; + } + + public void setResponseString(String responseString) { + this.responseString = responseString; + } + + public int getStatusCode() { + return statusCode; + } + + public void setStatusCode(int statusCode) { + this.statusCode = statusCode; + } + + public String getStatusString() { + return statusString; + } + + public void setStatusString(String statusString) { + this.statusString = statusString; + } + + public T getData() { + return data; + } + + public void setData(T data) { + this.data = data; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceInfo.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceInfo.java new file mode 100644 index 0000000..f128c92 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceInfo.java @@ -0,0 +1,128 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; + +import java.util.List; + +public class FaceInfo { + @JSONField(name = "ID") + private Long id; + @JSONField(name = "Timestamp") + private Long timestamp; + @JSONField(name = "CapSrc") + private Long capSrc; + @JSONField(name = "FeatureNum") + private Long featureNum; + @JSONField(name = "FeatureList") + private List featureList; + @JSONField(name = "FeatureVersion") + private String featureVersion; + @JSONField(name = "Feature") + private String feature; + @JSONField(name = "Temperature") + private Float temperature; + @JSONField(name = "MaskFlag") + private Long maskFlag; + @JSONField(name = "PanoImage") + private Object panoImage; + @JSONField(name = "FaceImage") + private Object faceImage; + @JSONField(name = "FaceArea") + private Object faceArea; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Long getTimestamp() { + return timestamp; + } + + public void setTimestamp(Long timestamp) { + this.timestamp = timestamp; + } + + public Long getCapSrc() { + return capSrc; + } + + public void setCapSrc(Long capSrc) { + this.capSrc = capSrc; + } + + public Long getFeatureNum() { + return featureNum; + } + + public void setFeatureNum(Long featureNum) { + this.featureNum = featureNum; + } + + public List getFeatureList() { + return featureList; + } + + public void setFeatureList(List featureList) { + this.featureList = featureList; + } + + public String getFeatureVersion() { + return featureVersion; + } + + public void setFeatureVersion(String featureVersion) { + this.featureVersion = featureVersion; + } + + public String getFeature() { + return feature; + } + + public void setFeature(String feature) { + this.feature = feature; + } + + public Float getTemperature() { + return temperature; + } + + public void setTemperature(Float temperature) { + this.temperature = temperature; + } + + public Long getMaskFlag() { + return maskFlag; + } + + public void setMaskFlag(Long maskFlag) { + this.maskFlag = maskFlag; + } + + public Object getPanoImage() { + return panoImage; + } + + public void setPanoImage(Object panoImage) { + this.panoImage = panoImage; + } + + public Object getFaceImage() { + return faceImage; + } + + public void setFaceImage(Object faceImage) { + this.faceImage = faceImage; + } + + public Object getFaceArea() { + return faceArea; + } + + public void setFaceArea(Object faceArea) { + this.faceArea = faceArea; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/LibMatInfo.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/LibMatInfo.java new file mode 100644 index 0000000..ce6dd33 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/LibMatInfo.java @@ -0,0 +1,69 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; + +public class LibMatInfo { + @JSONField(name = "ID") + private Long id; + @JSONField(name = "LibID") + private Long libId; + @JSONField(name = "LibType") + private Long libType; + @JSONField(name = "MatchStatus") + private Long matchStatus; + @JSONField(name = "MatchPersonID") + private Long matchPersonId; + @JSONField(name = "MatchFaceID") + private Long matchFaceId; + + // MatchPersonInfo 暂时忽略不用 + + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Long getLibId() { + return libId; + } + + public void setLibId(Long libId) { + this.libId = libId; + } + + public Long getLibType() { + return libType; + } + + public void setLibType(Long libType) { + this.libType = libType; + } + + public Long getMatchStatus() { + return matchStatus; + } + + public void setMatchStatus(Long matchStatus) { + this.matchStatus = matchStatus; + } + + public Long getMatchPersonId() { + return matchPersonId; + } + + public void setMatchPersonId(Long matchPersonId) { + this.matchPersonId = matchPersonId; + } + + public Long getMatchFaceId() { + return matchFaceId; + } + + public void setMatchFaceId(Long matchFaceId) { + this.matchFaceId = matchFaceId; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/PersonResponseData.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/PersonResponseData.java new file mode 100644 index 0000000..186faed --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/PersonResponseData.java @@ -0,0 +1,31 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; +import com.google.gson.annotations.SerializedName; + +import java.util.List; + +public class PersonResponseData { + @JSONField(name = "Num") + @SerializedName("Num") + private int num; + @JSONField(name = "PersonList") + @SerializedName("PersonList") + private List personList; + + public int getNum() { + return num; + } + + public void setNum(int num) { + this.num = num; + } + + public List getPersonList() { + return personList; + } + + public void setPersonList(List personList) { + this.personList = personList; + } +} diff --git a/casic-face-sync/pom.xml b/casic-face-sync/pom.xml new file mode 100644 index 0000000..24dc884 --- /dev/null +++ b/casic-face-sync/pom.xml @@ -0,0 +1,74 @@ + + + 4.0.0 + + com.casic + casic-iris-parent + 1.0.0-SNAPSHOT + ../pom.xml + + + + casic-face-sync + ${pro.version} + jar + casic-face-sync + + + + + + com.casic + casic-core + ${core.version} + + + + com.casic + casic-admin-support + ${admin.version} + + + com.casic + casic-iris-support + ${pro.version} + + + + org.apache.httpcomponents + httpclient + 4.5.3 + + + + org.apache.httpcomponents + httpcore + 4.4.8 + + + + org.apache.httpcomponents + httpmime + 4.5.3 + + + + com.google.code.gson + gson + + + + + + + + src/main/java + + **/*.xml + + + + + \ No newline at end of file diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/constant/FaceSyncConst.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/constant/FaceSyncConst.java new file mode 100644 index 0000000..352d47d --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/constant/FaceSyncConst.java @@ -0,0 +1,29 @@ +package com.casic.missiles.modular.system.constant; + +public class FaceSyncConst { + + /** + * 单次最大批量上传人员数 + */ + public static final int UPLOAD_MAX_PERSON = 6; + + /** + * 上传人员库 + */ + public static final String UPLOAD_STAFF_LIB = "3"; + public static final String UPLOAD_VISITOR_LIB = "4"; + + public static final String UPLOAD_URL_PREFIX = "/LAPI/V1.0/PeopleLibraries/"; + + public static final String UPLOAD_URL_SUFFIX = "/People"; + + public static final int UPLOAD_PERSONCODE_MAXLENGTH = 15; + + public static final int UPLOAD_REMARK_MAXLENGTH = 63; + + public static final String SUBSCRIBE_URL = "/LAPI/V1.0/System/Event/Subscription/"; + + public static final String STAFF_PERSON_TYPE = "1"; + + public static final String VISITOR_PERSON_TYPE = "0"; +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/controller/FaceSyncController.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/controller/FaceSyncController.java new file mode 100644 index 0000000..1b35431 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/controller/FaceSyncController.java @@ -0,0 +1,117 @@ +package com.casic.missiles.modular.system.controller; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson.serializer.SerializerFeature; +import com.casic.missiles.core.base.response.ResponseData; +import com.casic.missiles.core.common.service.ICommonPermissionService; +import com.casic.missiles.core.common.service.ICommonPersonService; +import com.casic.missiles.core.datascope.DataScope; +import com.casic.missiles.core.util.ToolUtil; +import com.casic.missiles.modular.system.request.PersonInfo; +import com.casic.missiles.modular.system.response.RecordNotification; +import com.casic.missiles.modular.system.service.IFaceSyncService; +import com.casic.missiles.modular.system.service.IIrisPersonSupportService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.*; +import com.casic.missiles.modular.system.constant.FaceSyncConst; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + + + +@Controller +public class FaceSyncController { + private final static Logger logger = LoggerFactory.getLogger(FaceSyncController.class); + + @Autowired + private IFaceSyncService syncService; + @Autowired + private ICommonPersonService commonPersonService; + @Autowired + private IIrisPersonSupportService personSupportService; + @Autowired + private ICommonPermissionService permissionService; + + @RequestMapping("/face/upload") + @ResponseBody + public Object upload(@RequestParam("personIds") List personIds, + @RequestParam("deviceIds") List deviceIds, + @RequestParam("personType")String personType ){ + // 检查数量 +// if(personIds.size()>FaceSyncConst.UPLOAD_MAX_PERSON){ +// return ResponseData.error(String.format("每次最多上传%s个人",FaceSyncConst.UPLOAD_MAX_PERSON)); +// } + // 检查照片格式及大小 + String photoCheck = syncService.checkPersonPhoto(personIds); + if(ToolUtil.isNotEmpty(photoCheck)){ + return ResponseData.error(photoCheck); + } + else{ + // 上传数据 + String error = syncService.uploadPerson(personIds,deviceIds,personType); + if(ToolUtil.isNotEmpty(error)){ + return ResponseData.error(error); + } + } + return ResponseData.success(); + } + + @RequestMapping("/face/uploadAll") + @ResponseBody + public Object uploadAll(@RequestParam("deviceIds") List deviceIds){ + DataScope dataScope = permissionService.getCurrUserDataScope(); + + List staffPersonIds = personSupportService.listIdsByType(dataScope,FaceSyncConst.STAFF_PERSON_TYPE); + List visitorPersonIds = personSupportService.listIdsByType(dataScope,FaceSyncConst.VISITOR_PERSON_TYPE); + // 1.检查照片,分别检查员工、访客 + String staffPhotoCheck = syncService.checkPersonPhoto(staffPersonIds); + if(ToolUtil.isNotEmpty(staffPhotoCheck)){ + return ResponseData.error(staffPhotoCheck); + } + String visitorPhotoCheck = syncService.checkPersonPhoto(visitorPersonIds); + if(ToolUtil.isNotEmpty(visitorPhotoCheck)){ + return ResponseData.error(visitorPhotoCheck); + } + + // 2. 下发数据 + String staffError = syncService.uploadPerson(staffPersonIds,deviceIds,FaceSyncConst.STAFF_PERSON_TYPE); + if(ToolUtil.isNotEmpty(staffError)){ + return ResponseData.error(staffError); + } + String visitorError = syncService.uploadPerson(visitorPersonIds,deviceIds,FaceSyncConst.VISITOR_PERSON_TYPE); + if(ToolUtil.isNotEmpty(visitorError)){ + return ResponseData.error(visitorError); + } + + return ResponseData.success(); + } + + // 错误信息返回 + @RequestMapping("/subsrcibe/init") + @ResponseBody + public Object upload(@RequestParam("deviceIds") List deviceIds){ + String errorMsg = syncService.initSubscription(deviceIds); + if(ToolUtil.isNotEmpty(errorMsg)){ + return ResponseData.error(errorMsg); + } + return ResponseData.success(); + } + + + @RequestMapping(value = "/LAPI/V1.0/System/Event/Notification/PersonVerification", method = RequestMethod.POST) + @ResponseBody + public void verification(@RequestBody String recordNotification){ + logger.info(recordNotification); + RecordNotification record = JSONObject.parseObject(recordNotification,RecordNotification.class); + syncService.receiveRecord(record); + //return ResponseData.success(); + } + + +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FacePersonSyncMapper.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FacePersonSyncMapper.java new file mode 100644 index 0000000..af53702 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FacePersonSyncMapper.java @@ -0,0 +1,17 @@ +package com.casic.missiles.modular.system.dao; + +import com.casic.missiles.modular.system.model.FacePersonSync; +import com.baomidou.mybatisplus.mapper.BaseMapper; + +/** + *

+ * Mapper 接口 + *

+ * + * @author zyj123 + * @since 2020-07-24 + */ +public interface FacePersonSyncMapper extends BaseMapper { + + Long getMaxSyncId(); +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FaceSubscribeMapper.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FaceSubscribeMapper.java new file mode 100644 index 0000000..0c6374a --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FaceSubscribeMapper.java @@ -0,0 +1,16 @@ +package com.casic.missiles.modular.system.dao; + +import com.casic.missiles.modular.system.model.FaceSubscribe; +import com.baomidou.mybatisplus.mapper.BaseMapper; + +/** + *

+ * Mapper 接口 + *

+ * + * @author zyj123 + * @since 2020-07-25 + */ +public interface FaceSubscribeMapper extends BaseMapper { + +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FacePersonSyncMapper.xml b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FacePersonSyncMapper.xml new file mode 100644 index 0000000..ac46ad0 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FacePersonSyncMapper.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + PERSON_ID AS personId, SYNC_ID AS syncId + + + + + diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FaceSubscribeMapper.xml b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FaceSubscribeMapper.xml new file mode 100644 index 0000000..16024e2 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FaceSubscribeMapper.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + SUBSCRIBE_ID AS subscribeId, DEVICE_CODE AS deviceCode, UPDATE_TIME AS updateTime + + + diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FacePersonSync.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FacePersonSync.java new file mode 100644 index 0000000..7cdb821 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FacePersonSync.java @@ -0,0 +1,68 @@ +package com.casic.missiles.modular.system.model; + +import java.io.Serializable; + +import com.baomidou.mybatisplus.annotations.TableId; +import com.baomidou.mybatisplus.annotations.TableField; +import com.baomidou.mybatisplus.activerecord.Model; +import com.baomidou.mybatisplus.annotations.TableName; +import java.io.Serializable; + +/** + *

+ * + *

+ * + * @author zyj123 + * @since 2020-07-24 + */ +@TableName("face_person_sync") +public class FacePersonSync extends Model { + + private static final long serialVersionUID = 1L; + + /** + * 人员id + */ + @TableId("PERSON_ID") + private Long personId; + /** + * 人员同步id + */ + @TableField("SYNC_ID") + private Long syncId; + + public FacePersonSync(Long personId, Long syncId) { + this.personId = personId; + this.syncId = syncId; + } + + public Long getPersonId() { + return personId; + } + + public void setPersonId(Long personId) { + this.personId = personId; + } + + public Long getSyncId() { + return syncId; + } + + public void setSyncId(Long syncId) { + this.syncId = syncId; + } + + @Override + protected Serializable pkVal() { + return this.personId; + } + + @Override + public String toString() { + return "FacePersonSync{" + + "personId=" + personId + + ", syncId=" + syncId + + "}"; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FaceSubscribe.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FaceSubscribe.java new file mode 100644 index 0000000..ccc7792 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FaceSubscribe.java @@ -0,0 +1,79 @@ +package com.casic.missiles.modular.system.model; + +import java.io.Serializable; + +import java.util.Date; +import com.baomidou.mybatisplus.annotations.TableId; +import com.baomidou.mybatisplus.annotations.TableField; +import com.baomidou.mybatisplus.activerecord.Model; +import com.baomidou.mybatisplus.annotations.TableName; +import java.io.Serializable; + +/** + *

+ * + *

+ * + * @author zyj123 + * @since 2020-07-25 + */ +@TableName("face_subscribe") +public class FaceSubscribe extends Model { + + private static final long serialVersionUID = 1L; + + /** + * 订阅id + */ + @TableId("SUBSCRIBE_ID") + private Long subscribeId; + /** + * 设备编号 + */ + @TableField("DEVICE_CODE") + private String deviceCode; + /** + * 更新时间 + */ + @TableField("UPDATE_TIME") + private Date updateTime; + + + public Long getSubscribeId() { + return subscribeId; + } + + public void setSubscribeId(Long subscribeId) { + this.subscribeId = subscribeId; + } + + public String getDeviceCode() { + return deviceCode; + } + + public void setDeviceCode(String deviceCode) { + this.deviceCode = deviceCode; + } + + public Date getUpdateTime() { + return updateTime; + } + + public void setUpdateTime(Date updateTime) { + this.updateTime = updateTime; + } + + @Override + protected Serializable pkVal() { + return this.subscribeId; + } + + @Override + public String toString() { + return "FaceSubscribe{" + + "subscribeId=" + subscribeId + + ", deviceCode=" + deviceCode + + ", updateTime=" + updateTime + + "}"; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/request/PersonInfo.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/request/PersonInfo.java new file mode 100644 index 0000000..80d9eff --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/request/PersonInfo.java @@ -0,0 +1,271 @@ +package com.casic.missiles.modular.system.request; + +import com.alibaba.fastjson.annotation.JSONField; +import com.baomidou.mybatisplus.annotations.TableField; +import com.google.gson.annotations.SerializedName; + +import java.util.List; + +public class PersonInfo { + + //@JSONField(name = "PersonID") + @SerializedName("PersonID") + private Long personID; + + //@JSONField(name = "LastChange") + @SerializedName("LastChange") + private Long lastChange; + + //@JSONField(name = "PersonCode") + @SerializedName("PersonCode") + private String personCode; + + //@JSONField(name = "PersonName") + @SerializedName("PersonName") + private String personName; + + //@JSONField(name = "Remarks") + @SerializedName("Remarks") + private String remarks; + + //@JSONField(name = "TimeTemplateNum") + @SerializedName("TimeTemplateNum") + private Integer timeTemplateNum; + + //@JSONField(name = "TimeTemplateList") + @SerializedName("TimeTemplateList") + private List timeTemplateList; + + //@JSONField(name = "IdentificationNum") + @SerializedName("IdentificationNum") + private Integer identificationNum; + + //@JSONField(name = "IdentificationList") + @SerializedName("IdentificationList") + private List identificationList; + + //@JSONField(name = "ImageNum") + @SerializedName("ImageNum") + private Integer imageNum; + + //@JSONField(name = "ImageList") + @SerializedName("ImageList") + private List imageList; + + public Long getPersonID() { + return personID; + } + + public void setPersonID(Long personID) { + this.personID = personID; + } + + public Long getLastChange() { + return lastChange; + } + + public void setLastChange(Long lastChange) { + this.lastChange = lastChange; + } + + public String getPersonCode() { + return personCode; + } + + public void setPersonCode(String personCode) { + this.personCode = personCode; + } + + public String getPersonName() { + return personName; + } + + public void setPersonName(String personName) { + this.personName = personName; + } + + public String getRemarks() { + return remarks; + } + + public void setRemarks(String remarks) { + this.remarks = remarks; + } + + public Integer getTimeTemplateNum() { + return timeTemplateNum; + } + + public void setTimeTemplateNum(Integer timeTemplateNum) { + this.timeTemplateNum = timeTemplateNum; + } + + public List getTimeTemplateList() { + return timeTemplateList; + } + + public void setTimeTemplateList(List timeTemplateList) { + this.timeTemplateList = timeTemplateList; + } + + public Integer getIdentificationNum() { + return identificationNum; + } + + public void setIdentificationNum(Integer identificationNum) { + this.identificationNum = identificationNum; + } + + public List getIdentificationList() { + return identificationList; + } + + public void setIdentificationList(List identificationList) { + this.identificationList = identificationList; + } + + public Integer getImageNum() { + return imageNum; + } + + public void setImageNum(Integer imageNum) { + this.imageNum = imageNum; + } + + public List getImageList() { + return imageList; + } + + public void setImageList(List imageList) { + this.imageList = imageList; + } + + public class TimeTemplate{ + @JSONField(name = "BeginTime") + private Long beginTime; + @JSONField(name = "EndTime") + private Long endTime; + @JSONField(name = "Index") + private Long index; + + public TimeTemplate(Long beginTime, Long endTime, Long index) { + this.beginTime = beginTime; + this.endTime = endTime; + this.index = index; + } + + public Long getBeginTime() { + return beginTime; + } + + public void setBeginTime(Long beginTime) { + this.beginTime = beginTime; + } + + public Long getEndTime() { + return endTime; + } + + public void setEndTime(Long endTime) { + this.endTime = endTime; + } + + public Long getIndex() { + return index; + } + + public void setIndex(Long index) { + this.index = index; + } + } + + public TimeTemplate createTimeTemplate(Long beginTime, Long endTime, Long index){ + return new TimeTemplate(beginTime, endTime, index); + } + + public class IdentificationInfo { + @JSONField(name = "Type") + private Integer type; + @JSONField(name = "Number") + private String number; + + public IdentificationInfo(Integer type, String number) { + this.type = type; + this.number = number; + } + + public Integer getType() { + return type; + } + + public void setType(Integer type) { + this.type = type; + } + + public String getNumber() { + return number; + } + + public void setNumber(String number) { + this.number = number; + } + } + + public IdentificationInfo createIdentificationInfo(Integer type, String number){ + return new IdentificationInfo(type,number); + } + + public class ImageInfo{ + @JSONField(name = "FaceID") + private Long faceID; + @JSONField(name = "Name") + private String name; + @JSONField(name = "Size") + private Long size; + @JSONField(name = "Data") + private String data; + + public ImageInfo(Long faceID, String name, Long size, String data) { + this.faceID = faceID; + this.name = name; + this.size = size; + this.data = data; + } + + public Long getFaceID() { + return faceID; + } + + public void setFaceID(Long faceID) { + this.faceID = faceID; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Long getSize() { + return size; + } + + public void setSize(Long size) { + this.size = size; + } + + public String getData() { + return data; + } + + public void setData(String data) { + this.data = data; + } + } + + public ImageInfo createImageInfo(Long faceID, String name, Long size, String data){ + return new ImageInfo(faceID, name, size, data); + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceBaseResponse.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceBaseResponse.java new file mode 100644 index 0000000..fe93b8a --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceBaseResponse.java @@ -0,0 +1,90 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; +import com.google.gson.annotations.SerializedName; + +public class FaceBaseResponse { + @JSONField(name = "ResponseURL") + @SerializedName("ResponseURL") + private String responseUrl; + + @JSONField(name = "CreatedID") + @SerializedName("CreatedID") + private int createdId; + + @JSONField(name = "ResponseCode") + @SerializedName("ResponseCode") + private int responseCode; + + @JSONField(name = "ResponseString") + @SerializedName("ResponseString") + private String responseString; + + @JSONField(name = "StatusCode") + @SerializedName("StatusCode") + private int statusCode; + + @JSONField(name = "StatusString") + @SerializedName("StatusString") + private String statusString; + + //@JSONField(name = "Data") + @SerializedName("Data") + private T data; + + public String getResponseUrl() { + return responseUrl; + } + + public void setResponseUrl(String responseUrl) { + this.responseUrl = responseUrl; + } + + public int getCreatedId() { + return createdId; + } + + public void setCreatedId(int createdId) { + this.createdId = createdId; + } + + public int getResponseCode() { + return responseCode; + } + + public void setResponseCode(int responseCode) { + this.responseCode = responseCode; + } + + public String getResponseString() { + return responseString; + } + + public void setResponseString(String responseString) { + this.responseString = responseString; + } + + public int getStatusCode() { + return statusCode; + } + + public void setStatusCode(int statusCode) { + this.statusCode = statusCode; + } + + public String getStatusString() { + return statusString; + } + + public void setStatusString(String statusString) { + this.statusString = statusString; + } + + public T getData() { + return data; + } + + public void setData(T data) { + this.data = data; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceInfo.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceInfo.java new file mode 100644 index 0000000..f128c92 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceInfo.java @@ -0,0 +1,128 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; + +import java.util.List; + +public class FaceInfo { + @JSONField(name = "ID") + private Long id; + @JSONField(name = "Timestamp") + private Long timestamp; + @JSONField(name = "CapSrc") + private Long capSrc; + @JSONField(name = "FeatureNum") + private Long featureNum; + @JSONField(name = "FeatureList") + private List featureList; + @JSONField(name = "FeatureVersion") + private String featureVersion; + @JSONField(name = "Feature") + private String feature; + @JSONField(name = "Temperature") + private Float temperature; + @JSONField(name = "MaskFlag") + private Long maskFlag; + @JSONField(name = "PanoImage") + private Object panoImage; + @JSONField(name = "FaceImage") + private Object faceImage; + @JSONField(name = "FaceArea") + private Object faceArea; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Long getTimestamp() { + return timestamp; + } + + public void setTimestamp(Long timestamp) { + this.timestamp = timestamp; + } + + public Long getCapSrc() { + return capSrc; + } + + public void setCapSrc(Long capSrc) { + this.capSrc = capSrc; + } + + public Long getFeatureNum() { + return featureNum; + } + + public void setFeatureNum(Long featureNum) { + this.featureNum = featureNum; + } + + public List getFeatureList() { + return featureList; + } + + public void setFeatureList(List featureList) { + this.featureList = featureList; + } + + public String getFeatureVersion() { + return featureVersion; + } + + public void setFeatureVersion(String featureVersion) { + this.featureVersion = featureVersion; + } + + public String getFeature() { + return feature; + } + + public void setFeature(String feature) { + this.feature = feature; + } + + public Float getTemperature() { + return temperature; + } + + public void setTemperature(Float temperature) { + this.temperature = temperature; + } + + public Long getMaskFlag() { + return maskFlag; + } + + public void setMaskFlag(Long maskFlag) { + this.maskFlag = maskFlag; + } + + public Object getPanoImage() { + return panoImage; + } + + public void setPanoImage(Object panoImage) { + this.panoImage = panoImage; + } + + public Object getFaceImage() { + return faceImage; + } + + public void setFaceImage(Object faceImage) { + this.faceImage = faceImage; + } + + public Object getFaceArea() { + return faceArea; + } + + public void setFaceArea(Object faceArea) { + this.faceArea = faceArea; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/LibMatInfo.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/LibMatInfo.java new file mode 100644 index 0000000..ce6dd33 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/LibMatInfo.java @@ -0,0 +1,69 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; + +public class LibMatInfo { + @JSONField(name = "ID") + private Long id; + @JSONField(name = "LibID") + private Long libId; + @JSONField(name = "LibType") + private Long libType; + @JSONField(name = "MatchStatus") + private Long matchStatus; + @JSONField(name = "MatchPersonID") + private Long matchPersonId; + @JSONField(name = "MatchFaceID") + private Long matchFaceId; + + // MatchPersonInfo 暂时忽略不用 + + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Long getLibId() { + return libId; + } + + public void setLibId(Long libId) { + this.libId = libId; + } + + public Long getLibType() { + return libType; + } + + public void setLibType(Long libType) { + this.libType = libType; + } + + public Long getMatchStatus() { + return matchStatus; + } + + public void setMatchStatus(Long matchStatus) { + this.matchStatus = matchStatus; + } + + public Long getMatchPersonId() { + return matchPersonId; + } + + public void setMatchPersonId(Long matchPersonId) { + this.matchPersonId = matchPersonId; + } + + public Long getMatchFaceId() { + return matchFaceId; + } + + public void setMatchFaceId(Long matchFaceId) { + this.matchFaceId = matchFaceId; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/PersonResponseData.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/PersonResponseData.java new file mode 100644 index 0000000..186faed --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/PersonResponseData.java @@ -0,0 +1,31 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; +import com.google.gson.annotations.SerializedName; + +import java.util.List; + +public class PersonResponseData { + @JSONField(name = "Num") + @SerializedName("Num") + private int num; + @JSONField(name = "PersonList") + @SerializedName("PersonList") + private List personList; + + public int getNum() { + return num; + } + + public void setNum(int num) { + this.num = num; + } + + public List getPersonList() { + return personList; + } + + public void setPersonList(List personList) { + this.personList = personList; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/PersonResponseInfo.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/PersonResponseInfo.java new file mode 100644 index 0000000..7ba3edc --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/PersonResponseInfo.java @@ -0,0 +1,67 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; +import com.google.gson.annotations.SerializedName; + +import java.util.List; + +public class PersonResponseInfo { + @JSONField(name = "PersonID") + @SerializedName("PersonID") + private Long personId; + @JSONField(name = "FaceNum") + @SerializedName("FaceNum") + private Long faceNum; + @JSONField(name = "FaceList") + @SerializedName("FaceList") + private List faceList; + + public Long getPersonId() { + return personId; + } + + public void setPersonId(Long personId) { + this.personId = personId; + } + + public Long getFaceNum() { + return faceNum; + } + + public void setFaceNum(Long faceNum) { + this.faceNum = faceNum; + } + + public List getFaceList() { + return faceList; + } + + public void setFaceList(List faceList) { + this.faceList = faceList; + } + + public class PersonResponseFace{ + @JSONField(name = "FaceID") + @SerializedName("FaceID") + private Long faceId; + @JSONField(name = "ResultCode") + @SerializedName("ResultCode") + private Long resultCode; + + public Long getFaceId() { + return faceId; + } + + public void setFaceId(Long faceId) { + this.faceId = faceId; + } + + public Long getResultCode() { + return resultCode; + } + + public void setResultCode(Long resultCode) { + this.resultCode = resultCode; + } + } +} diff --git a/casic-face-sync/pom.xml b/casic-face-sync/pom.xml new file mode 100644 index 0000000..24dc884 --- /dev/null +++ b/casic-face-sync/pom.xml @@ -0,0 +1,74 @@ + + + 4.0.0 + + com.casic + casic-iris-parent + 1.0.0-SNAPSHOT + ../pom.xml + + + + casic-face-sync + ${pro.version} + jar + casic-face-sync + + + + + + com.casic + casic-core + ${core.version} + + + + com.casic + casic-admin-support + ${admin.version} + + + com.casic + casic-iris-support + ${pro.version} + + + + org.apache.httpcomponents + httpclient + 4.5.3 + + + + org.apache.httpcomponents + httpcore + 4.4.8 + + + + org.apache.httpcomponents + httpmime + 4.5.3 + + + + com.google.code.gson + gson + + + + + + + + src/main/java + + **/*.xml + + + + + \ No newline at end of file diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/constant/FaceSyncConst.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/constant/FaceSyncConst.java new file mode 100644 index 0000000..352d47d --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/constant/FaceSyncConst.java @@ -0,0 +1,29 @@ +package com.casic.missiles.modular.system.constant; + +public class FaceSyncConst { + + /** + * 单次最大批量上传人员数 + */ + public static final int UPLOAD_MAX_PERSON = 6; + + /** + * 上传人员库 + */ + public static final String UPLOAD_STAFF_LIB = "3"; + public static final String UPLOAD_VISITOR_LIB = "4"; + + public static final String UPLOAD_URL_PREFIX = "/LAPI/V1.0/PeopleLibraries/"; + + public static final String UPLOAD_URL_SUFFIX = "/People"; + + public static final int UPLOAD_PERSONCODE_MAXLENGTH = 15; + + public static final int UPLOAD_REMARK_MAXLENGTH = 63; + + public static final String SUBSCRIBE_URL = "/LAPI/V1.0/System/Event/Subscription/"; + + public static final String STAFF_PERSON_TYPE = "1"; + + public static final String VISITOR_PERSON_TYPE = "0"; +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/controller/FaceSyncController.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/controller/FaceSyncController.java new file mode 100644 index 0000000..1b35431 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/controller/FaceSyncController.java @@ -0,0 +1,117 @@ +package com.casic.missiles.modular.system.controller; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson.serializer.SerializerFeature; +import com.casic.missiles.core.base.response.ResponseData; +import com.casic.missiles.core.common.service.ICommonPermissionService; +import com.casic.missiles.core.common.service.ICommonPersonService; +import com.casic.missiles.core.datascope.DataScope; +import com.casic.missiles.core.util.ToolUtil; +import com.casic.missiles.modular.system.request.PersonInfo; +import com.casic.missiles.modular.system.response.RecordNotification; +import com.casic.missiles.modular.system.service.IFaceSyncService; +import com.casic.missiles.modular.system.service.IIrisPersonSupportService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.*; +import com.casic.missiles.modular.system.constant.FaceSyncConst; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + + + +@Controller +public class FaceSyncController { + private final static Logger logger = LoggerFactory.getLogger(FaceSyncController.class); + + @Autowired + private IFaceSyncService syncService; + @Autowired + private ICommonPersonService commonPersonService; + @Autowired + private IIrisPersonSupportService personSupportService; + @Autowired + private ICommonPermissionService permissionService; + + @RequestMapping("/face/upload") + @ResponseBody + public Object upload(@RequestParam("personIds") List personIds, + @RequestParam("deviceIds") List deviceIds, + @RequestParam("personType")String personType ){ + // 检查数量 +// if(personIds.size()>FaceSyncConst.UPLOAD_MAX_PERSON){ +// return ResponseData.error(String.format("每次最多上传%s个人",FaceSyncConst.UPLOAD_MAX_PERSON)); +// } + // 检查照片格式及大小 + String photoCheck = syncService.checkPersonPhoto(personIds); + if(ToolUtil.isNotEmpty(photoCheck)){ + return ResponseData.error(photoCheck); + } + else{ + // 上传数据 + String error = syncService.uploadPerson(personIds,deviceIds,personType); + if(ToolUtil.isNotEmpty(error)){ + return ResponseData.error(error); + } + } + return ResponseData.success(); + } + + @RequestMapping("/face/uploadAll") + @ResponseBody + public Object uploadAll(@RequestParam("deviceIds") List deviceIds){ + DataScope dataScope = permissionService.getCurrUserDataScope(); + + List staffPersonIds = personSupportService.listIdsByType(dataScope,FaceSyncConst.STAFF_PERSON_TYPE); + List visitorPersonIds = personSupportService.listIdsByType(dataScope,FaceSyncConst.VISITOR_PERSON_TYPE); + // 1.检查照片,分别检查员工、访客 + String staffPhotoCheck = syncService.checkPersonPhoto(staffPersonIds); + if(ToolUtil.isNotEmpty(staffPhotoCheck)){ + return ResponseData.error(staffPhotoCheck); + } + String visitorPhotoCheck = syncService.checkPersonPhoto(visitorPersonIds); + if(ToolUtil.isNotEmpty(visitorPhotoCheck)){ + return ResponseData.error(visitorPhotoCheck); + } + + // 2. 下发数据 + String staffError = syncService.uploadPerson(staffPersonIds,deviceIds,FaceSyncConst.STAFF_PERSON_TYPE); + if(ToolUtil.isNotEmpty(staffError)){ + return ResponseData.error(staffError); + } + String visitorError = syncService.uploadPerson(visitorPersonIds,deviceIds,FaceSyncConst.VISITOR_PERSON_TYPE); + if(ToolUtil.isNotEmpty(visitorError)){ + return ResponseData.error(visitorError); + } + + return ResponseData.success(); + } + + // 错误信息返回 + @RequestMapping("/subsrcibe/init") + @ResponseBody + public Object upload(@RequestParam("deviceIds") List deviceIds){ + String errorMsg = syncService.initSubscription(deviceIds); + if(ToolUtil.isNotEmpty(errorMsg)){ + return ResponseData.error(errorMsg); + } + return ResponseData.success(); + } + + + @RequestMapping(value = "/LAPI/V1.0/System/Event/Notification/PersonVerification", method = RequestMethod.POST) + @ResponseBody + public void verification(@RequestBody String recordNotification){ + logger.info(recordNotification); + RecordNotification record = JSONObject.parseObject(recordNotification,RecordNotification.class); + syncService.receiveRecord(record); + //return ResponseData.success(); + } + + +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FacePersonSyncMapper.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FacePersonSyncMapper.java new file mode 100644 index 0000000..af53702 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FacePersonSyncMapper.java @@ -0,0 +1,17 @@ +package com.casic.missiles.modular.system.dao; + +import com.casic.missiles.modular.system.model.FacePersonSync; +import com.baomidou.mybatisplus.mapper.BaseMapper; + +/** + *

+ * Mapper 接口 + *

+ * + * @author zyj123 + * @since 2020-07-24 + */ +public interface FacePersonSyncMapper extends BaseMapper { + + Long getMaxSyncId(); +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FaceSubscribeMapper.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FaceSubscribeMapper.java new file mode 100644 index 0000000..0c6374a --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FaceSubscribeMapper.java @@ -0,0 +1,16 @@ +package com.casic.missiles.modular.system.dao; + +import com.casic.missiles.modular.system.model.FaceSubscribe; +import com.baomidou.mybatisplus.mapper.BaseMapper; + +/** + *

+ * Mapper 接口 + *

+ * + * @author zyj123 + * @since 2020-07-25 + */ +public interface FaceSubscribeMapper extends BaseMapper { + +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FacePersonSyncMapper.xml b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FacePersonSyncMapper.xml new file mode 100644 index 0000000..ac46ad0 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FacePersonSyncMapper.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + PERSON_ID AS personId, SYNC_ID AS syncId + + + + + diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FaceSubscribeMapper.xml b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FaceSubscribeMapper.xml new file mode 100644 index 0000000..16024e2 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FaceSubscribeMapper.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + SUBSCRIBE_ID AS subscribeId, DEVICE_CODE AS deviceCode, UPDATE_TIME AS updateTime + + + diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FacePersonSync.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FacePersonSync.java new file mode 100644 index 0000000..7cdb821 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FacePersonSync.java @@ -0,0 +1,68 @@ +package com.casic.missiles.modular.system.model; + +import java.io.Serializable; + +import com.baomidou.mybatisplus.annotations.TableId; +import com.baomidou.mybatisplus.annotations.TableField; +import com.baomidou.mybatisplus.activerecord.Model; +import com.baomidou.mybatisplus.annotations.TableName; +import java.io.Serializable; + +/** + *

+ * + *

+ * + * @author zyj123 + * @since 2020-07-24 + */ +@TableName("face_person_sync") +public class FacePersonSync extends Model { + + private static final long serialVersionUID = 1L; + + /** + * 人员id + */ + @TableId("PERSON_ID") + private Long personId; + /** + * 人员同步id + */ + @TableField("SYNC_ID") + private Long syncId; + + public FacePersonSync(Long personId, Long syncId) { + this.personId = personId; + this.syncId = syncId; + } + + public Long getPersonId() { + return personId; + } + + public void setPersonId(Long personId) { + this.personId = personId; + } + + public Long getSyncId() { + return syncId; + } + + public void setSyncId(Long syncId) { + this.syncId = syncId; + } + + @Override + protected Serializable pkVal() { + return this.personId; + } + + @Override + public String toString() { + return "FacePersonSync{" + + "personId=" + personId + + ", syncId=" + syncId + + "}"; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FaceSubscribe.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FaceSubscribe.java new file mode 100644 index 0000000..ccc7792 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FaceSubscribe.java @@ -0,0 +1,79 @@ +package com.casic.missiles.modular.system.model; + +import java.io.Serializable; + +import java.util.Date; +import com.baomidou.mybatisplus.annotations.TableId; +import com.baomidou.mybatisplus.annotations.TableField; +import com.baomidou.mybatisplus.activerecord.Model; +import com.baomidou.mybatisplus.annotations.TableName; +import java.io.Serializable; + +/** + *

+ * + *

+ * + * @author zyj123 + * @since 2020-07-25 + */ +@TableName("face_subscribe") +public class FaceSubscribe extends Model { + + private static final long serialVersionUID = 1L; + + /** + * 订阅id + */ + @TableId("SUBSCRIBE_ID") + private Long subscribeId; + /** + * 设备编号 + */ + @TableField("DEVICE_CODE") + private String deviceCode; + /** + * 更新时间 + */ + @TableField("UPDATE_TIME") + private Date updateTime; + + + public Long getSubscribeId() { + return subscribeId; + } + + public void setSubscribeId(Long subscribeId) { + this.subscribeId = subscribeId; + } + + public String getDeviceCode() { + return deviceCode; + } + + public void setDeviceCode(String deviceCode) { + this.deviceCode = deviceCode; + } + + public Date getUpdateTime() { + return updateTime; + } + + public void setUpdateTime(Date updateTime) { + this.updateTime = updateTime; + } + + @Override + protected Serializable pkVal() { + return this.subscribeId; + } + + @Override + public String toString() { + return "FaceSubscribe{" + + "subscribeId=" + subscribeId + + ", deviceCode=" + deviceCode + + ", updateTime=" + updateTime + + "}"; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/request/PersonInfo.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/request/PersonInfo.java new file mode 100644 index 0000000..80d9eff --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/request/PersonInfo.java @@ -0,0 +1,271 @@ +package com.casic.missiles.modular.system.request; + +import com.alibaba.fastjson.annotation.JSONField; +import com.baomidou.mybatisplus.annotations.TableField; +import com.google.gson.annotations.SerializedName; + +import java.util.List; + +public class PersonInfo { + + //@JSONField(name = "PersonID") + @SerializedName("PersonID") + private Long personID; + + //@JSONField(name = "LastChange") + @SerializedName("LastChange") + private Long lastChange; + + //@JSONField(name = "PersonCode") + @SerializedName("PersonCode") + private String personCode; + + //@JSONField(name = "PersonName") + @SerializedName("PersonName") + private String personName; + + //@JSONField(name = "Remarks") + @SerializedName("Remarks") + private String remarks; + + //@JSONField(name = "TimeTemplateNum") + @SerializedName("TimeTemplateNum") + private Integer timeTemplateNum; + + //@JSONField(name = "TimeTemplateList") + @SerializedName("TimeTemplateList") + private List timeTemplateList; + + //@JSONField(name = "IdentificationNum") + @SerializedName("IdentificationNum") + private Integer identificationNum; + + //@JSONField(name = "IdentificationList") + @SerializedName("IdentificationList") + private List identificationList; + + //@JSONField(name = "ImageNum") + @SerializedName("ImageNum") + private Integer imageNum; + + //@JSONField(name = "ImageList") + @SerializedName("ImageList") + private List imageList; + + public Long getPersonID() { + return personID; + } + + public void setPersonID(Long personID) { + this.personID = personID; + } + + public Long getLastChange() { + return lastChange; + } + + public void setLastChange(Long lastChange) { + this.lastChange = lastChange; + } + + public String getPersonCode() { + return personCode; + } + + public void setPersonCode(String personCode) { + this.personCode = personCode; + } + + public String getPersonName() { + return personName; + } + + public void setPersonName(String personName) { + this.personName = personName; + } + + public String getRemarks() { + return remarks; + } + + public void setRemarks(String remarks) { + this.remarks = remarks; + } + + public Integer getTimeTemplateNum() { + return timeTemplateNum; + } + + public void setTimeTemplateNum(Integer timeTemplateNum) { + this.timeTemplateNum = timeTemplateNum; + } + + public List getTimeTemplateList() { + return timeTemplateList; + } + + public void setTimeTemplateList(List timeTemplateList) { + this.timeTemplateList = timeTemplateList; + } + + public Integer getIdentificationNum() { + return identificationNum; + } + + public void setIdentificationNum(Integer identificationNum) { + this.identificationNum = identificationNum; + } + + public List getIdentificationList() { + return identificationList; + } + + public void setIdentificationList(List identificationList) { + this.identificationList = identificationList; + } + + public Integer getImageNum() { + return imageNum; + } + + public void setImageNum(Integer imageNum) { + this.imageNum = imageNum; + } + + public List getImageList() { + return imageList; + } + + public void setImageList(List imageList) { + this.imageList = imageList; + } + + public class TimeTemplate{ + @JSONField(name = "BeginTime") + private Long beginTime; + @JSONField(name = "EndTime") + private Long endTime; + @JSONField(name = "Index") + private Long index; + + public TimeTemplate(Long beginTime, Long endTime, Long index) { + this.beginTime = beginTime; + this.endTime = endTime; + this.index = index; + } + + public Long getBeginTime() { + return beginTime; + } + + public void setBeginTime(Long beginTime) { + this.beginTime = beginTime; + } + + public Long getEndTime() { + return endTime; + } + + public void setEndTime(Long endTime) { + this.endTime = endTime; + } + + public Long getIndex() { + return index; + } + + public void setIndex(Long index) { + this.index = index; + } + } + + public TimeTemplate createTimeTemplate(Long beginTime, Long endTime, Long index){ + return new TimeTemplate(beginTime, endTime, index); + } + + public class IdentificationInfo { + @JSONField(name = "Type") + private Integer type; + @JSONField(name = "Number") + private String number; + + public IdentificationInfo(Integer type, String number) { + this.type = type; + this.number = number; + } + + public Integer getType() { + return type; + } + + public void setType(Integer type) { + this.type = type; + } + + public String getNumber() { + return number; + } + + public void setNumber(String number) { + this.number = number; + } + } + + public IdentificationInfo createIdentificationInfo(Integer type, String number){ + return new IdentificationInfo(type,number); + } + + public class ImageInfo{ + @JSONField(name = "FaceID") + private Long faceID; + @JSONField(name = "Name") + private String name; + @JSONField(name = "Size") + private Long size; + @JSONField(name = "Data") + private String data; + + public ImageInfo(Long faceID, String name, Long size, String data) { + this.faceID = faceID; + this.name = name; + this.size = size; + this.data = data; + } + + public Long getFaceID() { + return faceID; + } + + public void setFaceID(Long faceID) { + this.faceID = faceID; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Long getSize() { + return size; + } + + public void setSize(Long size) { + this.size = size; + } + + public String getData() { + return data; + } + + public void setData(String data) { + this.data = data; + } + } + + public ImageInfo createImageInfo(Long faceID, String name, Long size, String data){ + return new ImageInfo(faceID, name, size, data); + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceBaseResponse.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceBaseResponse.java new file mode 100644 index 0000000..fe93b8a --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceBaseResponse.java @@ -0,0 +1,90 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; +import com.google.gson.annotations.SerializedName; + +public class FaceBaseResponse { + @JSONField(name = "ResponseURL") + @SerializedName("ResponseURL") + private String responseUrl; + + @JSONField(name = "CreatedID") + @SerializedName("CreatedID") + private int createdId; + + @JSONField(name = "ResponseCode") + @SerializedName("ResponseCode") + private int responseCode; + + @JSONField(name = "ResponseString") + @SerializedName("ResponseString") + private String responseString; + + @JSONField(name = "StatusCode") + @SerializedName("StatusCode") + private int statusCode; + + @JSONField(name = "StatusString") + @SerializedName("StatusString") + private String statusString; + + //@JSONField(name = "Data") + @SerializedName("Data") + private T data; + + public String getResponseUrl() { + return responseUrl; + } + + public void setResponseUrl(String responseUrl) { + this.responseUrl = responseUrl; + } + + public int getCreatedId() { + return createdId; + } + + public void setCreatedId(int createdId) { + this.createdId = createdId; + } + + public int getResponseCode() { + return responseCode; + } + + public void setResponseCode(int responseCode) { + this.responseCode = responseCode; + } + + public String getResponseString() { + return responseString; + } + + public void setResponseString(String responseString) { + this.responseString = responseString; + } + + public int getStatusCode() { + return statusCode; + } + + public void setStatusCode(int statusCode) { + this.statusCode = statusCode; + } + + public String getStatusString() { + return statusString; + } + + public void setStatusString(String statusString) { + this.statusString = statusString; + } + + public T getData() { + return data; + } + + public void setData(T data) { + this.data = data; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceInfo.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceInfo.java new file mode 100644 index 0000000..f128c92 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceInfo.java @@ -0,0 +1,128 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; + +import java.util.List; + +public class FaceInfo { + @JSONField(name = "ID") + private Long id; + @JSONField(name = "Timestamp") + private Long timestamp; + @JSONField(name = "CapSrc") + private Long capSrc; + @JSONField(name = "FeatureNum") + private Long featureNum; + @JSONField(name = "FeatureList") + private List featureList; + @JSONField(name = "FeatureVersion") + private String featureVersion; + @JSONField(name = "Feature") + private String feature; + @JSONField(name = "Temperature") + private Float temperature; + @JSONField(name = "MaskFlag") + private Long maskFlag; + @JSONField(name = "PanoImage") + private Object panoImage; + @JSONField(name = "FaceImage") + private Object faceImage; + @JSONField(name = "FaceArea") + private Object faceArea; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Long getTimestamp() { + return timestamp; + } + + public void setTimestamp(Long timestamp) { + this.timestamp = timestamp; + } + + public Long getCapSrc() { + return capSrc; + } + + public void setCapSrc(Long capSrc) { + this.capSrc = capSrc; + } + + public Long getFeatureNum() { + return featureNum; + } + + public void setFeatureNum(Long featureNum) { + this.featureNum = featureNum; + } + + public List getFeatureList() { + return featureList; + } + + public void setFeatureList(List featureList) { + this.featureList = featureList; + } + + public String getFeatureVersion() { + return featureVersion; + } + + public void setFeatureVersion(String featureVersion) { + this.featureVersion = featureVersion; + } + + public String getFeature() { + return feature; + } + + public void setFeature(String feature) { + this.feature = feature; + } + + public Float getTemperature() { + return temperature; + } + + public void setTemperature(Float temperature) { + this.temperature = temperature; + } + + public Long getMaskFlag() { + return maskFlag; + } + + public void setMaskFlag(Long maskFlag) { + this.maskFlag = maskFlag; + } + + public Object getPanoImage() { + return panoImage; + } + + public void setPanoImage(Object panoImage) { + this.panoImage = panoImage; + } + + public Object getFaceImage() { + return faceImage; + } + + public void setFaceImage(Object faceImage) { + this.faceImage = faceImage; + } + + public Object getFaceArea() { + return faceArea; + } + + public void setFaceArea(Object faceArea) { + this.faceArea = faceArea; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/LibMatInfo.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/LibMatInfo.java new file mode 100644 index 0000000..ce6dd33 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/LibMatInfo.java @@ -0,0 +1,69 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; + +public class LibMatInfo { + @JSONField(name = "ID") + private Long id; + @JSONField(name = "LibID") + private Long libId; + @JSONField(name = "LibType") + private Long libType; + @JSONField(name = "MatchStatus") + private Long matchStatus; + @JSONField(name = "MatchPersonID") + private Long matchPersonId; + @JSONField(name = "MatchFaceID") + private Long matchFaceId; + + // MatchPersonInfo 暂时忽略不用 + + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Long getLibId() { + return libId; + } + + public void setLibId(Long libId) { + this.libId = libId; + } + + public Long getLibType() { + return libType; + } + + public void setLibType(Long libType) { + this.libType = libType; + } + + public Long getMatchStatus() { + return matchStatus; + } + + public void setMatchStatus(Long matchStatus) { + this.matchStatus = matchStatus; + } + + public Long getMatchPersonId() { + return matchPersonId; + } + + public void setMatchPersonId(Long matchPersonId) { + this.matchPersonId = matchPersonId; + } + + public Long getMatchFaceId() { + return matchFaceId; + } + + public void setMatchFaceId(Long matchFaceId) { + this.matchFaceId = matchFaceId; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/PersonResponseData.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/PersonResponseData.java new file mode 100644 index 0000000..186faed --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/PersonResponseData.java @@ -0,0 +1,31 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; +import com.google.gson.annotations.SerializedName; + +import java.util.List; + +public class PersonResponseData { + @JSONField(name = "Num") + @SerializedName("Num") + private int num; + @JSONField(name = "PersonList") + @SerializedName("PersonList") + private List personList; + + public int getNum() { + return num; + } + + public void setNum(int num) { + this.num = num; + } + + public List getPersonList() { + return personList; + } + + public void setPersonList(List personList) { + this.personList = personList; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/PersonResponseInfo.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/PersonResponseInfo.java new file mode 100644 index 0000000..7ba3edc --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/PersonResponseInfo.java @@ -0,0 +1,67 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; +import com.google.gson.annotations.SerializedName; + +import java.util.List; + +public class PersonResponseInfo { + @JSONField(name = "PersonID") + @SerializedName("PersonID") + private Long personId; + @JSONField(name = "FaceNum") + @SerializedName("FaceNum") + private Long faceNum; + @JSONField(name = "FaceList") + @SerializedName("FaceList") + private List faceList; + + public Long getPersonId() { + return personId; + } + + public void setPersonId(Long personId) { + this.personId = personId; + } + + public Long getFaceNum() { + return faceNum; + } + + public void setFaceNum(Long faceNum) { + this.faceNum = faceNum; + } + + public List getFaceList() { + return faceList; + } + + public void setFaceList(List faceList) { + this.faceList = faceList; + } + + public class PersonResponseFace{ + @JSONField(name = "FaceID") + @SerializedName("FaceID") + private Long faceId; + @JSONField(name = "ResultCode") + @SerializedName("ResultCode") + private Long resultCode; + + public Long getFaceId() { + return faceId; + } + + public void setFaceId(Long faceId) { + this.faceId = faceId; + } + + public Long getResultCode() { + return resultCode; + } + + public void setResultCode(Long resultCode) { + this.resultCode = resultCode; + } + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/RecordNotification.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/RecordNotification.java new file mode 100644 index 0000000..ca52d29 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/RecordNotification.java @@ -0,0 +1,138 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; + +import java.util.List; + +public class RecordNotification { + @JSONField(name = "Reference") + private String reference; + @JSONField(name = "Seq") + private int seq; + @JSONField(name = "DeviceCode") + private String deviceCode; + @JSONField(name = "Timestamp") + private Long timestamp; + @JSONField(name = "NotificationType") + private int notificationType; + @JSONField(name = "FaceInfoNum") + private int faceInfoNum; + @JSONField(name = "FaceInfoList") + private List faceInfoList; + @JSONField(name = "CardInfoNum") + private int cardInfoNum; + @JSONField(name = "CardInfoList") + private List cardInfoList; + @JSONField(name = "GateInfoNum") + private int gateInfoNum; + @JSONField(name = "GateInfoList") + private List gateInfoList; + @JSONField(name = "LibMatInfoNum") + private int libMatInfoNum; + @JSONField(name = "LibMatInfoList") + private List libMatInfoList; + + public String getReference() { + return reference; + } + + public void setReference(String reference) { + this.reference = reference; + } + + public int getSeq() { + return seq; + } + + public void setSeq(int seq) { + this.seq = seq; + } + + public String getDeviceCode() { + return deviceCode; + } + + public void setDeviceCode(String deviceCode) { + this.deviceCode = deviceCode; + } + + public Long getTimestamp() { + return timestamp; + } + + public void setTimestamp(Long timestamp) { + this.timestamp = timestamp; + } + + public int getNotificationType() { + return notificationType; + } + + public void setNotificationType(int notificationType) { + this.notificationType = notificationType; + } + + public int getFaceInfoNum() { + return faceInfoNum; + } + + public void setFaceInfoNum(int faceInfoNum) { + this.faceInfoNum = faceInfoNum; + } + + public List getFaceInfoList() { + return faceInfoList; + } + + public void setFaceInfoList(List faceInfoList) { + this.faceInfoList = faceInfoList; + } + + public int getCardInfoNum() { + return cardInfoNum; + } + + public void setCardInfoNum(int cardInfoNum) { + this.cardInfoNum = cardInfoNum; + } + + public List getCardInfoList() { + return cardInfoList; + } + + public void setCardInfoList(List cardInfoList) { + this.cardInfoList = cardInfoList; + } + + public int getGateInfoNum() { + return gateInfoNum; + } + + public void setGateInfoNum(int gateInfoNum) { + this.gateInfoNum = gateInfoNum; + } + + public List getGateInfoList() { + return gateInfoList; + } + + public void setGateInfoList(List gateInfoList) { + this.gateInfoList = gateInfoList; + } + + public int getLibMatInfoNum() { + return libMatInfoNum; + } + + public void setLibMatInfoNum(int libMatInfoNum) { + this.libMatInfoNum = libMatInfoNum; + } + + public List getLibMatInfoList() { + return libMatInfoList; + } + + public void setLibMatInfoList(List libMatInfoList) { + this.libMatInfoList = libMatInfoList; + } +} diff --git a/casic-face-sync/pom.xml b/casic-face-sync/pom.xml new file mode 100644 index 0000000..24dc884 --- /dev/null +++ b/casic-face-sync/pom.xml @@ -0,0 +1,74 @@ + + + 4.0.0 + + com.casic + casic-iris-parent + 1.0.0-SNAPSHOT + ../pom.xml + + + + casic-face-sync + ${pro.version} + jar + casic-face-sync + + + + + + com.casic + casic-core + ${core.version} + + + + com.casic + casic-admin-support + ${admin.version} + + + com.casic + casic-iris-support + ${pro.version} + + + + org.apache.httpcomponents + httpclient + 4.5.3 + + + + org.apache.httpcomponents + httpcore + 4.4.8 + + + + org.apache.httpcomponents + httpmime + 4.5.3 + + + + com.google.code.gson + gson + + + + + + + + src/main/java + + **/*.xml + + + + + \ No newline at end of file diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/constant/FaceSyncConst.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/constant/FaceSyncConst.java new file mode 100644 index 0000000..352d47d --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/constant/FaceSyncConst.java @@ -0,0 +1,29 @@ +package com.casic.missiles.modular.system.constant; + +public class FaceSyncConst { + + /** + * 单次最大批量上传人员数 + */ + public static final int UPLOAD_MAX_PERSON = 6; + + /** + * 上传人员库 + */ + public static final String UPLOAD_STAFF_LIB = "3"; + public static final String UPLOAD_VISITOR_LIB = "4"; + + public static final String UPLOAD_URL_PREFIX = "/LAPI/V1.0/PeopleLibraries/"; + + public static final String UPLOAD_URL_SUFFIX = "/People"; + + public static final int UPLOAD_PERSONCODE_MAXLENGTH = 15; + + public static final int UPLOAD_REMARK_MAXLENGTH = 63; + + public static final String SUBSCRIBE_URL = "/LAPI/V1.0/System/Event/Subscription/"; + + public static final String STAFF_PERSON_TYPE = "1"; + + public static final String VISITOR_PERSON_TYPE = "0"; +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/controller/FaceSyncController.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/controller/FaceSyncController.java new file mode 100644 index 0000000..1b35431 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/controller/FaceSyncController.java @@ -0,0 +1,117 @@ +package com.casic.missiles.modular.system.controller; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson.serializer.SerializerFeature; +import com.casic.missiles.core.base.response.ResponseData; +import com.casic.missiles.core.common.service.ICommonPermissionService; +import com.casic.missiles.core.common.service.ICommonPersonService; +import com.casic.missiles.core.datascope.DataScope; +import com.casic.missiles.core.util.ToolUtil; +import com.casic.missiles.modular.system.request.PersonInfo; +import com.casic.missiles.modular.system.response.RecordNotification; +import com.casic.missiles.modular.system.service.IFaceSyncService; +import com.casic.missiles.modular.system.service.IIrisPersonSupportService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.*; +import com.casic.missiles.modular.system.constant.FaceSyncConst; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + + + +@Controller +public class FaceSyncController { + private final static Logger logger = LoggerFactory.getLogger(FaceSyncController.class); + + @Autowired + private IFaceSyncService syncService; + @Autowired + private ICommonPersonService commonPersonService; + @Autowired + private IIrisPersonSupportService personSupportService; + @Autowired + private ICommonPermissionService permissionService; + + @RequestMapping("/face/upload") + @ResponseBody + public Object upload(@RequestParam("personIds") List personIds, + @RequestParam("deviceIds") List deviceIds, + @RequestParam("personType")String personType ){ + // 检查数量 +// if(personIds.size()>FaceSyncConst.UPLOAD_MAX_PERSON){ +// return ResponseData.error(String.format("每次最多上传%s个人",FaceSyncConst.UPLOAD_MAX_PERSON)); +// } + // 检查照片格式及大小 + String photoCheck = syncService.checkPersonPhoto(personIds); + if(ToolUtil.isNotEmpty(photoCheck)){ + return ResponseData.error(photoCheck); + } + else{ + // 上传数据 + String error = syncService.uploadPerson(personIds,deviceIds,personType); + if(ToolUtil.isNotEmpty(error)){ + return ResponseData.error(error); + } + } + return ResponseData.success(); + } + + @RequestMapping("/face/uploadAll") + @ResponseBody + public Object uploadAll(@RequestParam("deviceIds") List deviceIds){ + DataScope dataScope = permissionService.getCurrUserDataScope(); + + List staffPersonIds = personSupportService.listIdsByType(dataScope,FaceSyncConst.STAFF_PERSON_TYPE); + List visitorPersonIds = personSupportService.listIdsByType(dataScope,FaceSyncConst.VISITOR_PERSON_TYPE); + // 1.检查照片,分别检查员工、访客 + String staffPhotoCheck = syncService.checkPersonPhoto(staffPersonIds); + if(ToolUtil.isNotEmpty(staffPhotoCheck)){ + return ResponseData.error(staffPhotoCheck); + } + String visitorPhotoCheck = syncService.checkPersonPhoto(visitorPersonIds); + if(ToolUtil.isNotEmpty(visitorPhotoCheck)){ + return ResponseData.error(visitorPhotoCheck); + } + + // 2. 下发数据 + String staffError = syncService.uploadPerson(staffPersonIds,deviceIds,FaceSyncConst.STAFF_PERSON_TYPE); + if(ToolUtil.isNotEmpty(staffError)){ + return ResponseData.error(staffError); + } + String visitorError = syncService.uploadPerson(visitorPersonIds,deviceIds,FaceSyncConst.VISITOR_PERSON_TYPE); + if(ToolUtil.isNotEmpty(visitorError)){ + return ResponseData.error(visitorError); + } + + return ResponseData.success(); + } + + // 错误信息返回 + @RequestMapping("/subsrcibe/init") + @ResponseBody + public Object upload(@RequestParam("deviceIds") List deviceIds){ + String errorMsg = syncService.initSubscription(deviceIds); + if(ToolUtil.isNotEmpty(errorMsg)){ + return ResponseData.error(errorMsg); + } + return ResponseData.success(); + } + + + @RequestMapping(value = "/LAPI/V1.0/System/Event/Notification/PersonVerification", method = RequestMethod.POST) + @ResponseBody + public void verification(@RequestBody String recordNotification){ + logger.info(recordNotification); + RecordNotification record = JSONObject.parseObject(recordNotification,RecordNotification.class); + syncService.receiveRecord(record); + //return ResponseData.success(); + } + + +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FacePersonSyncMapper.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FacePersonSyncMapper.java new file mode 100644 index 0000000..af53702 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FacePersonSyncMapper.java @@ -0,0 +1,17 @@ +package com.casic.missiles.modular.system.dao; + +import com.casic.missiles.modular.system.model.FacePersonSync; +import com.baomidou.mybatisplus.mapper.BaseMapper; + +/** + *

+ * Mapper 接口 + *

+ * + * @author zyj123 + * @since 2020-07-24 + */ +public interface FacePersonSyncMapper extends BaseMapper { + + Long getMaxSyncId(); +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FaceSubscribeMapper.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FaceSubscribeMapper.java new file mode 100644 index 0000000..0c6374a --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FaceSubscribeMapper.java @@ -0,0 +1,16 @@ +package com.casic.missiles.modular.system.dao; + +import com.casic.missiles.modular.system.model.FaceSubscribe; +import com.baomidou.mybatisplus.mapper.BaseMapper; + +/** + *

+ * Mapper 接口 + *

+ * + * @author zyj123 + * @since 2020-07-25 + */ +public interface FaceSubscribeMapper extends BaseMapper { + +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FacePersonSyncMapper.xml b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FacePersonSyncMapper.xml new file mode 100644 index 0000000..ac46ad0 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FacePersonSyncMapper.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + PERSON_ID AS personId, SYNC_ID AS syncId + + + + + diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FaceSubscribeMapper.xml b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FaceSubscribeMapper.xml new file mode 100644 index 0000000..16024e2 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FaceSubscribeMapper.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + SUBSCRIBE_ID AS subscribeId, DEVICE_CODE AS deviceCode, UPDATE_TIME AS updateTime + + + diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FacePersonSync.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FacePersonSync.java new file mode 100644 index 0000000..7cdb821 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FacePersonSync.java @@ -0,0 +1,68 @@ +package com.casic.missiles.modular.system.model; + +import java.io.Serializable; + +import com.baomidou.mybatisplus.annotations.TableId; +import com.baomidou.mybatisplus.annotations.TableField; +import com.baomidou.mybatisplus.activerecord.Model; +import com.baomidou.mybatisplus.annotations.TableName; +import java.io.Serializable; + +/** + *

+ * + *

+ * + * @author zyj123 + * @since 2020-07-24 + */ +@TableName("face_person_sync") +public class FacePersonSync extends Model { + + private static final long serialVersionUID = 1L; + + /** + * 人员id + */ + @TableId("PERSON_ID") + private Long personId; + /** + * 人员同步id + */ + @TableField("SYNC_ID") + private Long syncId; + + public FacePersonSync(Long personId, Long syncId) { + this.personId = personId; + this.syncId = syncId; + } + + public Long getPersonId() { + return personId; + } + + public void setPersonId(Long personId) { + this.personId = personId; + } + + public Long getSyncId() { + return syncId; + } + + public void setSyncId(Long syncId) { + this.syncId = syncId; + } + + @Override + protected Serializable pkVal() { + return this.personId; + } + + @Override + public String toString() { + return "FacePersonSync{" + + "personId=" + personId + + ", syncId=" + syncId + + "}"; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FaceSubscribe.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FaceSubscribe.java new file mode 100644 index 0000000..ccc7792 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FaceSubscribe.java @@ -0,0 +1,79 @@ +package com.casic.missiles.modular.system.model; + +import java.io.Serializable; + +import java.util.Date; +import com.baomidou.mybatisplus.annotations.TableId; +import com.baomidou.mybatisplus.annotations.TableField; +import com.baomidou.mybatisplus.activerecord.Model; +import com.baomidou.mybatisplus.annotations.TableName; +import java.io.Serializable; + +/** + *

+ * + *

+ * + * @author zyj123 + * @since 2020-07-25 + */ +@TableName("face_subscribe") +public class FaceSubscribe extends Model { + + private static final long serialVersionUID = 1L; + + /** + * 订阅id + */ + @TableId("SUBSCRIBE_ID") + private Long subscribeId; + /** + * 设备编号 + */ + @TableField("DEVICE_CODE") + private String deviceCode; + /** + * 更新时间 + */ + @TableField("UPDATE_TIME") + private Date updateTime; + + + public Long getSubscribeId() { + return subscribeId; + } + + public void setSubscribeId(Long subscribeId) { + this.subscribeId = subscribeId; + } + + public String getDeviceCode() { + return deviceCode; + } + + public void setDeviceCode(String deviceCode) { + this.deviceCode = deviceCode; + } + + public Date getUpdateTime() { + return updateTime; + } + + public void setUpdateTime(Date updateTime) { + this.updateTime = updateTime; + } + + @Override + protected Serializable pkVal() { + return this.subscribeId; + } + + @Override + public String toString() { + return "FaceSubscribe{" + + "subscribeId=" + subscribeId + + ", deviceCode=" + deviceCode + + ", updateTime=" + updateTime + + "}"; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/request/PersonInfo.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/request/PersonInfo.java new file mode 100644 index 0000000..80d9eff --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/request/PersonInfo.java @@ -0,0 +1,271 @@ +package com.casic.missiles.modular.system.request; + +import com.alibaba.fastjson.annotation.JSONField; +import com.baomidou.mybatisplus.annotations.TableField; +import com.google.gson.annotations.SerializedName; + +import java.util.List; + +public class PersonInfo { + + //@JSONField(name = "PersonID") + @SerializedName("PersonID") + private Long personID; + + //@JSONField(name = "LastChange") + @SerializedName("LastChange") + private Long lastChange; + + //@JSONField(name = "PersonCode") + @SerializedName("PersonCode") + private String personCode; + + //@JSONField(name = "PersonName") + @SerializedName("PersonName") + private String personName; + + //@JSONField(name = "Remarks") + @SerializedName("Remarks") + private String remarks; + + //@JSONField(name = "TimeTemplateNum") + @SerializedName("TimeTemplateNum") + private Integer timeTemplateNum; + + //@JSONField(name = "TimeTemplateList") + @SerializedName("TimeTemplateList") + private List timeTemplateList; + + //@JSONField(name = "IdentificationNum") + @SerializedName("IdentificationNum") + private Integer identificationNum; + + //@JSONField(name = "IdentificationList") + @SerializedName("IdentificationList") + private List identificationList; + + //@JSONField(name = "ImageNum") + @SerializedName("ImageNum") + private Integer imageNum; + + //@JSONField(name = "ImageList") + @SerializedName("ImageList") + private List imageList; + + public Long getPersonID() { + return personID; + } + + public void setPersonID(Long personID) { + this.personID = personID; + } + + public Long getLastChange() { + return lastChange; + } + + public void setLastChange(Long lastChange) { + this.lastChange = lastChange; + } + + public String getPersonCode() { + return personCode; + } + + public void setPersonCode(String personCode) { + this.personCode = personCode; + } + + public String getPersonName() { + return personName; + } + + public void setPersonName(String personName) { + this.personName = personName; + } + + public String getRemarks() { + return remarks; + } + + public void setRemarks(String remarks) { + this.remarks = remarks; + } + + public Integer getTimeTemplateNum() { + return timeTemplateNum; + } + + public void setTimeTemplateNum(Integer timeTemplateNum) { + this.timeTemplateNum = timeTemplateNum; + } + + public List getTimeTemplateList() { + return timeTemplateList; + } + + public void setTimeTemplateList(List timeTemplateList) { + this.timeTemplateList = timeTemplateList; + } + + public Integer getIdentificationNum() { + return identificationNum; + } + + public void setIdentificationNum(Integer identificationNum) { + this.identificationNum = identificationNum; + } + + public List getIdentificationList() { + return identificationList; + } + + public void setIdentificationList(List identificationList) { + this.identificationList = identificationList; + } + + public Integer getImageNum() { + return imageNum; + } + + public void setImageNum(Integer imageNum) { + this.imageNum = imageNum; + } + + public List getImageList() { + return imageList; + } + + public void setImageList(List imageList) { + this.imageList = imageList; + } + + public class TimeTemplate{ + @JSONField(name = "BeginTime") + private Long beginTime; + @JSONField(name = "EndTime") + private Long endTime; + @JSONField(name = "Index") + private Long index; + + public TimeTemplate(Long beginTime, Long endTime, Long index) { + this.beginTime = beginTime; + this.endTime = endTime; + this.index = index; + } + + public Long getBeginTime() { + return beginTime; + } + + public void setBeginTime(Long beginTime) { + this.beginTime = beginTime; + } + + public Long getEndTime() { + return endTime; + } + + public void setEndTime(Long endTime) { + this.endTime = endTime; + } + + public Long getIndex() { + return index; + } + + public void setIndex(Long index) { + this.index = index; + } + } + + public TimeTemplate createTimeTemplate(Long beginTime, Long endTime, Long index){ + return new TimeTemplate(beginTime, endTime, index); + } + + public class IdentificationInfo { + @JSONField(name = "Type") + private Integer type; + @JSONField(name = "Number") + private String number; + + public IdentificationInfo(Integer type, String number) { + this.type = type; + this.number = number; + } + + public Integer getType() { + return type; + } + + public void setType(Integer type) { + this.type = type; + } + + public String getNumber() { + return number; + } + + public void setNumber(String number) { + this.number = number; + } + } + + public IdentificationInfo createIdentificationInfo(Integer type, String number){ + return new IdentificationInfo(type,number); + } + + public class ImageInfo{ + @JSONField(name = "FaceID") + private Long faceID; + @JSONField(name = "Name") + private String name; + @JSONField(name = "Size") + private Long size; + @JSONField(name = "Data") + private String data; + + public ImageInfo(Long faceID, String name, Long size, String data) { + this.faceID = faceID; + this.name = name; + this.size = size; + this.data = data; + } + + public Long getFaceID() { + return faceID; + } + + public void setFaceID(Long faceID) { + this.faceID = faceID; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Long getSize() { + return size; + } + + public void setSize(Long size) { + this.size = size; + } + + public String getData() { + return data; + } + + public void setData(String data) { + this.data = data; + } + } + + public ImageInfo createImageInfo(Long faceID, String name, Long size, String data){ + return new ImageInfo(faceID, name, size, data); + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceBaseResponse.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceBaseResponse.java new file mode 100644 index 0000000..fe93b8a --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceBaseResponse.java @@ -0,0 +1,90 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; +import com.google.gson.annotations.SerializedName; + +public class FaceBaseResponse { + @JSONField(name = "ResponseURL") + @SerializedName("ResponseURL") + private String responseUrl; + + @JSONField(name = "CreatedID") + @SerializedName("CreatedID") + private int createdId; + + @JSONField(name = "ResponseCode") + @SerializedName("ResponseCode") + private int responseCode; + + @JSONField(name = "ResponseString") + @SerializedName("ResponseString") + private String responseString; + + @JSONField(name = "StatusCode") + @SerializedName("StatusCode") + private int statusCode; + + @JSONField(name = "StatusString") + @SerializedName("StatusString") + private String statusString; + + //@JSONField(name = "Data") + @SerializedName("Data") + private T data; + + public String getResponseUrl() { + return responseUrl; + } + + public void setResponseUrl(String responseUrl) { + this.responseUrl = responseUrl; + } + + public int getCreatedId() { + return createdId; + } + + public void setCreatedId(int createdId) { + this.createdId = createdId; + } + + public int getResponseCode() { + return responseCode; + } + + public void setResponseCode(int responseCode) { + this.responseCode = responseCode; + } + + public String getResponseString() { + return responseString; + } + + public void setResponseString(String responseString) { + this.responseString = responseString; + } + + public int getStatusCode() { + return statusCode; + } + + public void setStatusCode(int statusCode) { + this.statusCode = statusCode; + } + + public String getStatusString() { + return statusString; + } + + public void setStatusString(String statusString) { + this.statusString = statusString; + } + + public T getData() { + return data; + } + + public void setData(T data) { + this.data = data; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceInfo.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceInfo.java new file mode 100644 index 0000000..f128c92 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceInfo.java @@ -0,0 +1,128 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; + +import java.util.List; + +public class FaceInfo { + @JSONField(name = "ID") + private Long id; + @JSONField(name = "Timestamp") + private Long timestamp; + @JSONField(name = "CapSrc") + private Long capSrc; + @JSONField(name = "FeatureNum") + private Long featureNum; + @JSONField(name = "FeatureList") + private List featureList; + @JSONField(name = "FeatureVersion") + private String featureVersion; + @JSONField(name = "Feature") + private String feature; + @JSONField(name = "Temperature") + private Float temperature; + @JSONField(name = "MaskFlag") + private Long maskFlag; + @JSONField(name = "PanoImage") + private Object panoImage; + @JSONField(name = "FaceImage") + private Object faceImage; + @JSONField(name = "FaceArea") + private Object faceArea; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Long getTimestamp() { + return timestamp; + } + + public void setTimestamp(Long timestamp) { + this.timestamp = timestamp; + } + + public Long getCapSrc() { + return capSrc; + } + + public void setCapSrc(Long capSrc) { + this.capSrc = capSrc; + } + + public Long getFeatureNum() { + return featureNum; + } + + public void setFeatureNum(Long featureNum) { + this.featureNum = featureNum; + } + + public List getFeatureList() { + return featureList; + } + + public void setFeatureList(List featureList) { + this.featureList = featureList; + } + + public String getFeatureVersion() { + return featureVersion; + } + + public void setFeatureVersion(String featureVersion) { + this.featureVersion = featureVersion; + } + + public String getFeature() { + return feature; + } + + public void setFeature(String feature) { + this.feature = feature; + } + + public Float getTemperature() { + return temperature; + } + + public void setTemperature(Float temperature) { + this.temperature = temperature; + } + + public Long getMaskFlag() { + return maskFlag; + } + + public void setMaskFlag(Long maskFlag) { + this.maskFlag = maskFlag; + } + + public Object getPanoImage() { + return panoImage; + } + + public void setPanoImage(Object panoImage) { + this.panoImage = panoImage; + } + + public Object getFaceImage() { + return faceImage; + } + + public void setFaceImage(Object faceImage) { + this.faceImage = faceImage; + } + + public Object getFaceArea() { + return faceArea; + } + + public void setFaceArea(Object faceArea) { + this.faceArea = faceArea; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/LibMatInfo.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/LibMatInfo.java new file mode 100644 index 0000000..ce6dd33 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/LibMatInfo.java @@ -0,0 +1,69 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; + +public class LibMatInfo { + @JSONField(name = "ID") + private Long id; + @JSONField(name = "LibID") + private Long libId; + @JSONField(name = "LibType") + private Long libType; + @JSONField(name = "MatchStatus") + private Long matchStatus; + @JSONField(name = "MatchPersonID") + private Long matchPersonId; + @JSONField(name = "MatchFaceID") + private Long matchFaceId; + + // MatchPersonInfo 暂时忽略不用 + + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Long getLibId() { + return libId; + } + + public void setLibId(Long libId) { + this.libId = libId; + } + + public Long getLibType() { + return libType; + } + + public void setLibType(Long libType) { + this.libType = libType; + } + + public Long getMatchStatus() { + return matchStatus; + } + + public void setMatchStatus(Long matchStatus) { + this.matchStatus = matchStatus; + } + + public Long getMatchPersonId() { + return matchPersonId; + } + + public void setMatchPersonId(Long matchPersonId) { + this.matchPersonId = matchPersonId; + } + + public Long getMatchFaceId() { + return matchFaceId; + } + + public void setMatchFaceId(Long matchFaceId) { + this.matchFaceId = matchFaceId; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/PersonResponseData.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/PersonResponseData.java new file mode 100644 index 0000000..186faed --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/PersonResponseData.java @@ -0,0 +1,31 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; +import com.google.gson.annotations.SerializedName; + +import java.util.List; + +public class PersonResponseData { + @JSONField(name = "Num") + @SerializedName("Num") + private int num; + @JSONField(name = "PersonList") + @SerializedName("PersonList") + private List personList; + + public int getNum() { + return num; + } + + public void setNum(int num) { + this.num = num; + } + + public List getPersonList() { + return personList; + } + + public void setPersonList(List personList) { + this.personList = personList; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/PersonResponseInfo.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/PersonResponseInfo.java new file mode 100644 index 0000000..7ba3edc --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/PersonResponseInfo.java @@ -0,0 +1,67 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; +import com.google.gson.annotations.SerializedName; + +import java.util.List; + +public class PersonResponseInfo { + @JSONField(name = "PersonID") + @SerializedName("PersonID") + private Long personId; + @JSONField(name = "FaceNum") + @SerializedName("FaceNum") + private Long faceNum; + @JSONField(name = "FaceList") + @SerializedName("FaceList") + private List faceList; + + public Long getPersonId() { + return personId; + } + + public void setPersonId(Long personId) { + this.personId = personId; + } + + public Long getFaceNum() { + return faceNum; + } + + public void setFaceNum(Long faceNum) { + this.faceNum = faceNum; + } + + public List getFaceList() { + return faceList; + } + + public void setFaceList(List faceList) { + this.faceList = faceList; + } + + public class PersonResponseFace{ + @JSONField(name = "FaceID") + @SerializedName("FaceID") + private Long faceId; + @JSONField(name = "ResultCode") + @SerializedName("ResultCode") + private Long resultCode; + + public Long getFaceId() { + return faceId; + } + + public void setFaceId(Long faceId) { + this.faceId = faceId; + } + + public Long getResultCode() { + return resultCode; + } + + public void setResultCode(Long resultCode) { + this.resultCode = resultCode; + } + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/RecordNotification.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/RecordNotification.java new file mode 100644 index 0000000..ca52d29 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/RecordNotification.java @@ -0,0 +1,138 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; + +import java.util.List; + +public class RecordNotification { + @JSONField(name = "Reference") + private String reference; + @JSONField(name = "Seq") + private int seq; + @JSONField(name = "DeviceCode") + private String deviceCode; + @JSONField(name = "Timestamp") + private Long timestamp; + @JSONField(name = "NotificationType") + private int notificationType; + @JSONField(name = "FaceInfoNum") + private int faceInfoNum; + @JSONField(name = "FaceInfoList") + private List faceInfoList; + @JSONField(name = "CardInfoNum") + private int cardInfoNum; + @JSONField(name = "CardInfoList") + private List cardInfoList; + @JSONField(name = "GateInfoNum") + private int gateInfoNum; + @JSONField(name = "GateInfoList") + private List gateInfoList; + @JSONField(name = "LibMatInfoNum") + private int libMatInfoNum; + @JSONField(name = "LibMatInfoList") + private List libMatInfoList; + + public String getReference() { + return reference; + } + + public void setReference(String reference) { + this.reference = reference; + } + + public int getSeq() { + return seq; + } + + public void setSeq(int seq) { + this.seq = seq; + } + + public String getDeviceCode() { + return deviceCode; + } + + public void setDeviceCode(String deviceCode) { + this.deviceCode = deviceCode; + } + + public Long getTimestamp() { + return timestamp; + } + + public void setTimestamp(Long timestamp) { + this.timestamp = timestamp; + } + + public int getNotificationType() { + return notificationType; + } + + public void setNotificationType(int notificationType) { + this.notificationType = notificationType; + } + + public int getFaceInfoNum() { + return faceInfoNum; + } + + public void setFaceInfoNum(int faceInfoNum) { + this.faceInfoNum = faceInfoNum; + } + + public List getFaceInfoList() { + return faceInfoList; + } + + public void setFaceInfoList(List faceInfoList) { + this.faceInfoList = faceInfoList; + } + + public int getCardInfoNum() { + return cardInfoNum; + } + + public void setCardInfoNum(int cardInfoNum) { + this.cardInfoNum = cardInfoNum; + } + + public List getCardInfoList() { + return cardInfoList; + } + + public void setCardInfoList(List cardInfoList) { + this.cardInfoList = cardInfoList; + } + + public int getGateInfoNum() { + return gateInfoNum; + } + + public void setGateInfoNum(int gateInfoNum) { + this.gateInfoNum = gateInfoNum; + } + + public List getGateInfoList() { + return gateInfoList; + } + + public void setGateInfoList(List gateInfoList) { + this.gateInfoList = gateInfoList; + } + + public int getLibMatInfoNum() { + return libMatInfoNum; + } + + public void setLibMatInfoNum(int libMatInfoNum) { + this.libMatInfoNum = libMatInfoNum; + } + + public List getLibMatInfoList() { + return libMatInfoList; + } + + public void setLibMatInfoList(List libMatInfoList) { + this.libMatInfoList = libMatInfoList; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/runner/InitSubscribeRunner.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/runner/InitSubscribeRunner.java new file mode 100644 index 0000000..c7d0565 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/runner/InitSubscribeRunner.java @@ -0,0 +1,43 @@ +package com.casic.missiles.modular.system.runner; + +import com.casic.missiles.modular.system.model.Device; +import com.casic.missiles.modular.system.service.IDeviceSupportService; +import com.casic.missiles.modular.system.service.IFaceSyncService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.ApplicationArguments; +import org.springframework.boot.ApplicationRunner; +import org.springframework.stereotype.Component; + +import java.util.ArrayList; +import java.util.List; + +@Component +public class InitSubscribeRunner implements ApplicationRunner { + private static Logger logger = LoggerFactory.getLogger(InitSubscribeRunner.class); + + @Value("${iris.face.initSubscribe}") + private String initSubscribe; + @Autowired + private IDeviceSupportService deviceSupportService; + @Autowired + private IFaceSyncService faceSyncService; + + /** + * 启动项目时,根据需要初始化设备订阅信息 + * @param applicationArguments + * @throws Exception + */ + @Override + public void run(ApplicationArguments applicationArguments) throws Exception { + logger.info("==================initSubscribe: "); + if(Boolean.valueOf(initSubscribe)){ + List deviceList = deviceSupportService.selectDeviceByType("5"); + List deviceIds = new ArrayList<>(); + deviceList.forEach(device -> deviceIds.add(Long.valueOf(device.getId()))); + faceSyncService.initSubscription(deviceIds); + } + } +} diff --git a/casic-face-sync/pom.xml b/casic-face-sync/pom.xml new file mode 100644 index 0000000..24dc884 --- /dev/null +++ b/casic-face-sync/pom.xml @@ -0,0 +1,74 @@ + + + 4.0.0 + + com.casic + casic-iris-parent + 1.0.0-SNAPSHOT + ../pom.xml + + + + casic-face-sync + ${pro.version} + jar + casic-face-sync + + + + + + com.casic + casic-core + ${core.version} + + + + com.casic + casic-admin-support + ${admin.version} + + + com.casic + casic-iris-support + ${pro.version} + + + + org.apache.httpcomponents + httpclient + 4.5.3 + + + + org.apache.httpcomponents + httpcore + 4.4.8 + + + + org.apache.httpcomponents + httpmime + 4.5.3 + + + + com.google.code.gson + gson + + + + + + + + src/main/java + + **/*.xml + + + + + \ No newline at end of file diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/constant/FaceSyncConst.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/constant/FaceSyncConst.java new file mode 100644 index 0000000..352d47d --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/constant/FaceSyncConst.java @@ -0,0 +1,29 @@ +package com.casic.missiles.modular.system.constant; + +public class FaceSyncConst { + + /** + * 单次最大批量上传人员数 + */ + public static final int UPLOAD_MAX_PERSON = 6; + + /** + * 上传人员库 + */ + public static final String UPLOAD_STAFF_LIB = "3"; + public static final String UPLOAD_VISITOR_LIB = "4"; + + public static final String UPLOAD_URL_PREFIX = "/LAPI/V1.0/PeopleLibraries/"; + + public static final String UPLOAD_URL_SUFFIX = "/People"; + + public static final int UPLOAD_PERSONCODE_MAXLENGTH = 15; + + public static final int UPLOAD_REMARK_MAXLENGTH = 63; + + public static final String SUBSCRIBE_URL = "/LAPI/V1.0/System/Event/Subscription/"; + + public static final String STAFF_PERSON_TYPE = "1"; + + public static final String VISITOR_PERSON_TYPE = "0"; +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/controller/FaceSyncController.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/controller/FaceSyncController.java new file mode 100644 index 0000000..1b35431 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/controller/FaceSyncController.java @@ -0,0 +1,117 @@ +package com.casic.missiles.modular.system.controller; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson.serializer.SerializerFeature; +import com.casic.missiles.core.base.response.ResponseData; +import com.casic.missiles.core.common.service.ICommonPermissionService; +import com.casic.missiles.core.common.service.ICommonPersonService; +import com.casic.missiles.core.datascope.DataScope; +import com.casic.missiles.core.util.ToolUtil; +import com.casic.missiles.modular.system.request.PersonInfo; +import com.casic.missiles.modular.system.response.RecordNotification; +import com.casic.missiles.modular.system.service.IFaceSyncService; +import com.casic.missiles.modular.system.service.IIrisPersonSupportService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.*; +import com.casic.missiles.modular.system.constant.FaceSyncConst; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + + + +@Controller +public class FaceSyncController { + private final static Logger logger = LoggerFactory.getLogger(FaceSyncController.class); + + @Autowired + private IFaceSyncService syncService; + @Autowired + private ICommonPersonService commonPersonService; + @Autowired + private IIrisPersonSupportService personSupportService; + @Autowired + private ICommonPermissionService permissionService; + + @RequestMapping("/face/upload") + @ResponseBody + public Object upload(@RequestParam("personIds") List personIds, + @RequestParam("deviceIds") List deviceIds, + @RequestParam("personType")String personType ){ + // 检查数量 +// if(personIds.size()>FaceSyncConst.UPLOAD_MAX_PERSON){ +// return ResponseData.error(String.format("每次最多上传%s个人",FaceSyncConst.UPLOAD_MAX_PERSON)); +// } + // 检查照片格式及大小 + String photoCheck = syncService.checkPersonPhoto(personIds); + if(ToolUtil.isNotEmpty(photoCheck)){ + return ResponseData.error(photoCheck); + } + else{ + // 上传数据 + String error = syncService.uploadPerson(personIds,deviceIds,personType); + if(ToolUtil.isNotEmpty(error)){ + return ResponseData.error(error); + } + } + return ResponseData.success(); + } + + @RequestMapping("/face/uploadAll") + @ResponseBody + public Object uploadAll(@RequestParam("deviceIds") List deviceIds){ + DataScope dataScope = permissionService.getCurrUserDataScope(); + + List staffPersonIds = personSupportService.listIdsByType(dataScope,FaceSyncConst.STAFF_PERSON_TYPE); + List visitorPersonIds = personSupportService.listIdsByType(dataScope,FaceSyncConst.VISITOR_PERSON_TYPE); + // 1.检查照片,分别检查员工、访客 + String staffPhotoCheck = syncService.checkPersonPhoto(staffPersonIds); + if(ToolUtil.isNotEmpty(staffPhotoCheck)){ + return ResponseData.error(staffPhotoCheck); + } + String visitorPhotoCheck = syncService.checkPersonPhoto(visitorPersonIds); + if(ToolUtil.isNotEmpty(visitorPhotoCheck)){ + return ResponseData.error(visitorPhotoCheck); + } + + // 2. 下发数据 + String staffError = syncService.uploadPerson(staffPersonIds,deviceIds,FaceSyncConst.STAFF_PERSON_TYPE); + if(ToolUtil.isNotEmpty(staffError)){ + return ResponseData.error(staffError); + } + String visitorError = syncService.uploadPerson(visitorPersonIds,deviceIds,FaceSyncConst.VISITOR_PERSON_TYPE); + if(ToolUtil.isNotEmpty(visitorError)){ + return ResponseData.error(visitorError); + } + + return ResponseData.success(); + } + + // 错误信息返回 + @RequestMapping("/subsrcibe/init") + @ResponseBody + public Object upload(@RequestParam("deviceIds") List deviceIds){ + String errorMsg = syncService.initSubscription(deviceIds); + if(ToolUtil.isNotEmpty(errorMsg)){ + return ResponseData.error(errorMsg); + } + return ResponseData.success(); + } + + + @RequestMapping(value = "/LAPI/V1.0/System/Event/Notification/PersonVerification", method = RequestMethod.POST) + @ResponseBody + public void verification(@RequestBody String recordNotification){ + logger.info(recordNotification); + RecordNotification record = JSONObject.parseObject(recordNotification,RecordNotification.class); + syncService.receiveRecord(record); + //return ResponseData.success(); + } + + +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FacePersonSyncMapper.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FacePersonSyncMapper.java new file mode 100644 index 0000000..af53702 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FacePersonSyncMapper.java @@ -0,0 +1,17 @@ +package com.casic.missiles.modular.system.dao; + +import com.casic.missiles.modular.system.model.FacePersonSync; +import com.baomidou.mybatisplus.mapper.BaseMapper; + +/** + *

+ * Mapper 接口 + *

+ * + * @author zyj123 + * @since 2020-07-24 + */ +public interface FacePersonSyncMapper extends BaseMapper { + + Long getMaxSyncId(); +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FaceSubscribeMapper.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FaceSubscribeMapper.java new file mode 100644 index 0000000..0c6374a --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FaceSubscribeMapper.java @@ -0,0 +1,16 @@ +package com.casic.missiles.modular.system.dao; + +import com.casic.missiles.modular.system.model.FaceSubscribe; +import com.baomidou.mybatisplus.mapper.BaseMapper; + +/** + *

+ * Mapper 接口 + *

+ * + * @author zyj123 + * @since 2020-07-25 + */ +public interface FaceSubscribeMapper extends BaseMapper { + +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FacePersonSyncMapper.xml b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FacePersonSyncMapper.xml new file mode 100644 index 0000000..ac46ad0 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FacePersonSyncMapper.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + PERSON_ID AS personId, SYNC_ID AS syncId + + + + + diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FaceSubscribeMapper.xml b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FaceSubscribeMapper.xml new file mode 100644 index 0000000..16024e2 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FaceSubscribeMapper.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + SUBSCRIBE_ID AS subscribeId, DEVICE_CODE AS deviceCode, UPDATE_TIME AS updateTime + + + diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FacePersonSync.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FacePersonSync.java new file mode 100644 index 0000000..7cdb821 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FacePersonSync.java @@ -0,0 +1,68 @@ +package com.casic.missiles.modular.system.model; + +import java.io.Serializable; + +import com.baomidou.mybatisplus.annotations.TableId; +import com.baomidou.mybatisplus.annotations.TableField; +import com.baomidou.mybatisplus.activerecord.Model; +import com.baomidou.mybatisplus.annotations.TableName; +import java.io.Serializable; + +/** + *

+ * + *

+ * + * @author zyj123 + * @since 2020-07-24 + */ +@TableName("face_person_sync") +public class FacePersonSync extends Model { + + private static final long serialVersionUID = 1L; + + /** + * 人员id + */ + @TableId("PERSON_ID") + private Long personId; + /** + * 人员同步id + */ + @TableField("SYNC_ID") + private Long syncId; + + public FacePersonSync(Long personId, Long syncId) { + this.personId = personId; + this.syncId = syncId; + } + + public Long getPersonId() { + return personId; + } + + public void setPersonId(Long personId) { + this.personId = personId; + } + + public Long getSyncId() { + return syncId; + } + + public void setSyncId(Long syncId) { + this.syncId = syncId; + } + + @Override + protected Serializable pkVal() { + return this.personId; + } + + @Override + public String toString() { + return "FacePersonSync{" + + "personId=" + personId + + ", syncId=" + syncId + + "}"; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FaceSubscribe.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FaceSubscribe.java new file mode 100644 index 0000000..ccc7792 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FaceSubscribe.java @@ -0,0 +1,79 @@ +package com.casic.missiles.modular.system.model; + +import java.io.Serializable; + +import java.util.Date; +import com.baomidou.mybatisplus.annotations.TableId; +import com.baomidou.mybatisplus.annotations.TableField; +import com.baomidou.mybatisplus.activerecord.Model; +import com.baomidou.mybatisplus.annotations.TableName; +import java.io.Serializable; + +/** + *

+ * + *

+ * + * @author zyj123 + * @since 2020-07-25 + */ +@TableName("face_subscribe") +public class FaceSubscribe extends Model { + + private static final long serialVersionUID = 1L; + + /** + * 订阅id + */ + @TableId("SUBSCRIBE_ID") + private Long subscribeId; + /** + * 设备编号 + */ + @TableField("DEVICE_CODE") + private String deviceCode; + /** + * 更新时间 + */ + @TableField("UPDATE_TIME") + private Date updateTime; + + + public Long getSubscribeId() { + return subscribeId; + } + + public void setSubscribeId(Long subscribeId) { + this.subscribeId = subscribeId; + } + + public String getDeviceCode() { + return deviceCode; + } + + public void setDeviceCode(String deviceCode) { + this.deviceCode = deviceCode; + } + + public Date getUpdateTime() { + return updateTime; + } + + public void setUpdateTime(Date updateTime) { + this.updateTime = updateTime; + } + + @Override + protected Serializable pkVal() { + return this.subscribeId; + } + + @Override + public String toString() { + return "FaceSubscribe{" + + "subscribeId=" + subscribeId + + ", deviceCode=" + deviceCode + + ", updateTime=" + updateTime + + "}"; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/request/PersonInfo.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/request/PersonInfo.java new file mode 100644 index 0000000..80d9eff --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/request/PersonInfo.java @@ -0,0 +1,271 @@ +package com.casic.missiles.modular.system.request; + +import com.alibaba.fastjson.annotation.JSONField; +import com.baomidou.mybatisplus.annotations.TableField; +import com.google.gson.annotations.SerializedName; + +import java.util.List; + +public class PersonInfo { + + //@JSONField(name = "PersonID") + @SerializedName("PersonID") + private Long personID; + + //@JSONField(name = "LastChange") + @SerializedName("LastChange") + private Long lastChange; + + //@JSONField(name = "PersonCode") + @SerializedName("PersonCode") + private String personCode; + + //@JSONField(name = "PersonName") + @SerializedName("PersonName") + private String personName; + + //@JSONField(name = "Remarks") + @SerializedName("Remarks") + private String remarks; + + //@JSONField(name = "TimeTemplateNum") + @SerializedName("TimeTemplateNum") + private Integer timeTemplateNum; + + //@JSONField(name = "TimeTemplateList") + @SerializedName("TimeTemplateList") + private List timeTemplateList; + + //@JSONField(name = "IdentificationNum") + @SerializedName("IdentificationNum") + private Integer identificationNum; + + //@JSONField(name = "IdentificationList") + @SerializedName("IdentificationList") + private List identificationList; + + //@JSONField(name = "ImageNum") + @SerializedName("ImageNum") + private Integer imageNum; + + //@JSONField(name = "ImageList") + @SerializedName("ImageList") + private List imageList; + + public Long getPersonID() { + return personID; + } + + public void setPersonID(Long personID) { + this.personID = personID; + } + + public Long getLastChange() { + return lastChange; + } + + public void setLastChange(Long lastChange) { + this.lastChange = lastChange; + } + + public String getPersonCode() { + return personCode; + } + + public void setPersonCode(String personCode) { + this.personCode = personCode; + } + + public String getPersonName() { + return personName; + } + + public void setPersonName(String personName) { + this.personName = personName; + } + + public String getRemarks() { + return remarks; + } + + public void setRemarks(String remarks) { + this.remarks = remarks; + } + + public Integer getTimeTemplateNum() { + return timeTemplateNum; + } + + public void setTimeTemplateNum(Integer timeTemplateNum) { + this.timeTemplateNum = timeTemplateNum; + } + + public List getTimeTemplateList() { + return timeTemplateList; + } + + public void setTimeTemplateList(List timeTemplateList) { + this.timeTemplateList = timeTemplateList; + } + + public Integer getIdentificationNum() { + return identificationNum; + } + + public void setIdentificationNum(Integer identificationNum) { + this.identificationNum = identificationNum; + } + + public List getIdentificationList() { + return identificationList; + } + + public void setIdentificationList(List identificationList) { + this.identificationList = identificationList; + } + + public Integer getImageNum() { + return imageNum; + } + + public void setImageNum(Integer imageNum) { + this.imageNum = imageNum; + } + + public List getImageList() { + return imageList; + } + + public void setImageList(List imageList) { + this.imageList = imageList; + } + + public class TimeTemplate{ + @JSONField(name = "BeginTime") + private Long beginTime; + @JSONField(name = "EndTime") + private Long endTime; + @JSONField(name = "Index") + private Long index; + + public TimeTemplate(Long beginTime, Long endTime, Long index) { + this.beginTime = beginTime; + this.endTime = endTime; + this.index = index; + } + + public Long getBeginTime() { + return beginTime; + } + + public void setBeginTime(Long beginTime) { + this.beginTime = beginTime; + } + + public Long getEndTime() { + return endTime; + } + + public void setEndTime(Long endTime) { + this.endTime = endTime; + } + + public Long getIndex() { + return index; + } + + public void setIndex(Long index) { + this.index = index; + } + } + + public TimeTemplate createTimeTemplate(Long beginTime, Long endTime, Long index){ + return new TimeTemplate(beginTime, endTime, index); + } + + public class IdentificationInfo { + @JSONField(name = "Type") + private Integer type; + @JSONField(name = "Number") + private String number; + + public IdentificationInfo(Integer type, String number) { + this.type = type; + this.number = number; + } + + public Integer getType() { + return type; + } + + public void setType(Integer type) { + this.type = type; + } + + public String getNumber() { + return number; + } + + public void setNumber(String number) { + this.number = number; + } + } + + public IdentificationInfo createIdentificationInfo(Integer type, String number){ + return new IdentificationInfo(type,number); + } + + public class ImageInfo{ + @JSONField(name = "FaceID") + private Long faceID; + @JSONField(name = "Name") + private String name; + @JSONField(name = "Size") + private Long size; + @JSONField(name = "Data") + private String data; + + public ImageInfo(Long faceID, String name, Long size, String data) { + this.faceID = faceID; + this.name = name; + this.size = size; + this.data = data; + } + + public Long getFaceID() { + return faceID; + } + + public void setFaceID(Long faceID) { + this.faceID = faceID; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Long getSize() { + return size; + } + + public void setSize(Long size) { + this.size = size; + } + + public String getData() { + return data; + } + + public void setData(String data) { + this.data = data; + } + } + + public ImageInfo createImageInfo(Long faceID, String name, Long size, String data){ + return new ImageInfo(faceID, name, size, data); + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceBaseResponse.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceBaseResponse.java new file mode 100644 index 0000000..fe93b8a --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceBaseResponse.java @@ -0,0 +1,90 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; +import com.google.gson.annotations.SerializedName; + +public class FaceBaseResponse { + @JSONField(name = "ResponseURL") + @SerializedName("ResponseURL") + private String responseUrl; + + @JSONField(name = "CreatedID") + @SerializedName("CreatedID") + private int createdId; + + @JSONField(name = "ResponseCode") + @SerializedName("ResponseCode") + private int responseCode; + + @JSONField(name = "ResponseString") + @SerializedName("ResponseString") + private String responseString; + + @JSONField(name = "StatusCode") + @SerializedName("StatusCode") + private int statusCode; + + @JSONField(name = "StatusString") + @SerializedName("StatusString") + private String statusString; + + //@JSONField(name = "Data") + @SerializedName("Data") + private T data; + + public String getResponseUrl() { + return responseUrl; + } + + public void setResponseUrl(String responseUrl) { + this.responseUrl = responseUrl; + } + + public int getCreatedId() { + return createdId; + } + + public void setCreatedId(int createdId) { + this.createdId = createdId; + } + + public int getResponseCode() { + return responseCode; + } + + public void setResponseCode(int responseCode) { + this.responseCode = responseCode; + } + + public String getResponseString() { + return responseString; + } + + public void setResponseString(String responseString) { + this.responseString = responseString; + } + + public int getStatusCode() { + return statusCode; + } + + public void setStatusCode(int statusCode) { + this.statusCode = statusCode; + } + + public String getStatusString() { + return statusString; + } + + public void setStatusString(String statusString) { + this.statusString = statusString; + } + + public T getData() { + return data; + } + + public void setData(T data) { + this.data = data; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceInfo.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceInfo.java new file mode 100644 index 0000000..f128c92 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceInfo.java @@ -0,0 +1,128 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; + +import java.util.List; + +public class FaceInfo { + @JSONField(name = "ID") + private Long id; + @JSONField(name = "Timestamp") + private Long timestamp; + @JSONField(name = "CapSrc") + private Long capSrc; + @JSONField(name = "FeatureNum") + private Long featureNum; + @JSONField(name = "FeatureList") + private List featureList; + @JSONField(name = "FeatureVersion") + private String featureVersion; + @JSONField(name = "Feature") + private String feature; + @JSONField(name = "Temperature") + private Float temperature; + @JSONField(name = "MaskFlag") + private Long maskFlag; + @JSONField(name = "PanoImage") + private Object panoImage; + @JSONField(name = "FaceImage") + private Object faceImage; + @JSONField(name = "FaceArea") + private Object faceArea; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Long getTimestamp() { + return timestamp; + } + + public void setTimestamp(Long timestamp) { + this.timestamp = timestamp; + } + + public Long getCapSrc() { + return capSrc; + } + + public void setCapSrc(Long capSrc) { + this.capSrc = capSrc; + } + + public Long getFeatureNum() { + return featureNum; + } + + public void setFeatureNum(Long featureNum) { + this.featureNum = featureNum; + } + + public List getFeatureList() { + return featureList; + } + + public void setFeatureList(List featureList) { + this.featureList = featureList; + } + + public String getFeatureVersion() { + return featureVersion; + } + + public void setFeatureVersion(String featureVersion) { + this.featureVersion = featureVersion; + } + + public String getFeature() { + return feature; + } + + public void setFeature(String feature) { + this.feature = feature; + } + + public Float getTemperature() { + return temperature; + } + + public void setTemperature(Float temperature) { + this.temperature = temperature; + } + + public Long getMaskFlag() { + return maskFlag; + } + + public void setMaskFlag(Long maskFlag) { + this.maskFlag = maskFlag; + } + + public Object getPanoImage() { + return panoImage; + } + + public void setPanoImage(Object panoImage) { + this.panoImage = panoImage; + } + + public Object getFaceImage() { + return faceImage; + } + + public void setFaceImage(Object faceImage) { + this.faceImage = faceImage; + } + + public Object getFaceArea() { + return faceArea; + } + + public void setFaceArea(Object faceArea) { + this.faceArea = faceArea; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/LibMatInfo.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/LibMatInfo.java new file mode 100644 index 0000000..ce6dd33 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/LibMatInfo.java @@ -0,0 +1,69 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; + +public class LibMatInfo { + @JSONField(name = "ID") + private Long id; + @JSONField(name = "LibID") + private Long libId; + @JSONField(name = "LibType") + private Long libType; + @JSONField(name = "MatchStatus") + private Long matchStatus; + @JSONField(name = "MatchPersonID") + private Long matchPersonId; + @JSONField(name = "MatchFaceID") + private Long matchFaceId; + + // MatchPersonInfo 暂时忽略不用 + + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Long getLibId() { + return libId; + } + + public void setLibId(Long libId) { + this.libId = libId; + } + + public Long getLibType() { + return libType; + } + + public void setLibType(Long libType) { + this.libType = libType; + } + + public Long getMatchStatus() { + return matchStatus; + } + + public void setMatchStatus(Long matchStatus) { + this.matchStatus = matchStatus; + } + + public Long getMatchPersonId() { + return matchPersonId; + } + + public void setMatchPersonId(Long matchPersonId) { + this.matchPersonId = matchPersonId; + } + + public Long getMatchFaceId() { + return matchFaceId; + } + + public void setMatchFaceId(Long matchFaceId) { + this.matchFaceId = matchFaceId; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/PersonResponseData.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/PersonResponseData.java new file mode 100644 index 0000000..186faed --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/PersonResponseData.java @@ -0,0 +1,31 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; +import com.google.gson.annotations.SerializedName; + +import java.util.List; + +public class PersonResponseData { + @JSONField(name = "Num") + @SerializedName("Num") + private int num; + @JSONField(name = "PersonList") + @SerializedName("PersonList") + private List personList; + + public int getNum() { + return num; + } + + public void setNum(int num) { + this.num = num; + } + + public List getPersonList() { + return personList; + } + + public void setPersonList(List personList) { + this.personList = personList; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/PersonResponseInfo.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/PersonResponseInfo.java new file mode 100644 index 0000000..7ba3edc --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/PersonResponseInfo.java @@ -0,0 +1,67 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; +import com.google.gson.annotations.SerializedName; + +import java.util.List; + +public class PersonResponseInfo { + @JSONField(name = "PersonID") + @SerializedName("PersonID") + private Long personId; + @JSONField(name = "FaceNum") + @SerializedName("FaceNum") + private Long faceNum; + @JSONField(name = "FaceList") + @SerializedName("FaceList") + private List faceList; + + public Long getPersonId() { + return personId; + } + + public void setPersonId(Long personId) { + this.personId = personId; + } + + public Long getFaceNum() { + return faceNum; + } + + public void setFaceNum(Long faceNum) { + this.faceNum = faceNum; + } + + public List getFaceList() { + return faceList; + } + + public void setFaceList(List faceList) { + this.faceList = faceList; + } + + public class PersonResponseFace{ + @JSONField(name = "FaceID") + @SerializedName("FaceID") + private Long faceId; + @JSONField(name = "ResultCode") + @SerializedName("ResultCode") + private Long resultCode; + + public Long getFaceId() { + return faceId; + } + + public void setFaceId(Long faceId) { + this.faceId = faceId; + } + + public Long getResultCode() { + return resultCode; + } + + public void setResultCode(Long resultCode) { + this.resultCode = resultCode; + } + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/RecordNotification.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/RecordNotification.java new file mode 100644 index 0000000..ca52d29 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/RecordNotification.java @@ -0,0 +1,138 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; + +import java.util.List; + +public class RecordNotification { + @JSONField(name = "Reference") + private String reference; + @JSONField(name = "Seq") + private int seq; + @JSONField(name = "DeviceCode") + private String deviceCode; + @JSONField(name = "Timestamp") + private Long timestamp; + @JSONField(name = "NotificationType") + private int notificationType; + @JSONField(name = "FaceInfoNum") + private int faceInfoNum; + @JSONField(name = "FaceInfoList") + private List faceInfoList; + @JSONField(name = "CardInfoNum") + private int cardInfoNum; + @JSONField(name = "CardInfoList") + private List cardInfoList; + @JSONField(name = "GateInfoNum") + private int gateInfoNum; + @JSONField(name = "GateInfoList") + private List gateInfoList; + @JSONField(name = "LibMatInfoNum") + private int libMatInfoNum; + @JSONField(name = "LibMatInfoList") + private List libMatInfoList; + + public String getReference() { + return reference; + } + + public void setReference(String reference) { + this.reference = reference; + } + + public int getSeq() { + return seq; + } + + public void setSeq(int seq) { + this.seq = seq; + } + + public String getDeviceCode() { + return deviceCode; + } + + public void setDeviceCode(String deviceCode) { + this.deviceCode = deviceCode; + } + + public Long getTimestamp() { + return timestamp; + } + + public void setTimestamp(Long timestamp) { + this.timestamp = timestamp; + } + + public int getNotificationType() { + return notificationType; + } + + public void setNotificationType(int notificationType) { + this.notificationType = notificationType; + } + + public int getFaceInfoNum() { + return faceInfoNum; + } + + public void setFaceInfoNum(int faceInfoNum) { + this.faceInfoNum = faceInfoNum; + } + + public List getFaceInfoList() { + return faceInfoList; + } + + public void setFaceInfoList(List faceInfoList) { + this.faceInfoList = faceInfoList; + } + + public int getCardInfoNum() { + return cardInfoNum; + } + + public void setCardInfoNum(int cardInfoNum) { + this.cardInfoNum = cardInfoNum; + } + + public List getCardInfoList() { + return cardInfoList; + } + + public void setCardInfoList(List cardInfoList) { + this.cardInfoList = cardInfoList; + } + + public int getGateInfoNum() { + return gateInfoNum; + } + + public void setGateInfoNum(int gateInfoNum) { + this.gateInfoNum = gateInfoNum; + } + + public List getGateInfoList() { + return gateInfoList; + } + + public void setGateInfoList(List gateInfoList) { + this.gateInfoList = gateInfoList; + } + + public int getLibMatInfoNum() { + return libMatInfoNum; + } + + public void setLibMatInfoNum(int libMatInfoNum) { + this.libMatInfoNum = libMatInfoNum; + } + + public List getLibMatInfoList() { + return libMatInfoList; + } + + public void setLibMatInfoList(List libMatInfoList) { + this.libMatInfoList = libMatInfoList; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/runner/InitSubscribeRunner.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/runner/InitSubscribeRunner.java new file mode 100644 index 0000000..c7d0565 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/runner/InitSubscribeRunner.java @@ -0,0 +1,43 @@ +package com.casic.missiles.modular.system.runner; + +import com.casic.missiles.modular.system.model.Device; +import com.casic.missiles.modular.system.service.IDeviceSupportService; +import com.casic.missiles.modular.system.service.IFaceSyncService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.ApplicationArguments; +import org.springframework.boot.ApplicationRunner; +import org.springframework.stereotype.Component; + +import java.util.ArrayList; +import java.util.List; + +@Component +public class InitSubscribeRunner implements ApplicationRunner { + private static Logger logger = LoggerFactory.getLogger(InitSubscribeRunner.class); + + @Value("${iris.face.initSubscribe}") + private String initSubscribe; + @Autowired + private IDeviceSupportService deviceSupportService; + @Autowired + private IFaceSyncService faceSyncService; + + /** + * 启动项目时,根据需要初始化设备订阅信息 + * @param applicationArguments + * @throws Exception + */ + @Override + public void run(ApplicationArguments applicationArguments) throws Exception { + logger.info("==================initSubscribe: "); + if(Boolean.valueOf(initSubscribe)){ + List deviceList = deviceSupportService.selectDeviceByType("5"); + List deviceIds = new ArrayList<>(); + deviceList.forEach(device -> deviceIds.add(Long.valueOf(device.getId()))); + faceSyncService.initSubscription(deviceIds); + } + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFacePersonSyncService.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFacePersonSyncService.java new file mode 100644 index 0000000..6b2461b --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFacePersonSyncService.java @@ -0,0 +1,18 @@ +package com.casic.missiles.modular.system.service; + +import com.casic.missiles.modular.system.model.FacePersonSync; +import com.baomidou.mybatisplus.service.IService; + +/** + *

+ * 服务类 + *

+ * + * @author zyj123 + * @since 2020-07-24 + */ +public interface IFacePersonSyncService extends IService { + Long selectSyncId(Long personId); + Long selectPersonId(Long syncId); + Long getMaxSyncId(Long personId); +} diff --git a/casic-face-sync/pom.xml b/casic-face-sync/pom.xml new file mode 100644 index 0000000..24dc884 --- /dev/null +++ b/casic-face-sync/pom.xml @@ -0,0 +1,74 @@ + + + 4.0.0 + + com.casic + casic-iris-parent + 1.0.0-SNAPSHOT + ../pom.xml + + + + casic-face-sync + ${pro.version} + jar + casic-face-sync + + + + + + com.casic + casic-core + ${core.version} + + + + com.casic + casic-admin-support + ${admin.version} + + + com.casic + casic-iris-support + ${pro.version} + + + + org.apache.httpcomponents + httpclient + 4.5.3 + + + + org.apache.httpcomponents + httpcore + 4.4.8 + + + + org.apache.httpcomponents + httpmime + 4.5.3 + + + + com.google.code.gson + gson + + + + + + + + src/main/java + + **/*.xml + + + + + \ No newline at end of file diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/constant/FaceSyncConst.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/constant/FaceSyncConst.java new file mode 100644 index 0000000..352d47d --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/constant/FaceSyncConst.java @@ -0,0 +1,29 @@ +package com.casic.missiles.modular.system.constant; + +public class FaceSyncConst { + + /** + * 单次最大批量上传人员数 + */ + public static final int UPLOAD_MAX_PERSON = 6; + + /** + * 上传人员库 + */ + public static final String UPLOAD_STAFF_LIB = "3"; + public static final String UPLOAD_VISITOR_LIB = "4"; + + public static final String UPLOAD_URL_PREFIX = "/LAPI/V1.0/PeopleLibraries/"; + + public static final String UPLOAD_URL_SUFFIX = "/People"; + + public static final int UPLOAD_PERSONCODE_MAXLENGTH = 15; + + public static final int UPLOAD_REMARK_MAXLENGTH = 63; + + public static final String SUBSCRIBE_URL = "/LAPI/V1.0/System/Event/Subscription/"; + + public static final String STAFF_PERSON_TYPE = "1"; + + public static final String VISITOR_PERSON_TYPE = "0"; +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/controller/FaceSyncController.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/controller/FaceSyncController.java new file mode 100644 index 0000000..1b35431 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/controller/FaceSyncController.java @@ -0,0 +1,117 @@ +package com.casic.missiles.modular.system.controller; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson.serializer.SerializerFeature; +import com.casic.missiles.core.base.response.ResponseData; +import com.casic.missiles.core.common.service.ICommonPermissionService; +import com.casic.missiles.core.common.service.ICommonPersonService; +import com.casic.missiles.core.datascope.DataScope; +import com.casic.missiles.core.util.ToolUtil; +import com.casic.missiles.modular.system.request.PersonInfo; +import com.casic.missiles.modular.system.response.RecordNotification; +import com.casic.missiles.modular.system.service.IFaceSyncService; +import com.casic.missiles.modular.system.service.IIrisPersonSupportService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.*; +import com.casic.missiles.modular.system.constant.FaceSyncConst; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + + + +@Controller +public class FaceSyncController { + private final static Logger logger = LoggerFactory.getLogger(FaceSyncController.class); + + @Autowired + private IFaceSyncService syncService; + @Autowired + private ICommonPersonService commonPersonService; + @Autowired + private IIrisPersonSupportService personSupportService; + @Autowired + private ICommonPermissionService permissionService; + + @RequestMapping("/face/upload") + @ResponseBody + public Object upload(@RequestParam("personIds") List personIds, + @RequestParam("deviceIds") List deviceIds, + @RequestParam("personType")String personType ){ + // 检查数量 +// if(personIds.size()>FaceSyncConst.UPLOAD_MAX_PERSON){ +// return ResponseData.error(String.format("每次最多上传%s个人",FaceSyncConst.UPLOAD_MAX_PERSON)); +// } + // 检查照片格式及大小 + String photoCheck = syncService.checkPersonPhoto(personIds); + if(ToolUtil.isNotEmpty(photoCheck)){ + return ResponseData.error(photoCheck); + } + else{ + // 上传数据 + String error = syncService.uploadPerson(personIds,deviceIds,personType); + if(ToolUtil.isNotEmpty(error)){ + return ResponseData.error(error); + } + } + return ResponseData.success(); + } + + @RequestMapping("/face/uploadAll") + @ResponseBody + public Object uploadAll(@RequestParam("deviceIds") List deviceIds){ + DataScope dataScope = permissionService.getCurrUserDataScope(); + + List staffPersonIds = personSupportService.listIdsByType(dataScope,FaceSyncConst.STAFF_PERSON_TYPE); + List visitorPersonIds = personSupportService.listIdsByType(dataScope,FaceSyncConst.VISITOR_PERSON_TYPE); + // 1.检查照片,分别检查员工、访客 + String staffPhotoCheck = syncService.checkPersonPhoto(staffPersonIds); + if(ToolUtil.isNotEmpty(staffPhotoCheck)){ + return ResponseData.error(staffPhotoCheck); + } + String visitorPhotoCheck = syncService.checkPersonPhoto(visitorPersonIds); + if(ToolUtil.isNotEmpty(visitorPhotoCheck)){ + return ResponseData.error(visitorPhotoCheck); + } + + // 2. 下发数据 + String staffError = syncService.uploadPerson(staffPersonIds,deviceIds,FaceSyncConst.STAFF_PERSON_TYPE); + if(ToolUtil.isNotEmpty(staffError)){ + return ResponseData.error(staffError); + } + String visitorError = syncService.uploadPerson(visitorPersonIds,deviceIds,FaceSyncConst.VISITOR_PERSON_TYPE); + if(ToolUtil.isNotEmpty(visitorError)){ + return ResponseData.error(visitorError); + } + + return ResponseData.success(); + } + + // 错误信息返回 + @RequestMapping("/subsrcibe/init") + @ResponseBody + public Object upload(@RequestParam("deviceIds") List deviceIds){ + String errorMsg = syncService.initSubscription(deviceIds); + if(ToolUtil.isNotEmpty(errorMsg)){ + return ResponseData.error(errorMsg); + } + return ResponseData.success(); + } + + + @RequestMapping(value = "/LAPI/V1.0/System/Event/Notification/PersonVerification", method = RequestMethod.POST) + @ResponseBody + public void verification(@RequestBody String recordNotification){ + logger.info(recordNotification); + RecordNotification record = JSONObject.parseObject(recordNotification,RecordNotification.class); + syncService.receiveRecord(record); + //return ResponseData.success(); + } + + +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FacePersonSyncMapper.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FacePersonSyncMapper.java new file mode 100644 index 0000000..af53702 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FacePersonSyncMapper.java @@ -0,0 +1,17 @@ +package com.casic.missiles.modular.system.dao; + +import com.casic.missiles.modular.system.model.FacePersonSync; +import com.baomidou.mybatisplus.mapper.BaseMapper; + +/** + *

+ * Mapper 接口 + *

+ * + * @author zyj123 + * @since 2020-07-24 + */ +public interface FacePersonSyncMapper extends BaseMapper { + + Long getMaxSyncId(); +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FaceSubscribeMapper.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FaceSubscribeMapper.java new file mode 100644 index 0000000..0c6374a --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FaceSubscribeMapper.java @@ -0,0 +1,16 @@ +package com.casic.missiles.modular.system.dao; + +import com.casic.missiles.modular.system.model.FaceSubscribe; +import com.baomidou.mybatisplus.mapper.BaseMapper; + +/** + *

+ * Mapper 接口 + *

+ * + * @author zyj123 + * @since 2020-07-25 + */ +public interface FaceSubscribeMapper extends BaseMapper { + +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FacePersonSyncMapper.xml b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FacePersonSyncMapper.xml new file mode 100644 index 0000000..ac46ad0 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FacePersonSyncMapper.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + PERSON_ID AS personId, SYNC_ID AS syncId + + + + + diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FaceSubscribeMapper.xml b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FaceSubscribeMapper.xml new file mode 100644 index 0000000..16024e2 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FaceSubscribeMapper.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + SUBSCRIBE_ID AS subscribeId, DEVICE_CODE AS deviceCode, UPDATE_TIME AS updateTime + + + diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FacePersonSync.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FacePersonSync.java new file mode 100644 index 0000000..7cdb821 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FacePersonSync.java @@ -0,0 +1,68 @@ +package com.casic.missiles.modular.system.model; + +import java.io.Serializable; + +import com.baomidou.mybatisplus.annotations.TableId; +import com.baomidou.mybatisplus.annotations.TableField; +import com.baomidou.mybatisplus.activerecord.Model; +import com.baomidou.mybatisplus.annotations.TableName; +import java.io.Serializable; + +/** + *

+ * + *

+ * + * @author zyj123 + * @since 2020-07-24 + */ +@TableName("face_person_sync") +public class FacePersonSync extends Model { + + private static final long serialVersionUID = 1L; + + /** + * 人员id + */ + @TableId("PERSON_ID") + private Long personId; + /** + * 人员同步id + */ + @TableField("SYNC_ID") + private Long syncId; + + public FacePersonSync(Long personId, Long syncId) { + this.personId = personId; + this.syncId = syncId; + } + + public Long getPersonId() { + return personId; + } + + public void setPersonId(Long personId) { + this.personId = personId; + } + + public Long getSyncId() { + return syncId; + } + + public void setSyncId(Long syncId) { + this.syncId = syncId; + } + + @Override + protected Serializable pkVal() { + return this.personId; + } + + @Override + public String toString() { + return "FacePersonSync{" + + "personId=" + personId + + ", syncId=" + syncId + + "}"; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FaceSubscribe.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FaceSubscribe.java new file mode 100644 index 0000000..ccc7792 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FaceSubscribe.java @@ -0,0 +1,79 @@ +package com.casic.missiles.modular.system.model; + +import java.io.Serializable; + +import java.util.Date; +import com.baomidou.mybatisplus.annotations.TableId; +import com.baomidou.mybatisplus.annotations.TableField; +import com.baomidou.mybatisplus.activerecord.Model; +import com.baomidou.mybatisplus.annotations.TableName; +import java.io.Serializable; + +/** + *

+ * + *

+ * + * @author zyj123 + * @since 2020-07-25 + */ +@TableName("face_subscribe") +public class FaceSubscribe extends Model { + + private static final long serialVersionUID = 1L; + + /** + * 订阅id + */ + @TableId("SUBSCRIBE_ID") + private Long subscribeId; + /** + * 设备编号 + */ + @TableField("DEVICE_CODE") + private String deviceCode; + /** + * 更新时间 + */ + @TableField("UPDATE_TIME") + private Date updateTime; + + + public Long getSubscribeId() { + return subscribeId; + } + + public void setSubscribeId(Long subscribeId) { + this.subscribeId = subscribeId; + } + + public String getDeviceCode() { + return deviceCode; + } + + public void setDeviceCode(String deviceCode) { + this.deviceCode = deviceCode; + } + + public Date getUpdateTime() { + return updateTime; + } + + public void setUpdateTime(Date updateTime) { + this.updateTime = updateTime; + } + + @Override + protected Serializable pkVal() { + return this.subscribeId; + } + + @Override + public String toString() { + return "FaceSubscribe{" + + "subscribeId=" + subscribeId + + ", deviceCode=" + deviceCode + + ", updateTime=" + updateTime + + "}"; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/request/PersonInfo.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/request/PersonInfo.java new file mode 100644 index 0000000..80d9eff --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/request/PersonInfo.java @@ -0,0 +1,271 @@ +package com.casic.missiles.modular.system.request; + +import com.alibaba.fastjson.annotation.JSONField; +import com.baomidou.mybatisplus.annotations.TableField; +import com.google.gson.annotations.SerializedName; + +import java.util.List; + +public class PersonInfo { + + //@JSONField(name = "PersonID") + @SerializedName("PersonID") + private Long personID; + + //@JSONField(name = "LastChange") + @SerializedName("LastChange") + private Long lastChange; + + //@JSONField(name = "PersonCode") + @SerializedName("PersonCode") + private String personCode; + + //@JSONField(name = "PersonName") + @SerializedName("PersonName") + private String personName; + + //@JSONField(name = "Remarks") + @SerializedName("Remarks") + private String remarks; + + //@JSONField(name = "TimeTemplateNum") + @SerializedName("TimeTemplateNum") + private Integer timeTemplateNum; + + //@JSONField(name = "TimeTemplateList") + @SerializedName("TimeTemplateList") + private List timeTemplateList; + + //@JSONField(name = "IdentificationNum") + @SerializedName("IdentificationNum") + private Integer identificationNum; + + //@JSONField(name = "IdentificationList") + @SerializedName("IdentificationList") + private List identificationList; + + //@JSONField(name = "ImageNum") + @SerializedName("ImageNum") + private Integer imageNum; + + //@JSONField(name = "ImageList") + @SerializedName("ImageList") + private List imageList; + + public Long getPersonID() { + return personID; + } + + public void setPersonID(Long personID) { + this.personID = personID; + } + + public Long getLastChange() { + return lastChange; + } + + public void setLastChange(Long lastChange) { + this.lastChange = lastChange; + } + + public String getPersonCode() { + return personCode; + } + + public void setPersonCode(String personCode) { + this.personCode = personCode; + } + + public String getPersonName() { + return personName; + } + + public void setPersonName(String personName) { + this.personName = personName; + } + + public String getRemarks() { + return remarks; + } + + public void setRemarks(String remarks) { + this.remarks = remarks; + } + + public Integer getTimeTemplateNum() { + return timeTemplateNum; + } + + public void setTimeTemplateNum(Integer timeTemplateNum) { + this.timeTemplateNum = timeTemplateNum; + } + + public List getTimeTemplateList() { + return timeTemplateList; + } + + public void setTimeTemplateList(List timeTemplateList) { + this.timeTemplateList = timeTemplateList; + } + + public Integer getIdentificationNum() { + return identificationNum; + } + + public void setIdentificationNum(Integer identificationNum) { + this.identificationNum = identificationNum; + } + + public List getIdentificationList() { + return identificationList; + } + + public void setIdentificationList(List identificationList) { + this.identificationList = identificationList; + } + + public Integer getImageNum() { + return imageNum; + } + + public void setImageNum(Integer imageNum) { + this.imageNum = imageNum; + } + + public List getImageList() { + return imageList; + } + + public void setImageList(List imageList) { + this.imageList = imageList; + } + + public class TimeTemplate{ + @JSONField(name = "BeginTime") + private Long beginTime; + @JSONField(name = "EndTime") + private Long endTime; + @JSONField(name = "Index") + private Long index; + + public TimeTemplate(Long beginTime, Long endTime, Long index) { + this.beginTime = beginTime; + this.endTime = endTime; + this.index = index; + } + + public Long getBeginTime() { + return beginTime; + } + + public void setBeginTime(Long beginTime) { + this.beginTime = beginTime; + } + + public Long getEndTime() { + return endTime; + } + + public void setEndTime(Long endTime) { + this.endTime = endTime; + } + + public Long getIndex() { + return index; + } + + public void setIndex(Long index) { + this.index = index; + } + } + + public TimeTemplate createTimeTemplate(Long beginTime, Long endTime, Long index){ + return new TimeTemplate(beginTime, endTime, index); + } + + public class IdentificationInfo { + @JSONField(name = "Type") + private Integer type; + @JSONField(name = "Number") + private String number; + + public IdentificationInfo(Integer type, String number) { + this.type = type; + this.number = number; + } + + public Integer getType() { + return type; + } + + public void setType(Integer type) { + this.type = type; + } + + public String getNumber() { + return number; + } + + public void setNumber(String number) { + this.number = number; + } + } + + public IdentificationInfo createIdentificationInfo(Integer type, String number){ + return new IdentificationInfo(type,number); + } + + public class ImageInfo{ + @JSONField(name = "FaceID") + private Long faceID; + @JSONField(name = "Name") + private String name; + @JSONField(name = "Size") + private Long size; + @JSONField(name = "Data") + private String data; + + public ImageInfo(Long faceID, String name, Long size, String data) { + this.faceID = faceID; + this.name = name; + this.size = size; + this.data = data; + } + + public Long getFaceID() { + return faceID; + } + + public void setFaceID(Long faceID) { + this.faceID = faceID; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Long getSize() { + return size; + } + + public void setSize(Long size) { + this.size = size; + } + + public String getData() { + return data; + } + + public void setData(String data) { + this.data = data; + } + } + + public ImageInfo createImageInfo(Long faceID, String name, Long size, String data){ + return new ImageInfo(faceID, name, size, data); + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceBaseResponse.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceBaseResponse.java new file mode 100644 index 0000000..fe93b8a --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceBaseResponse.java @@ -0,0 +1,90 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; +import com.google.gson.annotations.SerializedName; + +public class FaceBaseResponse { + @JSONField(name = "ResponseURL") + @SerializedName("ResponseURL") + private String responseUrl; + + @JSONField(name = "CreatedID") + @SerializedName("CreatedID") + private int createdId; + + @JSONField(name = "ResponseCode") + @SerializedName("ResponseCode") + private int responseCode; + + @JSONField(name = "ResponseString") + @SerializedName("ResponseString") + private String responseString; + + @JSONField(name = "StatusCode") + @SerializedName("StatusCode") + private int statusCode; + + @JSONField(name = "StatusString") + @SerializedName("StatusString") + private String statusString; + + //@JSONField(name = "Data") + @SerializedName("Data") + private T data; + + public String getResponseUrl() { + return responseUrl; + } + + public void setResponseUrl(String responseUrl) { + this.responseUrl = responseUrl; + } + + public int getCreatedId() { + return createdId; + } + + public void setCreatedId(int createdId) { + this.createdId = createdId; + } + + public int getResponseCode() { + return responseCode; + } + + public void setResponseCode(int responseCode) { + this.responseCode = responseCode; + } + + public String getResponseString() { + return responseString; + } + + public void setResponseString(String responseString) { + this.responseString = responseString; + } + + public int getStatusCode() { + return statusCode; + } + + public void setStatusCode(int statusCode) { + this.statusCode = statusCode; + } + + public String getStatusString() { + return statusString; + } + + public void setStatusString(String statusString) { + this.statusString = statusString; + } + + public T getData() { + return data; + } + + public void setData(T data) { + this.data = data; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceInfo.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceInfo.java new file mode 100644 index 0000000..f128c92 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceInfo.java @@ -0,0 +1,128 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; + +import java.util.List; + +public class FaceInfo { + @JSONField(name = "ID") + private Long id; + @JSONField(name = "Timestamp") + private Long timestamp; + @JSONField(name = "CapSrc") + private Long capSrc; + @JSONField(name = "FeatureNum") + private Long featureNum; + @JSONField(name = "FeatureList") + private List featureList; + @JSONField(name = "FeatureVersion") + private String featureVersion; + @JSONField(name = "Feature") + private String feature; + @JSONField(name = "Temperature") + private Float temperature; + @JSONField(name = "MaskFlag") + private Long maskFlag; + @JSONField(name = "PanoImage") + private Object panoImage; + @JSONField(name = "FaceImage") + private Object faceImage; + @JSONField(name = "FaceArea") + private Object faceArea; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Long getTimestamp() { + return timestamp; + } + + public void setTimestamp(Long timestamp) { + this.timestamp = timestamp; + } + + public Long getCapSrc() { + return capSrc; + } + + public void setCapSrc(Long capSrc) { + this.capSrc = capSrc; + } + + public Long getFeatureNum() { + return featureNum; + } + + public void setFeatureNum(Long featureNum) { + this.featureNum = featureNum; + } + + public List getFeatureList() { + return featureList; + } + + public void setFeatureList(List featureList) { + this.featureList = featureList; + } + + public String getFeatureVersion() { + return featureVersion; + } + + public void setFeatureVersion(String featureVersion) { + this.featureVersion = featureVersion; + } + + public String getFeature() { + return feature; + } + + public void setFeature(String feature) { + this.feature = feature; + } + + public Float getTemperature() { + return temperature; + } + + public void setTemperature(Float temperature) { + this.temperature = temperature; + } + + public Long getMaskFlag() { + return maskFlag; + } + + public void setMaskFlag(Long maskFlag) { + this.maskFlag = maskFlag; + } + + public Object getPanoImage() { + return panoImage; + } + + public void setPanoImage(Object panoImage) { + this.panoImage = panoImage; + } + + public Object getFaceImage() { + return faceImage; + } + + public void setFaceImage(Object faceImage) { + this.faceImage = faceImage; + } + + public Object getFaceArea() { + return faceArea; + } + + public void setFaceArea(Object faceArea) { + this.faceArea = faceArea; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/LibMatInfo.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/LibMatInfo.java new file mode 100644 index 0000000..ce6dd33 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/LibMatInfo.java @@ -0,0 +1,69 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; + +public class LibMatInfo { + @JSONField(name = "ID") + private Long id; + @JSONField(name = "LibID") + private Long libId; + @JSONField(name = "LibType") + private Long libType; + @JSONField(name = "MatchStatus") + private Long matchStatus; + @JSONField(name = "MatchPersonID") + private Long matchPersonId; + @JSONField(name = "MatchFaceID") + private Long matchFaceId; + + // MatchPersonInfo 暂时忽略不用 + + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Long getLibId() { + return libId; + } + + public void setLibId(Long libId) { + this.libId = libId; + } + + public Long getLibType() { + return libType; + } + + public void setLibType(Long libType) { + this.libType = libType; + } + + public Long getMatchStatus() { + return matchStatus; + } + + public void setMatchStatus(Long matchStatus) { + this.matchStatus = matchStatus; + } + + public Long getMatchPersonId() { + return matchPersonId; + } + + public void setMatchPersonId(Long matchPersonId) { + this.matchPersonId = matchPersonId; + } + + public Long getMatchFaceId() { + return matchFaceId; + } + + public void setMatchFaceId(Long matchFaceId) { + this.matchFaceId = matchFaceId; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/PersonResponseData.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/PersonResponseData.java new file mode 100644 index 0000000..186faed --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/PersonResponseData.java @@ -0,0 +1,31 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; +import com.google.gson.annotations.SerializedName; + +import java.util.List; + +public class PersonResponseData { + @JSONField(name = "Num") + @SerializedName("Num") + private int num; + @JSONField(name = "PersonList") + @SerializedName("PersonList") + private List personList; + + public int getNum() { + return num; + } + + public void setNum(int num) { + this.num = num; + } + + public List getPersonList() { + return personList; + } + + public void setPersonList(List personList) { + this.personList = personList; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/PersonResponseInfo.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/PersonResponseInfo.java new file mode 100644 index 0000000..7ba3edc --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/PersonResponseInfo.java @@ -0,0 +1,67 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; +import com.google.gson.annotations.SerializedName; + +import java.util.List; + +public class PersonResponseInfo { + @JSONField(name = "PersonID") + @SerializedName("PersonID") + private Long personId; + @JSONField(name = "FaceNum") + @SerializedName("FaceNum") + private Long faceNum; + @JSONField(name = "FaceList") + @SerializedName("FaceList") + private List faceList; + + public Long getPersonId() { + return personId; + } + + public void setPersonId(Long personId) { + this.personId = personId; + } + + public Long getFaceNum() { + return faceNum; + } + + public void setFaceNum(Long faceNum) { + this.faceNum = faceNum; + } + + public List getFaceList() { + return faceList; + } + + public void setFaceList(List faceList) { + this.faceList = faceList; + } + + public class PersonResponseFace{ + @JSONField(name = "FaceID") + @SerializedName("FaceID") + private Long faceId; + @JSONField(name = "ResultCode") + @SerializedName("ResultCode") + private Long resultCode; + + public Long getFaceId() { + return faceId; + } + + public void setFaceId(Long faceId) { + this.faceId = faceId; + } + + public Long getResultCode() { + return resultCode; + } + + public void setResultCode(Long resultCode) { + this.resultCode = resultCode; + } + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/RecordNotification.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/RecordNotification.java new file mode 100644 index 0000000..ca52d29 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/RecordNotification.java @@ -0,0 +1,138 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; + +import java.util.List; + +public class RecordNotification { + @JSONField(name = "Reference") + private String reference; + @JSONField(name = "Seq") + private int seq; + @JSONField(name = "DeviceCode") + private String deviceCode; + @JSONField(name = "Timestamp") + private Long timestamp; + @JSONField(name = "NotificationType") + private int notificationType; + @JSONField(name = "FaceInfoNum") + private int faceInfoNum; + @JSONField(name = "FaceInfoList") + private List faceInfoList; + @JSONField(name = "CardInfoNum") + private int cardInfoNum; + @JSONField(name = "CardInfoList") + private List cardInfoList; + @JSONField(name = "GateInfoNum") + private int gateInfoNum; + @JSONField(name = "GateInfoList") + private List gateInfoList; + @JSONField(name = "LibMatInfoNum") + private int libMatInfoNum; + @JSONField(name = "LibMatInfoList") + private List libMatInfoList; + + public String getReference() { + return reference; + } + + public void setReference(String reference) { + this.reference = reference; + } + + public int getSeq() { + return seq; + } + + public void setSeq(int seq) { + this.seq = seq; + } + + public String getDeviceCode() { + return deviceCode; + } + + public void setDeviceCode(String deviceCode) { + this.deviceCode = deviceCode; + } + + public Long getTimestamp() { + return timestamp; + } + + public void setTimestamp(Long timestamp) { + this.timestamp = timestamp; + } + + public int getNotificationType() { + return notificationType; + } + + public void setNotificationType(int notificationType) { + this.notificationType = notificationType; + } + + public int getFaceInfoNum() { + return faceInfoNum; + } + + public void setFaceInfoNum(int faceInfoNum) { + this.faceInfoNum = faceInfoNum; + } + + public List getFaceInfoList() { + return faceInfoList; + } + + public void setFaceInfoList(List faceInfoList) { + this.faceInfoList = faceInfoList; + } + + public int getCardInfoNum() { + return cardInfoNum; + } + + public void setCardInfoNum(int cardInfoNum) { + this.cardInfoNum = cardInfoNum; + } + + public List getCardInfoList() { + return cardInfoList; + } + + public void setCardInfoList(List cardInfoList) { + this.cardInfoList = cardInfoList; + } + + public int getGateInfoNum() { + return gateInfoNum; + } + + public void setGateInfoNum(int gateInfoNum) { + this.gateInfoNum = gateInfoNum; + } + + public List getGateInfoList() { + return gateInfoList; + } + + public void setGateInfoList(List gateInfoList) { + this.gateInfoList = gateInfoList; + } + + public int getLibMatInfoNum() { + return libMatInfoNum; + } + + public void setLibMatInfoNum(int libMatInfoNum) { + this.libMatInfoNum = libMatInfoNum; + } + + public List getLibMatInfoList() { + return libMatInfoList; + } + + public void setLibMatInfoList(List libMatInfoList) { + this.libMatInfoList = libMatInfoList; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/runner/InitSubscribeRunner.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/runner/InitSubscribeRunner.java new file mode 100644 index 0000000..c7d0565 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/runner/InitSubscribeRunner.java @@ -0,0 +1,43 @@ +package com.casic.missiles.modular.system.runner; + +import com.casic.missiles.modular.system.model.Device; +import com.casic.missiles.modular.system.service.IDeviceSupportService; +import com.casic.missiles.modular.system.service.IFaceSyncService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.ApplicationArguments; +import org.springframework.boot.ApplicationRunner; +import org.springframework.stereotype.Component; + +import java.util.ArrayList; +import java.util.List; + +@Component +public class InitSubscribeRunner implements ApplicationRunner { + private static Logger logger = LoggerFactory.getLogger(InitSubscribeRunner.class); + + @Value("${iris.face.initSubscribe}") + private String initSubscribe; + @Autowired + private IDeviceSupportService deviceSupportService; + @Autowired + private IFaceSyncService faceSyncService; + + /** + * 启动项目时,根据需要初始化设备订阅信息 + * @param applicationArguments + * @throws Exception + */ + @Override + public void run(ApplicationArguments applicationArguments) throws Exception { + logger.info("==================initSubscribe: "); + if(Boolean.valueOf(initSubscribe)){ + List deviceList = deviceSupportService.selectDeviceByType("5"); + List deviceIds = new ArrayList<>(); + deviceList.forEach(device -> deviceIds.add(Long.valueOf(device.getId()))); + faceSyncService.initSubscription(deviceIds); + } + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFacePersonSyncService.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFacePersonSyncService.java new file mode 100644 index 0000000..6b2461b --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFacePersonSyncService.java @@ -0,0 +1,18 @@ +package com.casic.missiles.modular.system.service; + +import com.casic.missiles.modular.system.model.FacePersonSync; +import com.baomidou.mybatisplus.service.IService; + +/** + *

+ * 服务类 + *

+ * + * @author zyj123 + * @since 2020-07-24 + */ +public interface IFacePersonSyncService extends IService { + Long selectSyncId(Long personId); + Long selectPersonId(Long syncId); + Long getMaxSyncId(Long personId); +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFaceSubscribeService.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFaceSubscribeService.java new file mode 100644 index 0000000..e0461ed --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFaceSubscribeService.java @@ -0,0 +1,24 @@ +package com.casic.missiles.modular.system.service; + +import com.casic.missiles.modular.system.model.FaceSubscribe; +import com.baomidou.mybatisplus.service.IService; + +import java.util.List; + +/** + *

+ * 服务类 + *

+ * + * @author zyj123 + * @since 2020-07-25 + */ +public interface IFaceSubscribeService extends IService { + + List selectSubscribeIdsByDevCode(String devCode); + + boolean deleteByDevCode(String devCode); + + boolean insertSubscribe(Long subscribeId, String devCode); + +} diff --git a/casic-face-sync/pom.xml b/casic-face-sync/pom.xml new file mode 100644 index 0000000..24dc884 --- /dev/null +++ b/casic-face-sync/pom.xml @@ -0,0 +1,74 @@ + + + 4.0.0 + + com.casic + casic-iris-parent + 1.0.0-SNAPSHOT + ../pom.xml + + + + casic-face-sync + ${pro.version} + jar + casic-face-sync + + + + + + com.casic + casic-core + ${core.version} + + + + com.casic + casic-admin-support + ${admin.version} + + + com.casic + casic-iris-support + ${pro.version} + + + + org.apache.httpcomponents + httpclient + 4.5.3 + + + + org.apache.httpcomponents + httpcore + 4.4.8 + + + + org.apache.httpcomponents + httpmime + 4.5.3 + + + + com.google.code.gson + gson + + + + + + + + src/main/java + + **/*.xml + + + + + \ No newline at end of file diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/constant/FaceSyncConst.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/constant/FaceSyncConst.java new file mode 100644 index 0000000..352d47d --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/constant/FaceSyncConst.java @@ -0,0 +1,29 @@ +package com.casic.missiles.modular.system.constant; + +public class FaceSyncConst { + + /** + * 单次最大批量上传人员数 + */ + public static final int UPLOAD_MAX_PERSON = 6; + + /** + * 上传人员库 + */ + public static final String UPLOAD_STAFF_LIB = "3"; + public static final String UPLOAD_VISITOR_LIB = "4"; + + public static final String UPLOAD_URL_PREFIX = "/LAPI/V1.0/PeopleLibraries/"; + + public static final String UPLOAD_URL_SUFFIX = "/People"; + + public static final int UPLOAD_PERSONCODE_MAXLENGTH = 15; + + public static final int UPLOAD_REMARK_MAXLENGTH = 63; + + public static final String SUBSCRIBE_URL = "/LAPI/V1.0/System/Event/Subscription/"; + + public static final String STAFF_PERSON_TYPE = "1"; + + public static final String VISITOR_PERSON_TYPE = "0"; +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/controller/FaceSyncController.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/controller/FaceSyncController.java new file mode 100644 index 0000000..1b35431 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/controller/FaceSyncController.java @@ -0,0 +1,117 @@ +package com.casic.missiles.modular.system.controller; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson.serializer.SerializerFeature; +import com.casic.missiles.core.base.response.ResponseData; +import com.casic.missiles.core.common.service.ICommonPermissionService; +import com.casic.missiles.core.common.service.ICommonPersonService; +import com.casic.missiles.core.datascope.DataScope; +import com.casic.missiles.core.util.ToolUtil; +import com.casic.missiles.modular.system.request.PersonInfo; +import com.casic.missiles.modular.system.response.RecordNotification; +import com.casic.missiles.modular.system.service.IFaceSyncService; +import com.casic.missiles.modular.system.service.IIrisPersonSupportService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.*; +import com.casic.missiles.modular.system.constant.FaceSyncConst; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + + + +@Controller +public class FaceSyncController { + private final static Logger logger = LoggerFactory.getLogger(FaceSyncController.class); + + @Autowired + private IFaceSyncService syncService; + @Autowired + private ICommonPersonService commonPersonService; + @Autowired + private IIrisPersonSupportService personSupportService; + @Autowired + private ICommonPermissionService permissionService; + + @RequestMapping("/face/upload") + @ResponseBody + public Object upload(@RequestParam("personIds") List personIds, + @RequestParam("deviceIds") List deviceIds, + @RequestParam("personType")String personType ){ + // 检查数量 +// if(personIds.size()>FaceSyncConst.UPLOAD_MAX_PERSON){ +// return ResponseData.error(String.format("每次最多上传%s个人",FaceSyncConst.UPLOAD_MAX_PERSON)); +// } + // 检查照片格式及大小 + String photoCheck = syncService.checkPersonPhoto(personIds); + if(ToolUtil.isNotEmpty(photoCheck)){ + return ResponseData.error(photoCheck); + } + else{ + // 上传数据 + String error = syncService.uploadPerson(personIds,deviceIds,personType); + if(ToolUtil.isNotEmpty(error)){ + return ResponseData.error(error); + } + } + return ResponseData.success(); + } + + @RequestMapping("/face/uploadAll") + @ResponseBody + public Object uploadAll(@RequestParam("deviceIds") List deviceIds){ + DataScope dataScope = permissionService.getCurrUserDataScope(); + + List staffPersonIds = personSupportService.listIdsByType(dataScope,FaceSyncConst.STAFF_PERSON_TYPE); + List visitorPersonIds = personSupportService.listIdsByType(dataScope,FaceSyncConst.VISITOR_PERSON_TYPE); + // 1.检查照片,分别检查员工、访客 + String staffPhotoCheck = syncService.checkPersonPhoto(staffPersonIds); + if(ToolUtil.isNotEmpty(staffPhotoCheck)){ + return ResponseData.error(staffPhotoCheck); + } + String visitorPhotoCheck = syncService.checkPersonPhoto(visitorPersonIds); + if(ToolUtil.isNotEmpty(visitorPhotoCheck)){ + return ResponseData.error(visitorPhotoCheck); + } + + // 2. 下发数据 + String staffError = syncService.uploadPerson(staffPersonIds,deviceIds,FaceSyncConst.STAFF_PERSON_TYPE); + if(ToolUtil.isNotEmpty(staffError)){ + return ResponseData.error(staffError); + } + String visitorError = syncService.uploadPerson(visitorPersonIds,deviceIds,FaceSyncConst.VISITOR_PERSON_TYPE); + if(ToolUtil.isNotEmpty(visitorError)){ + return ResponseData.error(visitorError); + } + + return ResponseData.success(); + } + + // 错误信息返回 + @RequestMapping("/subsrcibe/init") + @ResponseBody + public Object upload(@RequestParam("deviceIds") List deviceIds){ + String errorMsg = syncService.initSubscription(deviceIds); + if(ToolUtil.isNotEmpty(errorMsg)){ + return ResponseData.error(errorMsg); + } + return ResponseData.success(); + } + + + @RequestMapping(value = "/LAPI/V1.0/System/Event/Notification/PersonVerification", method = RequestMethod.POST) + @ResponseBody + public void verification(@RequestBody String recordNotification){ + logger.info(recordNotification); + RecordNotification record = JSONObject.parseObject(recordNotification,RecordNotification.class); + syncService.receiveRecord(record); + //return ResponseData.success(); + } + + +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FacePersonSyncMapper.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FacePersonSyncMapper.java new file mode 100644 index 0000000..af53702 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FacePersonSyncMapper.java @@ -0,0 +1,17 @@ +package com.casic.missiles.modular.system.dao; + +import com.casic.missiles.modular.system.model.FacePersonSync; +import com.baomidou.mybatisplus.mapper.BaseMapper; + +/** + *

+ * Mapper 接口 + *

+ * + * @author zyj123 + * @since 2020-07-24 + */ +public interface FacePersonSyncMapper extends BaseMapper { + + Long getMaxSyncId(); +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FaceSubscribeMapper.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FaceSubscribeMapper.java new file mode 100644 index 0000000..0c6374a --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FaceSubscribeMapper.java @@ -0,0 +1,16 @@ +package com.casic.missiles.modular.system.dao; + +import com.casic.missiles.modular.system.model.FaceSubscribe; +import com.baomidou.mybatisplus.mapper.BaseMapper; + +/** + *

+ * Mapper 接口 + *

+ * + * @author zyj123 + * @since 2020-07-25 + */ +public interface FaceSubscribeMapper extends BaseMapper { + +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FacePersonSyncMapper.xml b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FacePersonSyncMapper.xml new file mode 100644 index 0000000..ac46ad0 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FacePersonSyncMapper.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + PERSON_ID AS personId, SYNC_ID AS syncId + + + + + diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FaceSubscribeMapper.xml b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FaceSubscribeMapper.xml new file mode 100644 index 0000000..16024e2 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FaceSubscribeMapper.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + SUBSCRIBE_ID AS subscribeId, DEVICE_CODE AS deviceCode, UPDATE_TIME AS updateTime + + + diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FacePersonSync.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FacePersonSync.java new file mode 100644 index 0000000..7cdb821 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FacePersonSync.java @@ -0,0 +1,68 @@ +package com.casic.missiles.modular.system.model; + +import java.io.Serializable; + +import com.baomidou.mybatisplus.annotations.TableId; +import com.baomidou.mybatisplus.annotations.TableField; +import com.baomidou.mybatisplus.activerecord.Model; +import com.baomidou.mybatisplus.annotations.TableName; +import java.io.Serializable; + +/** + *

+ * + *

+ * + * @author zyj123 + * @since 2020-07-24 + */ +@TableName("face_person_sync") +public class FacePersonSync extends Model { + + private static final long serialVersionUID = 1L; + + /** + * 人员id + */ + @TableId("PERSON_ID") + private Long personId; + /** + * 人员同步id + */ + @TableField("SYNC_ID") + private Long syncId; + + public FacePersonSync(Long personId, Long syncId) { + this.personId = personId; + this.syncId = syncId; + } + + public Long getPersonId() { + return personId; + } + + public void setPersonId(Long personId) { + this.personId = personId; + } + + public Long getSyncId() { + return syncId; + } + + public void setSyncId(Long syncId) { + this.syncId = syncId; + } + + @Override + protected Serializable pkVal() { + return this.personId; + } + + @Override + public String toString() { + return "FacePersonSync{" + + "personId=" + personId + + ", syncId=" + syncId + + "}"; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FaceSubscribe.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FaceSubscribe.java new file mode 100644 index 0000000..ccc7792 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FaceSubscribe.java @@ -0,0 +1,79 @@ +package com.casic.missiles.modular.system.model; + +import java.io.Serializable; + +import java.util.Date; +import com.baomidou.mybatisplus.annotations.TableId; +import com.baomidou.mybatisplus.annotations.TableField; +import com.baomidou.mybatisplus.activerecord.Model; +import com.baomidou.mybatisplus.annotations.TableName; +import java.io.Serializable; + +/** + *

+ * + *

+ * + * @author zyj123 + * @since 2020-07-25 + */ +@TableName("face_subscribe") +public class FaceSubscribe extends Model { + + private static final long serialVersionUID = 1L; + + /** + * 订阅id + */ + @TableId("SUBSCRIBE_ID") + private Long subscribeId; + /** + * 设备编号 + */ + @TableField("DEVICE_CODE") + private String deviceCode; + /** + * 更新时间 + */ + @TableField("UPDATE_TIME") + private Date updateTime; + + + public Long getSubscribeId() { + return subscribeId; + } + + public void setSubscribeId(Long subscribeId) { + this.subscribeId = subscribeId; + } + + public String getDeviceCode() { + return deviceCode; + } + + public void setDeviceCode(String deviceCode) { + this.deviceCode = deviceCode; + } + + public Date getUpdateTime() { + return updateTime; + } + + public void setUpdateTime(Date updateTime) { + this.updateTime = updateTime; + } + + @Override + protected Serializable pkVal() { + return this.subscribeId; + } + + @Override + public String toString() { + return "FaceSubscribe{" + + "subscribeId=" + subscribeId + + ", deviceCode=" + deviceCode + + ", updateTime=" + updateTime + + "}"; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/request/PersonInfo.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/request/PersonInfo.java new file mode 100644 index 0000000..80d9eff --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/request/PersonInfo.java @@ -0,0 +1,271 @@ +package com.casic.missiles.modular.system.request; + +import com.alibaba.fastjson.annotation.JSONField; +import com.baomidou.mybatisplus.annotations.TableField; +import com.google.gson.annotations.SerializedName; + +import java.util.List; + +public class PersonInfo { + + //@JSONField(name = "PersonID") + @SerializedName("PersonID") + private Long personID; + + //@JSONField(name = "LastChange") + @SerializedName("LastChange") + private Long lastChange; + + //@JSONField(name = "PersonCode") + @SerializedName("PersonCode") + private String personCode; + + //@JSONField(name = "PersonName") + @SerializedName("PersonName") + private String personName; + + //@JSONField(name = "Remarks") + @SerializedName("Remarks") + private String remarks; + + //@JSONField(name = "TimeTemplateNum") + @SerializedName("TimeTemplateNum") + private Integer timeTemplateNum; + + //@JSONField(name = "TimeTemplateList") + @SerializedName("TimeTemplateList") + private List timeTemplateList; + + //@JSONField(name = "IdentificationNum") + @SerializedName("IdentificationNum") + private Integer identificationNum; + + //@JSONField(name = "IdentificationList") + @SerializedName("IdentificationList") + private List identificationList; + + //@JSONField(name = "ImageNum") + @SerializedName("ImageNum") + private Integer imageNum; + + //@JSONField(name = "ImageList") + @SerializedName("ImageList") + private List imageList; + + public Long getPersonID() { + return personID; + } + + public void setPersonID(Long personID) { + this.personID = personID; + } + + public Long getLastChange() { + return lastChange; + } + + public void setLastChange(Long lastChange) { + this.lastChange = lastChange; + } + + public String getPersonCode() { + return personCode; + } + + public void setPersonCode(String personCode) { + this.personCode = personCode; + } + + public String getPersonName() { + return personName; + } + + public void setPersonName(String personName) { + this.personName = personName; + } + + public String getRemarks() { + return remarks; + } + + public void setRemarks(String remarks) { + this.remarks = remarks; + } + + public Integer getTimeTemplateNum() { + return timeTemplateNum; + } + + public void setTimeTemplateNum(Integer timeTemplateNum) { + this.timeTemplateNum = timeTemplateNum; + } + + public List getTimeTemplateList() { + return timeTemplateList; + } + + public void setTimeTemplateList(List timeTemplateList) { + this.timeTemplateList = timeTemplateList; + } + + public Integer getIdentificationNum() { + return identificationNum; + } + + public void setIdentificationNum(Integer identificationNum) { + this.identificationNum = identificationNum; + } + + public List getIdentificationList() { + return identificationList; + } + + public void setIdentificationList(List identificationList) { + this.identificationList = identificationList; + } + + public Integer getImageNum() { + return imageNum; + } + + public void setImageNum(Integer imageNum) { + this.imageNum = imageNum; + } + + public List getImageList() { + return imageList; + } + + public void setImageList(List imageList) { + this.imageList = imageList; + } + + public class TimeTemplate{ + @JSONField(name = "BeginTime") + private Long beginTime; + @JSONField(name = "EndTime") + private Long endTime; + @JSONField(name = "Index") + private Long index; + + public TimeTemplate(Long beginTime, Long endTime, Long index) { + this.beginTime = beginTime; + this.endTime = endTime; + this.index = index; + } + + public Long getBeginTime() { + return beginTime; + } + + public void setBeginTime(Long beginTime) { + this.beginTime = beginTime; + } + + public Long getEndTime() { + return endTime; + } + + public void setEndTime(Long endTime) { + this.endTime = endTime; + } + + public Long getIndex() { + return index; + } + + public void setIndex(Long index) { + this.index = index; + } + } + + public TimeTemplate createTimeTemplate(Long beginTime, Long endTime, Long index){ + return new TimeTemplate(beginTime, endTime, index); + } + + public class IdentificationInfo { + @JSONField(name = "Type") + private Integer type; + @JSONField(name = "Number") + private String number; + + public IdentificationInfo(Integer type, String number) { + this.type = type; + this.number = number; + } + + public Integer getType() { + return type; + } + + public void setType(Integer type) { + this.type = type; + } + + public String getNumber() { + return number; + } + + public void setNumber(String number) { + this.number = number; + } + } + + public IdentificationInfo createIdentificationInfo(Integer type, String number){ + return new IdentificationInfo(type,number); + } + + public class ImageInfo{ + @JSONField(name = "FaceID") + private Long faceID; + @JSONField(name = "Name") + private String name; + @JSONField(name = "Size") + private Long size; + @JSONField(name = "Data") + private String data; + + public ImageInfo(Long faceID, String name, Long size, String data) { + this.faceID = faceID; + this.name = name; + this.size = size; + this.data = data; + } + + public Long getFaceID() { + return faceID; + } + + public void setFaceID(Long faceID) { + this.faceID = faceID; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Long getSize() { + return size; + } + + public void setSize(Long size) { + this.size = size; + } + + public String getData() { + return data; + } + + public void setData(String data) { + this.data = data; + } + } + + public ImageInfo createImageInfo(Long faceID, String name, Long size, String data){ + return new ImageInfo(faceID, name, size, data); + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceBaseResponse.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceBaseResponse.java new file mode 100644 index 0000000..fe93b8a --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceBaseResponse.java @@ -0,0 +1,90 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; +import com.google.gson.annotations.SerializedName; + +public class FaceBaseResponse { + @JSONField(name = "ResponseURL") + @SerializedName("ResponseURL") + private String responseUrl; + + @JSONField(name = "CreatedID") + @SerializedName("CreatedID") + private int createdId; + + @JSONField(name = "ResponseCode") + @SerializedName("ResponseCode") + private int responseCode; + + @JSONField(name = "ResponseString") + @SerializedName("ResponseString") + private String responseString; + + @JSONField(name = "StatusCode") + @SerializedName("StatusCode") + private int statusCode; + + @JSONField(name = "StatusString") + @SerializedName("StatusString") + private String statusString; + + //@JSONField(name = "Data") + @SerializedName("Data") + private T data; + + public String getResponseUrl() { + return responseUrl; + } + + public void setResponseUrl(String responseUrl) { + this.responseUrl = responseUrl; + } + + public int getCreatedId() { + return createdId; + } + + public void setCreatedId(int createdId) { + this.createdId = createdId; + } + + public int getResponseCode() { + return responseCode; + } + + public void setResponseCode(int responseCode) { + this.responseCode = responseCode; + } + + public String getResponseString() { + return responseString; + } + + public void setResponseString(String responseString) { + this.responseString = responseString; + } + + public int getStatusCode() { + return statusCode; + } + + public void setStatusCode(int statusCode) { + this.statusCode = statusCode; + } + + public String getStatusString() { + return statusString; + } + + public void setStatusString(String statusString) { + this.statusString = statusString; + } + + public T getData() { + return data; + } + + public void setData(T data) { + this.data = data; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceInfo.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceInfo.java new file mode 100644 index 0000000..f128c92 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceInfo.java @@ -0,0 +1,128 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; + +import java.util.List; + +public class FaceInfo { + @JSONField(name = "ID") + private Long id; + @JSONField(name = "Timestamp") + private Long timestamp; + @JSONField(name = "CapSrc") + private Long capSrc; + @JSONField(name = "FeatureNum") + private Long featureNum; + @JSONField(name = "FeatureList") + private List featureList; + @JSONField(name = "FeatureVersion") + private String featureVersion; + @JSONField(name = "Feature") + private String feature; + @JSONField(name = "Temperature") + private Float temperature; + @JSONField(name = "MaskFlag") + private Long maskFlag; + @JSONField(name = "PanoImage") + private Object panoImage; + @JSONField(name = "FaceImage") + private Object faceImage; + @JSONField(name = "FaceArea") + private Object faceArea; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Long getTimestamp() { + return timestamp; + } + + public void setTimestamp(Long timestamp) { + this.timestamp = timestamp; + } + + public Long getCapSrc() { + return capSrc; + } + + public void setCapSrc(Long capSrc) { + this.capSrc = capSrc; + } + + public Long getFeatureNum() { + return featureNum; + } + + public void setFeatureNum(Long featureNum) { + this.featureNum = featureNum; + } + + public List getFeatureList() { + return featureList; + } + + public void setFeatureList(List featureList) { + this.featureList = featureList; + } + + public String getFeatureVersion() { + return featureVersion; + } + + public void setFeatureVersion(String featureVersion) { + this.featureVersion = featureVersion; + } + + public String getFeature() { + return feature; + } + + public void setFeature(String feature) { + this.feature = feature; + } + + public Float getTemperature() { + return temperature; + } + + public void setTemperature(Float temperature) { + this.temperature = temperature; + } + + public Long getMaskFlag() { + return maskFlag; + } + + public void setMaskFlag(Long maskFlag) { + this.maskFlag = maskFlag; + } + + public Object getPanoImage() { + return panoImage; + } + + public void setPanoImage(Object panoImage) { + this.panoImage = panoImage; + } + + public Object getFaceImage() { + return faceImage; + } + + public void setFaceImage(Object faceImage) { + this.faceImage = faceImage; + } + + public Object getFaceArea() { + return faceArea; + } + + public void setFaceArea(Object faceArea) { + this.faceArea = faceArea; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/LibMatInfo.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/LibMatInfo.java new file mode 100644 index 0000000..ce6dd33 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/LibMatInfo.java @@ -0,0 +1,69 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; + +public class LibMatInfo { + @JSONField(name = "ID") + private Long id; + @JSONField(name = "LibID") + private Long libId; + @JSONField(name = "LibType") + private Long libType; + @JSONField(name = "MatchStatus") + private Long matchStatus; + @JSONField(name = "MatchPersonID") + private Long matchPersonId; + @JSONField(name = "MatchFaceID") + private Long matchFaceId; + + // MatchPersonInfo 暂时忽略不用 + + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Long getLibId() { + return libId; + } + + public void setLibId(Long libId) { + this.libId = libId; + } + + public Long getLibType() { + return libType; + } + + public void setLibType(Long libType) { + this.libType = libType; + } + + public Long getMatchStatus() { + return matchStatus; + } + + public void setMatchStatus(Long matchStatus) { + this.matchStatus = matchStatus; + } + + public Long getMatchPersonId() { + return matchPersonId; + } + + public void setMatchPersonId(Long matchPersonId) { + this.matchPersonId = matchPersonId; + } + + public Long getMatchFaceId() { + return matchFaceId; + } + + public void setMatchFaceId(Long matchFaceId) { + this.matchFaceId = matchFaceId; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/PersonResponseData.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/PersonResponseData.java new file mode 100644 index 0000000..186faed --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/PersonResponseData.java @@ -0,0 +1,31 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; +import com.google.gson.annotations.SerializedName; + +import java.util.List; + +public class PersonResponseData { + @JSONField(name = "Num") + @SerializedName("Num") + private int num; + @JSONField(name = "PersonList") + @SerializedName("PersonList") + private List personList; + + public int getNum() { + return num; + } + + public void setNum(int num) { + this.num = num; + } + + public List getPersonList() { + return personList; + } + + public void setPersonList(List personList) { + this.personList = personList; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/PersonResponseInfo.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/PersonResponseInfo.java new file mode 100644 index 0000000..7ba3edc --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/PersonResponseInfo.java @@ -0,0 +1,67 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; +import com.google.gson.annotations.SerializedName; + +import java.util.List; + +public class PersonResponseInfo { + @JSONField(name = "PersonID") + @SerializedName("PersonID") + private Long personId; + @JSONField(name = "FaceNum") + @SerializedName("FaceNum") + private Long faceNum; + @JSONField(name = "FaceList") + @SerializedName("FaceList") + private List faceList; + + public Long getPersonId() { + return personId; + } + + public void setPersonId(Long personId) { + this.personId = personId; + } + + public Long getFaceNum() { + return faceNum; + } + + public void setFaceNum(Long faceNum) { + this.faceNum = faceNum; + } + + public List getFaceList() { + return faceList; + } + + public void setFaceList(List faceList) { + this.faceList = faceList; + } + + public class PersonResponseFace{ + @JSONField(name = "FaceID") + @SerializedName("FaceID") + private Long faceId; + @JSONField(name = "ResultCode") + @SerializedName("ResultCode") + private Long resultCode; + + public Long getFaceId() { + return faceId; + } + + public void setFaceId(Long faceId) { + this.faceId = faceId; + } + + public Long getResultCode() { + return resultCode; + } + + public void setResultCode(Long resultCode) { + this.resultCode = resultCode; + } + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/RecordNotification.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/RecordNotification.java new file mode 100644 index 0000000..ca52d29 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/RecordNotification.java @@ -0,0 +1,138 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; + +import java.util.List; + +public class RecordNotification { + @JSONField(name = "Reference") + private String reference; + @JSONField(name = "Seq") + private int seq; + @JSONField(name = "DeviceCode") + private String deviceCode; + @JSONField(name = "Timestamp") + private Long timestamp; + @JSONField(name = "NotificationType") + private int notificationType; + @JSONField(name = "FaceInfoNum") + private int faceInfoNum; + @JSONField(name = "FaceInfoList") + private List faceInfoList; + @JSONField(name = "CardInfoNum") + private int cardInfoNum; + @JSONField(name = "CardInfoList") + private List cardInfoList; + @JSONField(name = "GateInfoNum") + private int gateInfoNum; + @JSONField(name = "GateInfoList") + private List gateInfoList; + @JSONField(name = "LibMatInfoNum") + private int libMatInfoNum; + @JSONField(name = "LibMatInfoList") + private List libMatInfoList; + + public String getReference() { + return reference; + } + + public void setReference(String reference) { + this.reference = reference; + } + + public int getSeq() { + return seq; + } + + public void setSeq(int seq) { + this.seq = seq; + } + + public String getDeviceCode() { + return deviceCode; + } + + public void setDeviceCode(String deviceCode) { + this.deviceCode = deviceCode; + } + + public Long getTimestamp() { + return timestamp; + } + + public void setTimestamp(Long timestamp) { + this.timestamp = timestamp; + } + + public int getNotificationType() { + return notificationType; + } + + public void setNotificationType(int notificationType) { + this.notificationType = notificationType; + } + + public int getFaceInfoNum() { + return faceInfoNum; + } + + public void setFaceInfoNum(int faceInfoNum) { + this.faceInfoNum = faceInfoNum; + } + + public List getFaceInfoList() { + return faceInfoList; + } + + public void setFaceInfoList(List faceInfoList) { + this.faceInfoList = faceInfoList; + } + + public int getCardInfoNum() { + return cardInfoNum; + } + + public void setCardInfoNum(int cardInfoNum) { + this.cardInfoNum = cardInfoNum; + } + + public List getCardInfoList() { + return cardInfoList; + } + + public void setCardInfoList(List cardInfoList) { + this.cardInfoList = cardInfoList; + } + + public int getGateInfoNum() { + return gateInfoNum; + } + + public void setGateInfoNum(int gateInfoNum) { + this.gateInfoNum = gateInfoNum; + } + + public List getGateInfoList() { + return gateInfoList; + } + + public void setGateInfoList(List gateInfoList) { + this.gateInfoList = gateInfoList; + } + + public int getLibMatInfoNum() { + return libMatInfoNum; + } + + public void setLibMatInfoNum(int libMatInfoNum) { + this.libMatInfoNum = libMatInfoNum; + } + + public List getLibMatInfoList() { + return libMatInfoList; + } + + public void setLibMatInfoList(List libMatInfoList) { + this.libMatInfoList = libMatInfoList; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/runner/InitSubscribeRunner.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/runner/InitSubscribeRunner.java new file mode 100644 index 0000000..c7d0565 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/runner/InitSubscribeRunner.java @@ -0,0 +1,43 @@ +package com.casic.missiles.modular.system.runner; + +import com.casic.missiles.modular.system.model.Device; +import com.casic.missiles.modular.system.service.IDeviceSupportService; +import com.casic.missiles.modular.system.service.IFaceSyncService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.ApplicationArguments; +import org.springframework.boot.ApplicationRunner; +import org.springframework.stereotype.Component; + +import java.util.ArrayList; +import java.util.List; + +@Component +public class InitSubscribeRunner implements ApplicationRunner { + private static Logger logger = LoggerFactory.getLogger(InitSubscribeRunner.class); + + @Value("${iris.face.initSubscribe}") + private String initSubscribe; + @Autowired + private IDeviceSupportService deviceSupportService; + @Autowired + private IFaceSyncService faceSyncService; + + /** + * 启动项目时,根据需要初始化设备订阅信息 + * @param applicationArguments + * @throws Exception + */ + @Override + public void run(ApplicationArguments applicationArguments) throws Exception { + logger.info("==================initSubscribe: "); + if(Boolean.valueOf(initSubscribe)){ + List deviceList = deviceSupportService.selectDeviceByType("5"); + List deviceIds = new ArrayList<>(); + deviceList.forEach(device -> deviceIds.add(Long.valueOf(device.getId()))); + faceSyncService.initSubscription(deviceIds); + } + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFacePersonSyncService.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFacePersonSyncService.java new file mode 100644 index 0000000..6b2461b --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFacePersonSyncService.java @@ -0,0 +1,18 @@ +package com.casic.missiles.modular.system.service; + +import com.casic.missiles.modular.system.model.FacePersonSync; +import com.baomidou.mybatisplus.service.IService; + +/** + *

+ * 服务类 + *

+ * + * @author zyj123 + * @since 2020-07-24 + */ +public interface IFacePersonSyncService extends IService { + Long selectSyncId(Long personId); + Long selectPersonId(Long syncId); + Long getMaxSyncId(Long personId); +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFaceSubscribeService.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFaceSubscribeService.java new file mode 100644 index 0000000..e0461ed --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFaceSubscribeService.java @@ -0,0 +1,24 @@ +package com.casic.missiles.modular.system.service; + +import com.casic.missiles.modular.system.model.FaceSubscribe; +import com.baomidou.mybatisplus.service.IService; + +import java.util.List; + +/** + *

+ * 服务类 + *

+ * + * @author zyj123 + * @since 2020-07-25 + */ +public interface IFaceSubscribeService extends IService { + + List selectSubscribeIdsByDevCode(String devCode); + + boolean deleteByDevCode(String devCode); + + boolean insertSubscribe(Long subscribeId, String devCode); + +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFaceSyncService.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFaceSyncService.java new file mode 100644 index 0000000..effd921 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFaceSyncService.java @@ -0,0 +1,21 @@ +package com.casic.missiles.modular.system.service; + +import com.casic.missiles.modular.system.response.RecordNotification; + +import java.util.List; + +public interface IFaceSyncService { + String uploadPerson(List personIds, List deviceIds,String personType); + + String checkPersonPhoto(List personIds); + + void receiveRecord(RecordNotification recordNotification); + + void receiveRecord(String recordNotificationStr); + + String initSubscription(List deviceIds); + + boolean deleteSubscription(String deviceIp, Long subscribeId); + + Long createSubscription(String deviceIp,String ip,String port); +} diff --git a/casic-face-sync/pom.xml b/casic-face-sync/pom.xml new file mode 100644 index 0000000..24dc884 --- /dev/null +++ b/casic-face-sync/pom.xml @@ -0,0 +1,74 @@ + + + 4.0.0 + + com.casic + casic-iris-parent + 1.0.0-SNAPSHOT + ../pom.xml + + + + casic-face-sync + ${pro.version} + jar + casic-face-sync + + + + + + com.casic + casic-core + ${core.version} + + + + com.casic + casic-admin-support + ${admin.version} + + + com.casic + casic-iris-support + ${pro.version} + + + + org.apache.httpcomponents + httpclient + 4.5.3 + + + + org.apache.httpcomponents + httpcore + 4.4.8 + + + + org.apache.httpcomponents + httpmime + 4.5.3 + + + + com.google.code.gson + gson + + + + + + + + src/main/java + + **/*.xml + + + + + \ No newline at end of file diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/constant/FaceSyncConst.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/constant/FaceSyncConst.java new file mode 100644 index 0000000..352d47d --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/constant/FaceSyncConst.java @@ -0,0 +1,29 @@ +package com.casic.missiles.modular.system.constant; + +public class FaceSyncConst { + + /** + * 单次最大批量上传人员数 + */ + public static final int UPLOAD_MAX_PERSON = 6; + + /** + * 上传人员库 + */ + public static final String UPLOAD_STAFF_LIB = "3"; + public static final String UPLOAD_VISITOR_LIB = "4"; + + public static final String UPLOAD_URL_PREFIX = "/LAPI/V1.0/PeopleLibraries/"; + + public static final String UPLOAD_URL_SUFFIX = "/People"; + + public static final int UPLOAD_PERSONCODE_MAXLENGTH = 15; + + public static final int UPLOAD_REMARK_MAXLENGTH = 63; + + public static final String SUBSCRIBE_URL = "/LAPI/V1.0/System/Event/Subscription/"; + + public static final String STAFF_PERSON_TYPE = "1"; + + public static final String VISITOR_PERSON_TYPE = "0"; +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/controller/FaceSyncController.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/controller/FaceSyncController.java new file mode 100644 index 0000000..1b35431 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/controller/FaceSyncController.java @@ -0,0 +1,117 @@ +package com.casic.missiles.modular.system.controller; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson.serializer.SerializerFeature; +import com.casic.missiles.core.base.response.ResponseData; +import com.casic.missiles.core.common.service.ICommonPermissionService; +import com.casic.missiles.core.common.service.ICommonPersonService; +import com.casic.missiles.core.datascope.DataScope; +import com.casic.missiles.core.util.ToolUtil; +import com.casic.missiles.modular.system.request.PersonInfo; +import com.casic.missiles.modular.system.response.RecordNotification; +import com.casic.missiles.modular.system.service.IFaceSyncService; +import com.casic.missiles.modular.system.service.IIrisPersonSupportService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.*; +import com.casic.missiles.modular.system.constant.FaceSyncConst; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + + + +@Controller +public class FaceSyncController { + private final static Logger logger = LoggerFactory.getLogger(FaceSyncController.class); + + @Autowired + private IFaceSyncService syncService; + @Autowired + private ICommonPersonService commonPersonService; + @Autowired + private IIrisPersonSupportService personSupportService; + @Autowired + private ICommonPermissionService permissionService; + + @RequestMapping("/face/upload") + @ResponseBody + public Object upload(@RequestParam("personIds") List personIds, + @RequestParam("deviceIds") List deviceIds, + @RequestParam("personType")String personType ){ + // 检查数量 +// if(personIds.size()>FaceSyncConst.UPLOAD_MAX_PERSON){ +// return ResponseData.error(String.format("每次最多上传%s个人",FaceSyncConst.UPLOAD_MAX_PERSON)); +// } + // 检查照片格式及大小 + String photoCheck = syncService.checkPersonPhoto(personIds); + if(ToolUtil.isNotEmpty(photoCheck)){ + return ResponseData.error(photoCheck); + } + else{ + // 上传数据 + String error = syncService.uploadPerson(personIds,deviceIds,personType); + if(ToolUtil.isNotEmpty(error)){ + return ResponseData.error(error); + } + } + return ResponseData.success(); + } + + @RequestMapping("/face/uploadAll") + @ResponseBody + public Object uploadAll(@RequestParam("deviceIds") List deviceIds){ + DataScope dataScope = permissionService.getCurrUserDataScope(); + + List staffPersonIds = personSupportService.listIdsByType(dataScope,FaceSyncConst.STAFF_PERSON_TYPE); + List visitorPersonIds = personSupportService.listIdsByType(dataScope,FaceSyncConst.VISITOR_PERSON_TYPE); + // 1.检查照片,分别检查员工、访客 + String staffPhotoCheck = syncService.checkPersonPhoto(staffPersonIds); + if(ToolUtil.isNotEmpty(staffPhotoCheck)){ + return ResponseData.error(staffPhotoCheck); + } + String visitorPhotoCheck = syncService.checkPersonPhoto(visitorPersonIds); + if(ToolUtil.isNotEmpty(visitorPhotoCheck)){ + return ResponseData.error(visitorPhotoCheck); + } + + // 2. 下发数据 + String staffError = syncService.uploadPerson(staffPersonIds,deviceIds,FaceSyncConst.STAFF_PERSON_TYPE); + if(ToolUtil.isNotEmpty(staffError)){ + return ResponseData.error(staffError); + } + String visitorError = syncService.uploadPerson(visitorPersonIds,deviceIds,FaceSyncConst.VISITOR_PERSON_TYPE); + if(ToolUtil.isNotEmpty(visitorError)){ + return ResponseData.error(visitorError); + } + + return ResponseData.success(); + } + + // 错误信息返回 + @RequestMapping("/subsrcibe/init") + @ResponseBody + public Object upload(@RequestParam("deviceIds") List deviceIds){ + String errorMsg = syncService.initSubscription(deviceIds); + if(ToolUtil.isNotEmpty(errorMsg)){ + return ResponseData.error(errorMsg); + } + return ResponseData.success(); + } + + + @RequestMapping(value = "/LAPI/V1.0/System/Event/Notification/PersonVerification", method = RequestMethod.POST) + @ResponseBody + public void verification(@RequestBody String recordNotification){ + logger.info(recordNotification); + RecordNotification record = JSONObject.parseObject(recordNotification,RecordNotification.class); + syncService.receiveRecord(record); + //return ResponseData.success(); + } + + +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FacePersonSyncMapper.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FacePersonSyncMapper.java new file mode 100644 index 0000000..af53702 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FacePersonSyncMapper.java @@ -0,0 +1,17 @@ +package com.casic.missiles.modular.system.dao; + +import com.casic.missiles.modular.system.model.FacePersonSync; +import com.baomidou.mybatisplus.mapper.BaseMapper; + +/** + *

+ * Mapper 接口 + *

+ * + * @author zyj123 + * @since 2020-07-24 + */ +public interface FacePersonSyncMapper extends BaseMapper { + + Long getMaxSyncId(); +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FaceSubscribeMapper.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FaceSubscribeMapper.java new file mode 100644 index 0000000..0c6374a --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FaceSubscribeMapper.java @@ -0,0 +1,16 @@ +package com.casic.missiles.modular.system.dao; + +import com.casic.missiles.modular.system.model.FaceSubscribe; +import com.baomidou.mybatisplus.mapper.BaseMapper; + +/** + *

+ * Mapper 接口 + *

+ * + * @author zyj123 + * @since 2020-07-25 + */ +public interface FaceSubscribeMapper extends BaseMapper { + +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FacePersonSyncMapper.xml b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FacePersonSyncMapper.xml new file mode 100644 index 0000000..ac46ad0 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FacePersonSyncMapper.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + PERSON_ID AS personId, SYNC_ID AS syncId + + + + + diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FaceSubscribeMapper.xml b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FaceSubscribeMapper.xml new file mode 100644 index 0000000..16024e2 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FaceSubscribeMapper.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + SUBSCRIBE_ID AS subscribeId, DEVICE_CODE AS deviceCode, UPDATE_TIME AS updateTime + + + diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FacePersonSync.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FacePersonSync.java new file mode 100644 index 0000000..7cdb821 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FacePersonSync.java @@ -0,0 +1,68 @@ +package com.casic.missiles.modular.system.model; + +import java.io.Serializable; + +import com.baomidou.mybatisplus.annotations.TableId; +import com.baomidou.mybatisplus.annotations.TableField; +import com.baomidou.mybatisplus.activerecord.Model; +import com.baomidou.mybatisplus.annotations.TableName; +import java.io.Serializable; + +/** + *

+ * + *

+ * + * @author zyj123 + * @since 2020-07-24 + */ +@TableName("face_person_sync") +public class FacePersonSync extends Model { + + private static final long serialVersionUID = 1L; + + /** + * 人员id + */ + @TableId("PERSON_ID") + private Long personId; + /** + * 人员同步id + */ + @TableField("SYNC_ID") + private Long syncId; + + public FacePersonSync(Long personId, Long syncId) { + this.personId = personId; + this.syncId = syncId; + } + + public Long getPersonId() { + return personId; + } + + public void setPersonId(Long personId) { + this.personId = personId; + } + + public Long getSyncId() { + return syncId; + } + + public void setSyncId(Long syncId) { + this.syncId = syncId; + } + + @Override + protected Serializable pkVal() { + return this.personId; + } + + @Override + public String toString() { + return "FacePersonSync{" + + "personId=" + personId + + ", syncId=" + syncId + + "}"; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FaceSubscribe.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FaceSubscribe.java new file mode 100644 index 0000000..ccc7792 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FaceSubscribe.java @@ -0,0 +1,79 @@ +package com.casic.missiles.modular.system.model; + +import java.io.Serializable; + +import java.util.Date; +import com.baomidou.mybatisplus.annotations.TableId; +import com.baomidou.mybatisplus.annotations.TableField; +import com.baomidou.mybatisplus.activerecord.Model; +import com.baomidou.mybatisplus.annotations.TableName; +import java.io.Serializable; + +/** + *

+ * + *

+ * + * @author zyj123 + * @since 2020-07-25 + */ +@TableName("face_subscribe") +public class FaceSubscribe extends Model { + + private static final long serialVersionUID = 1L; + + /** + * 订阅id + */ + @TableId("SUBSCRIBE_ID") + private Long subscribeId; + /** + * 设备编号 + */ + @TableField("DEVICE_CODE") + private String deviceCode; + /** + * 更新时间 + */ + @TableField("UPDATE_TIME") + private Date updateTime; + + + public Long getSubscribeId() { + return subscribeId; + } + + public void setSubscribeId(Long subscribeId) { + this.subscribeId = subscribeId; + } + + public String getDeviceCode() { + return deviceCode; + } + + public void setDeviceCode(String deviceCode) { + this.deviceCode = deviceCode; + } + + public Date getUpdateTime() { + return updateTime; + } + + public void setUpdateTime(Date updateTime) { + this.updateTime = updateTime; + } + + @Override + protected Serializable pkVal() { + return this.subscribeId; + } + + @Override + public String toString() { + return "FaceSubscribe{" + + "subscribeId=" + subscribeId + + ", deviceCode=" + deviceCode + + ", updateTime=" + updateTime + + "}"; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/request/PersonInfo.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/request/PersonInfo.java new file mode 100644 index 0000000..80d9eff --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/request/PersonInfo.java @@ -0,0 +1,271 @@ +package com.casic.missiles.modular.system.request; + +import com.alibaba.fastjson.annotation.JSONField; +import com.baomidou.mybatisplus.annotations.TableField; +import com.google.gson.annotations.SerializedName; + +import java.util.List; + +public class PersonInfo { + + //@JSONField(name = "PersonID") + @SerializedName("PersonID") + private Long personID; + + //@JSONField(name = "LastChange") + @SerializedName("LastChange") + private Long lastChange; + + //@JSONField(name = "PersonCode") + @SerializedName("PersonCode") + private String personCode; + + //@JSONField(name = "PersonName") + @SerializedName("PersonName") + private String personName; + + //@JSONField(name = "Remarks") + @SerializedName("Remarks") + private String remarks; + + //@JSONField(name = "TimeTemplateNum") + @SerializedName("TimeTemplateNum") + private Integer timeTemplateNum; + + //@JSONField(name = "TimeTemplateList") + @SerializedName("TimeTemplateList") + private List timeTemplateList; + + //@JSONField(name = "IdentificationNum") + @SerializedName("IdentificationNum") + private Integer identificationNum; + + //@JSONField(name = "IdentificationList") + @SerializedName("IdentificationList") + private List identificationList; + + //@JSONField(name = "ImageNum") + @SerializedName("ImageNum") + private Integer imageNum; + + //@JSONField(name = "ImageList") + @SerializedName("ImageList") + private List imageList; + + public Long getPersonID() { + return personID; + } + + public void setPersonID(Long personID) { + this.personID = personID; + } + + public Long getLastChange() { + return lastChange; + } + + public void setLastChange(Long lastChange) { + this.lastChange = lastChange; + } + + public String getPersonCode() { + return personCode; + } + + public void setPersonCode(String personCode) { + this.personCode = personCode; + } + + public String getPersonName() { + return personName; + } + + public void setPersonName(String personName) { + this.personName = personName; + } + + public String getRemarks() { + return remarks; + } + + public void setRemarks(String remarks) { + this.remarks = remarks; + } + + public Integer getTimeTemplateNum() { + return timeTemplateNum; + } + + public void setTimeTemplateNum(Integer timeTemplateNum) { + this.timeTemplateNum = timeTemplateNum; + } + + public List getTimeTemplateList() { + return timeTemplateList; + } + + public void setTimeTemplateList(List timeTemplateList) { + this.timeTemplateList = timeTemplateList; + } + + public Integer getIdentificationNum() { + return identificationNum; + } + + public void setIdentificationNum(Integer identificationNum) { + this.identificationNum = identificationNum; + } + + public List getIdentificationList() { + return identificationList; + } + + public void setIdentificationList(List identificationList) { + this.identificationList = identificationList; + } + + public Integer getImageNum() { + return imageNum; + } + + public void setImageNum(Integer imageNum) { + this.imageNum = imageNum; + } + + public List getImageList() { + return imageList; + } + + public void setImageList(List imageList) { + this.imageList = imageList; + } + + public class TimeTemplate{ + @JSONField(name = "BeginTime") + private Long beginTime; + @JSONField(name = "EndTime") + private Long endTime; + @JSONField(name = "Index") + private Long index; + + public TimeTemplate(Long beginTime, Long endTime, Long index) { + this.beginTime = beginTime; + this.endTime = endTime; + this.index = index; + } + + public Long getBeginTime() { + return beginTime; + } + + public void setBeginTime(Long beginTime) { + this.beginTime = beginTime; + } + + public Long getEndTime() { + return endTime; + } + + public void setEndTime(Long endTime) { + this.endTime = endTime; + } + + public Long getIndex() { + return index; + } + + public void setIndex(Long index) { + this.index = index; + } + } + + public TimeTemplate createTimeTemplate(Long beginTime, Long endTime, Long index){ + return new TimeTemplate(beginTime, endTime, index); + } + + public class IdentificationInfo { + @JSONField(name = "Type") + private Integer type; + @JSONField(name = "Number") + private String number; + + public IdentificationInfo(Integer type, String number) { + this.type = type; + this.number = number; + } + + public Integer getType() { + return type; + } + + public void setType(Integer type) { + this.type = type; + } + + public String getNumber() { + return number; + } + + public void setNumber(String number) { + this.number = number; + } + } + + public IdentificationInfo createIdentificationInfo(Integer type, String number){ + return new IdentificationInfo(type,number); + } + + public class ImageInfo{ + @JSONField(name = "FaceID") + private Long faceID; + @JSONField(name = "Name") + private String name; + @JSONField(name = "Size") + private Long size; + @JSONField(name = "Data") + private String data; + + public ImageInfo(Long faceID, String name, Long size, String data) { + this.faceID = faceID; + this.name = name; + this.size = size; + this.data = data; + } + + public Long getFaceID() { + return faceID; + } + + public void setFaceID(Long faceID) { + this.faceID = faceID; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Long getSize() { + return size; + } + + public void setSize(Long size) { + this.size = size; + } + + public String getData() { + return data; + } + + public void setData(String data) { + this.data = data; + } + } + + public ImageInfo createImageInfo(Long faceID, String name, Long size, String data){ + return new ImageInfo(faceID, name, size, data); + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceBaseResponse.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceBaseResponse.java new file mode 100644 index 0000000..fe93b8a --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceBaseResponse.java @@ -0,0 +1,90 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; +import com.google.gson.annotations.SerializedName; + +public class FaceBaseResponse { + @JSONField(name = "ResponseURL") + @SerializedName("ResponseURL") + private String responseUrl; + + @JSONField(name = "CreatedID") + @SerializedName("CreatedID") + private int createdId; + + @JSONField(name = "ResponseCode") + @SerializedName("ResponseCode") + private int responseCode; + + @JSONField(name = "ResponseString") + @SerializedName("ResponseString") + private String responseString; + + @JSONField(name = "StatusCode") + @SerializedName("StatusCode") + private int statusCode; + + @JSONField(name = "StatusString") + @SerializedName("StatusString") + private String statusString; + + //@JSONField(name = "Data") + @SerializedName("Data") + private T data; + + public String getResponseUrl() { + return responseUrl; + } + + public void setResponseUrl(String responseUrl) { + this.responseUrl = responseUrl; + } + + public int getCreatedId() { + return createdId; + } + + public void setCreatedId(int createdId) { + this.createdId = createdId; + } + + public int getResponseCode() { + return responseCode; + } + + public void setResponseCode(int responseCode) { + this.responseCode = responseCode; + } + + public String getResponseString() { + return responseString; + } + + public void setResponseString(String responseString) { + this.responseString = responseString; + } + + public int getStatusCode() { + return statusCode; + } + + public void setStatusCode(int statusCode) { + this.statusCode = statusCode; + } + + public String getStatusString() { + return statusString; + } + + public void setStatusString(String statusString) { + this.statusString = statusString; + } + + public T getData() { + return data; + } + + public void setData(T data) { + this.data = data; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceInfo.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceInfo.java new file mode 100644 index 0000000..f128c92 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceInfo.java @@ -0,0 +1,128 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; + +import java.util.List; + +public class FaceInfo { + @JSONField(name = "ID") + private Long id; + @JSONField(name = "Timestamp") + private Long timestamp; + @JSONField(name = "CapSrc") + private Long capSrc; + @JSONField(name = "FeatureNum") + private Long featureNum; + @JSONField(name = "FeatureList") + private List featureList; + @JSONField(name = "FeatureVersion") + private String featureVersion; + @JSONField(name = "Feature") + private String feature; + @JSONField(name = "Temperature") + private Float temperature; + @JSONField(name = "MaskFlag") + private Long maskFlag; + @JSONField(name = "PanoImage") + private Object panoImage; + @JSONField(name = "FaceImage") + private Object faceImage; + @JSONField(name = "FaceArea") + private Object faceArea; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Long getTimestamp() { + return timestamp; + } + + public void setTimestamp(Long timestamp) { + this.timestamp = timestamp; + } + + public Long getCapSrc() { + return capSrc; + } + + public void setCapSrc(Long capSrc) { + this.capSrc = capSrc; + } + + public Long getFeatureNum() { + return featureNum; + } + + public void setFeatureNum(Long featureNum) { + this.featureNum = featureNum; + } + + public List getFeatureList() { + return featureList; + } + + public void setFeatureList(List featureList) { + this.featureList = featureList; + } + + public String getFeatureVersion() { + return featureVersion; + } + + public void setFeatureVersion(String featureVersion) { + this.featureVersion = featureVersion; + } + + public String getFeature() { + return feature; + } + + public void setFeature(String feature) { + this.feature = feature; + } + + public Float getTemperature() { + return temperature; + } + + public void setTemperature(Float temperature) { + this.temperature = temperature; + } + + public Long getMaskFlag() { + return maskFlag; + } + + public void setMaskFlag(Long maskFlag) { + this.maskFlag = maskFlag; + } + + public Object getPanoImage() { + return panoImage; + } + + public void setPanoImage(Object panoImage) { + this.panoImage = panoImage; + } + + public Object getFaceImage() { + return faceImage; + } + + public void setFaceImage(Object faceImage) { + this.faceImage = faceImage; + } + + public Object getFaceArea() { + return faceArea; + } + + public void setFaceArea(Object faceArea) { + this.faceArea = faceArea; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/LibMatInfo.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/LibMatInfo.java new file mode 100644 index 0000000..ce6dd33 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/LibMatInfo.java @@ -0,0 +1,69 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; + +public class LibMatInfo { + @JSONField(name = "ID") + private Long id; + @JSONField(name = "LibID") + private Long libId; + @JSONField(name = "LibType") + private Long libType; + @JSONField(name = "MatchStatus") + private Long matchStatus; + @JSONField(name = "MatchPersonID") + private Long matchPersonId; + @JSONField(name = "MatchFaceID") + private Long matchFaceId; + + // MatchPersonInfo 暂时忽略不用 + + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Long getLibId() { + return libId; + } + + public void setLibId(Long libId) { + this.libId = libId; + } + + public Long getLibType() { + return libType; + } + + public void setLibType(Long libType) { + this.libType = libType; + } + + public Long getMatchStatus() { + return matchStatus; + } + + public void setMatchStatus(Long matchStatus) { + this.matchStatus = matchStatus; + } + + public Long getMatchPersonId() { + return matchPersonId; + } + + public void setMatchPersonId(Long matchPersonId) { + this.matchPersonId = matchPersonId; + } + + public Long getMatchFaceId() { + return matchFaceId; + } + + public void setMatchFaceId(Long matchFaceId) { + this.matchFaceId = matchFaceId; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/PersonResponseData.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/PersonResponseData.java new file mode 100644 index 0000000..186faed --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/PersonResponseData.java @@ -0,0 +1,31 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; +import com.google.gson.annotations.SerializedName; + +import java.util.List; + +public class PersonResponseData { + @JSONField(name = "Num") + @SerializedName("Num") + private int num; + @JSONField(name = "PersonList") + @SerializedName("PersonList") + private List personList; + + public int getNum() { + return num; + } + + public void setNum(int num) { + this.num = num; + } + + public List getPersonList() { + return personList; + } + + public void setPersonList(List personList) { + this.personList = personList; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/PersonResponseInfo.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/PersonResponseInfo.java new file mode 100644 index 0000000..7ba3edc --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/PersonResponseInfo.java @@ -0,0 +1,67 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; +import com.google.gson.annotations.SerializedName; + +import java.util.List; + +public class PersonResponseInfo { + @JSONField(name = "PersonID") + @SerializedName("PersonID") + private Long personId; + @JSONField(name = "FaceNum") + @SerializedName("FaceNum") + private Long faceNum; + @JSONField(name = "FaceList") + @SerializedName("FaceList") + private List faceList; + + public Long getPersonId() { + return personId; + } + + public void setPersonId(Long personId) { + this.personId = personId; + } + + public Long getFaceNum() { + return faceNum; + } + + public void setFaceNum(Long faceNum) { + this.faceNum = faceNum; + } + + public List getFaceList() { + return faceList; + } + + public void setFaceList(List faceList) { + this.faceList = faceList; + } + + public class PersonResponseFace{ + @JSONField(name = "FaceID") + @SerializedName("FaceID") + private Long faceId; + @JSONField(name = "ResultCode") + @SerializedName("ResultCode") + private Long resultCode; + + public Long getFaceId() { + return faceId; + } + + public void setFaceId(Long faceId) { + this.faceId = faceId; + } + + public Long getResultCode() { + return resultCode; + } + + public void setResultCode(Long resultCode) { + this.resultCode = resultCode; + } + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/RecordNotification.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/RecordNotification.java new file mode 100644 index 0000000..ca52d29 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/RecordNotification.java @@ -0,0 +1,138 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; + +import java.util.List; + +public class RecordNotification { + @JSONField(name = "Reference") + private String reference; + @JSONField(name = "Seq") + private int seq; + @JSONField(name = "DeviceCode") + private String deviceCode; + @JSONField(name = "Timestamp") + private Long timestamp; + @JSONField(name = "NotificationType") + private int notificationType; + @JSONField(name = "FaceInfoNum") + private int faceInfoNum; + @JSONField(name = "FaceInfoList") + private List faceInfoList; + @JSONField(name = "CardInfoNum") + private int cardInfoNum; + @JSONField(name = "CardInfoList") + private List cardInfoList; + @JSONField(name = "GateInfoNum") + private int gateInfoNum; + @JSONField(name = "GateInfoList") + private List gateInfoList; + @JSONField(name = "LibMatInfoNum") + private int libMatInfoNum; + @JSONField(name = "LibMatInfoList") + private List libMatInfoList; + + public String getReference() { + return reference; + } + + public void setReference(String reference) { + this.reference = reference; + } + + public int getSeq() { + return seq; + } + + public void setSeq(int seq) { + this.seq = seq; + } + + public String getDeviceCode() { + return deviceCode; + } + + public void setDeviceCode(String deviceCode) { + this.deviceCode = deviceCode; + } + + public Long getTimestamp() { + return timestamp; + } + + public void setTimestamp(Long timestamp) { + this.timestamp = timestamp; + } + + public int getNotificationType() { + return notificationType; + } + + public void setNotificationType(int notificationType) { + this.notificationType = notificationType; + } + + public int getFaceInfoNum() { + return faceInfoNum; + } + + public void setFaceInfoNum(int faceInfoNum) { + this.faceInfoNum = faceInfoNum; + } + + public List getFaceInfoList() { + return faceInfoList; + } + + public void setFaceInfoList(List faceInfoList) { + this.faceInfoList = faceInfoList; + } + + public int getCardInfoNum() { + return cardInfoNum; + } + + public void setCardInfoNum(int cardInfoNum) { + this.cardInfoNum = cardInfoNum; + } + + public List getCardInfoList() { + return cardInfoList; + } + + public void setCardInfoList(List cardInfoList) { + this.cardInfoList = cardInfoList; + } + + public int getGateInfoNum() { + return gateInfoNum; + } + + public void setGateInfoNum(int gateInfoNum) { + this.gateInfoNum = gateInfoNum; + } + + public List getGateInfoList() { + return gateInfoList; + } + + public void setGateInfoList(List gateInfoList) { + this.gateInfoList = gateInfoList; + } + + public int getLibMatInfoNum() { + return libMatInfoNum; + } + + public void setLibMatInfoNum(int libMatInfoNum) { + this.libMatInfoNum = libMatInfoNum; + } + + public List getLibMatInfoList() { + return libMatInfoList; + } + + public void setLibMatInfoList(List libMatInfoList) { + this.libMatInfoList = libMatInfoList; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/runner/InitSubscribeRunner.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/runner/InitSubscribeRunner.java new file mode 100644 index 0000000..c7d0565 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/runner/InitSubscribeRunner.java @@ -0,0 +1,43 @@ +package com.casic.missiles.modular.system.runner; + +import com.casic.missiles.modular.system.model.Device; +import com.casic.missiles.modular.system.service.IDeviceSupportService; +import com.casic.missiles.modular.system.service.IFaceSyncService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.ApplicationArguments; +import org.springframework.boot.ApplicationRunner; +import org.springframework.stereotype.Component; + +import java.util.ArrayList; +import java.util.List; + +@Component +public class InitSubscribeRunner implements ApplicationRunner { + private static Logger logger = LoggerFactory.getLogger(InitSubscribeRunner.class); + + @Value("${iris.face.initSubscribe}") + private String initSubscribe; + @Autowired + private IDeviceSupportService deviceSupportService; + @Autowired + private IFaceSyncService faceSyncService; + + /** + * 启动项目时,根据需要初始化设备订阅信息 + * @param applicationArguments + * @throws Exception + */ + @Override + public void run(ApplicationArguments applicationArguments) throws Exception { + logger.info("==================initSubscribe: "); + if(Boolean.valueOf(initSubscribe)){ + List deviceList = deviceSupportService.selectDeviceByType("5"); + List deviceIds = new ArrayList<>(); + deviceList.forEach(device -> deviceIds.add(Long.valueOf(device.getId()))); + faceSyncService.initSubscription(deviceIds); + } + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFacePersonSyncService.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFacePersonSyncService.java new file mode 100644 index 0000000..6b2461b --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFacePersonSyncService.java @@ -0,0 +1,18 @@ +package com.casic.missiles.modular.system.service; + +import com.casic.missiles.modular.system.model.FacePersonSync; +import com.baomidou.mybatisplus.service.IService; + +/** + *

+ * 服务类 + *

+ * + * @author zyj123 + * @since 2020-07-24 + */ +public interface IFacePersonSyncService extends IService { + Long selectSyncId(Long personId); + Long selectPersonId(Long syncId); + Long getMaxSyncId(Long personId); +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFaceSubscribeService.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFaceSubscribeService.java new file mode 100644 index 0000000..e0461ed --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFaceSubscribeService.java @@ -0,0 +1,24 @@ +package com.casic.missiles.modular.system.service; + +import com.casic.missiles.modular.system.model.FaceSubscribe; +import com.baomidou.mybatisplus.service.IService; + +import java.util.List; + +/** + *

+ * 服务类 + *

+ * + * @author zyj123 + * @since 2020-07-25 + */ +public interface IFaceSubscribeService extends IService { + + List selectSubscribeIdsByDevCode(String devCode); + + boolean deleteByDevCode(String devCode); + + boolean insertSubscribe(Long subscribeId, String devCode); + +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFaceSyncService.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFaceSyncService.java new file mode 100644 index 0000000..effd921 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFaceSyncService.java @@ -0,0 +1,21 @@ +package com.casic.missiles.modular.system.service; + +import com.casic.missiles.modular.system.response.RecordNotification; + +import java.util.List; + +public interface IFaceSyncService { + String uploadPerson(List personIds, List deviceIds,String personType); + + String checkPersonPhoto(List personIds); + + void receiveRecord(RecordNotification recordNotification); + + void receiveRecord(String recordNotificationStr); + + String initSubscription(List deviceIds); + + boolean deleteSubscription(String deviceIp, Long subscribeId); + + Long createSubscription(String deviceIp,String ip,String port); +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/Impl/FacePersonSyncServiceImpl.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/Impl/FacePersonSyncServiceImpl.java new file mode 100644 index 0000000..d1d1694 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/Impl/FacePersonSyncServiceImpl.java @@ -0,0 +1,55 @@ +package com.casic.missiles.modular.system.service.Impl; + +import com.baomidou.mybatisplus.mapper.EntityWrapper; +import com.casic.missiles.core.util.ToolUtil; +import com.casic.missiles.modular.system.model.FacePersonSync; +import com.casic.missiles.modular.system.dao.FacePersonSyncMapper; +import com.casic.missiles.modular.system.service.IFacePersonSyncService; +import com.baomidou.mybatisplus.service.impl.ServiceImpl; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +/** + *

+ * 服务实现类 + *

+ * + * @author zyj123 + * @since 2020-07-24 + */ +@Service +public class FacePersonSyncServiceImpl extends ServiceImpl implements IFacePersonSyncService { + + @Override + public Long selectSyncId(Long personId) { + FacePersonSync facePersonSync = this.selectById(personId); + if(ToolUtil.isNotEmpty(facePersonSync)){ + return facePersonSync.getSyncId(); + } + return null; + } + + @Override + public Long selectPersonId(Long syncId) { + EntityWrapper query = new EntityWrapper(); + query.eq("SYNC_ID",syncId); + FacePersonSync facePersonSync = this.selectOne(query); + if(ToolUtil.isNotEmpty(facePersonSync)){ + return facePersonSync.getPersonId(); + } + return null; + } + + @Override + @Transactional + public Long getMaxSyncId(Long personId) { + Long maxId = this.baseMapper.getMaxSyncId(); + if(ToolUtil.isEmpty(maxId)){ + maxId = 1000L; + }else { + maxId = maxId + 1; + } + this.insert(new FacePersonSync(personId,maxId)); + return maxId; + } +} diff --git a/casic-face-sync/pom.xml b/casic-face-sync/pom.xml new file mode 100644 index 0000000..24dc884 --- /dev/null +++ b/casic-face-sync/pom.xml @@ -0,0 +1,74 @@ + + + 4.0.0 + + com.casic + casic-iris-parent + 1.0.0-SNAPSHOT + ../pom.xml + + + + casic-face-sync + ${pro.version} + jar + casic-face-sync + + + + + + com.casic + casic-core + ${core.version} + + + + com.casic + casic-admin-support + ${admin.version} + + + com.casic + casic-iris-support + ${pro.version} + + + + org.apache.httpcomponents + httpclient + 4.5.3 + + + + org.apache.httpcomponents + httpcore + 4.4.8 + + + + org.apache.httpcomponents + httpmime + 4.5.3 + + + + com.google.code.gson + gson + + + + + + + + src/main/java + + **/*.xml + + + + + \ No newline at end of file diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/constant/FaceSyncConst.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/constant/FaceSyncConst.java new file mode 100644 index 0000000..352d47d --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/constant/FaceSyncConst.java @@ -0,0 +1,29 @@ +package com.casic.missiles.modular.system.constant; + +public class FaceSyncConst { + + /** + * 单次最大批量上传人员数 + */ + public static final int UPLOAD_MAX_PERSON = 6; + + /** + * 上传人员库 + */ + public static final String UPLOAD_STAFF_LIB = "3"; + public static final String UPLOAD_VISITOR_LIB = "4"; + + public static final String UPLOAD_URL_PREFIX = "/LAPI/V1.0/PeopleLibraries/"; + + public static final String UPLOAD_URL_SUFFIX = "/People"; + + public static final int UPLOAD_PERSONCODE_MAXLENGTH = 15; + + public static final int UPLOAD_REMARK_MAXLENGTH = 63; + + public static final String SUBSCRIBE_URL = "/LAPI/V1.0/System/Event/Subscription/"; + + public static final String STAFF_PERSON_TYPE = "1"; + + public static final String VISITOR_PERSON_TYPE = "0"; +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/controller/FaceSyncController.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/controller/FaceSyncController.java new file mode 100644 index 0000000..1b35431 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/controller/FaceSyncController.java @@ -0,0 +1,117 @@ +package com.casic.missiles.modular.system.controller; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson.serializer.SerializerFeature; +import com.casic.missiles.core.base.response.ResponseData; +import com.casic.missiles.core.common.service.ICommonPermissionService; +import com.casic.missiles.core.common.service.ICommonPersonService; +import com.casic.missiles.core.datascope.DataScope; +import com.casic.missiles.core.util.ToolUtil; +import com.casic.missiles.modular.system.request.PersonInfo; +import com.casic.missiles.modular.system.response.RecordNotification; +import com.casic.missiles.modular.system.service.IFaceSyncService; +import com.casic.missiles.modular.system.service.IIrisPersonSupportService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.*; +import com.casic.missiles.modular.system.constant.FaceSyncConst; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + + + +@Controller +public class FaceSyncController { + private final static Logger logger = LoggerFactory.getLogger(FaceSyncController.class); + + @Autowired + private IFaceSyncService syncService; + @Autowired + private ICommonPersonService commonPersonService; + @Autowired + private IIrisPersonSupportService personSupportService; + @Autowired + private ICommonPermissionService permissionService; + + @RequestMapping("/face/upload") + @ResponseBody + public Object upload(@RequestParam("personIds") List personIds, + @RequestParam("deviceIds") List deviceIds, + @RequestParam("personType")String personType ){ + // 检查数量 +// if(personIds.size()>FaceSyncConst.UPLOAD_MAX_PERSON){ +// return ResponseData.error(String.format("每次最多上传%s个人",FaceSyncConst.UPLOAD_MAX_PERSON)); +// } + // 检查照片格式及大小 + String photoCheck = syncService.checkPersonPhoto(personIds); + if(ToolUtil.isNotEmpty(photoCheck)){ + return ResponseData.error(photoCheck); + } + else{ + // 上传数据 + String error = syncService.uploadPerson(personIds,deviceIds,personType); + if(ToolUtil.isNotEmpty(error)){ + return ResponseData.error(error); + } + } + return ResponseData.success(); + } + + @RequestMapping("/face/uploadAll") + @ResponseBody + public Object uploadAll(@RequestParam("deviceIds") List deviceIds){ + DataScope dataScope = permissionService.getCurrUserDataScope(); + + List staffPersonIds = personSupportService.listIdsByType(dataScope,FaceSyncConst.STAFF_PERSON_TYPE); + List visitorPersonIds = personSupportService.listIdsByType(dataScope,FaceSyncConst.VISITOR_PERSON_TYPE); + // 1.检查照片,分别检查员工、访客 + String staffPhotoCheck = syncService.checkPersonPhoto(staffPersonIds); + if(ToolUtil.isNotEmpty(staffPhotoCheck)){ + return ResponseData.error(staffPhotoCheck); + } + String visitorPhotoCheck = syncService.checkPersonPhoto(visitorPersonIds); + if(ToolUtil.isNotEmpty(visitorPhotoCheck)){ + return ResponseData.error(visitorPhotoCheck); + } + + // 2. 下发数据 + String staffError = syncService.uploadPerson(staffPersonIds,deviceIds,FaceSyncConst.STAFF_PERSON_TYPE); + if(ToolUtil.isNotEmpty(staffError)){ + return ResponseData.error(staffError); + } + String visitorError = syncService.uploadPerson(visitorPersonIds,deviceIds,FaceSyncConst.VISITOR_PERSON_TYPE); + if(ToolUtil.isNotEmpty(visitorError)){ + return ResponseData.error(visitorError); + } + + return ResponseData.success(); + } + + // 错误信息返回 + @RequestMapping("/subsrcibe/init") + @ResponseBody + public Object upload(@RequestParam("deviceIds") List deviceIds){ + String errorMsg = syncService.initSubscription(deviceIds); + if(ToolUtil.isNotEmpty(errorMsg)){ + return ResponseData.error(errorMsg); + } + return ResponseData.success(); + } + + + @RequestMapping(value = "/LAPI/V1.0/System/Event/Notification/PersonVerification", method = RequestMethod.POST) + @ResponseBody + public void verification(@RequestBody String recordNotification){ + logger.info(recordNotification); + RecordNotification record = JSONObject.parseObject(recordNotification,RecordNotification.class); + syncService.receiveRecord(record); + //return ResponseData.success(); + } + + +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FacePersonSyncMapper.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FacePersonSyncMapper.java new file mode 100644 index 0000000..af53702 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FacePersonSyncMapper.java @@ -0,0 +1,17 @@ +package com.casic.missiles.modular.system.dao; + +import com.casic.missiles.modular.system.model.FacePersonSync; +import com.baomidou.mybatisplus.mapper.BaseMapper; + +/** + *

+ * Mapper 接口 + *

+ * + * @author zyj123 + * @since 2020-07-24 + */ +public interface FacePersonSyncMapper extends BaseMapper { + + Long getMaxSyncId(); +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FaceSubscribeMapper.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FaceSubscribeMapper.java new file mode 100644 index 0000000..0c6374a --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FaceSubscribeMapper.java @@ -0,0 +1,16 @@ +package com.casic.missiles.modular.system.dao; + +import com.casic.missiles.modular.system.model.FaceSubscribe; +import com.baomidou.mybatisplus.mapper.BaseMapper; + +/** + *

+ * Mapper 接口 + *

+ * + * @author zyj123 + * @since 2020-07-25 + */ +public interface FaceSubscribeMapper extends BaseMapper { + +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FacePersonSyncMapper.xml b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FacePersonSyncMapper.xml new file mode 100644 index 0000000..ac46ad0 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FacePersonSyncMapper.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + PERSON_ID AS personId, SYNC_ID AS syncId + + + + + diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FaceSubscribeMapper.xml b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FaceSubscribeMapper.xml new file mode 100644 index 0000000..16024e2 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FaceSubscribeMapper.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + SUBSCRIBE_ID AS subscribeId, DEVICE_CODE AS deviceCode, UPDATE_TIME AS updateTime + + + diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FacePersonSync.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FacePersonSync.java new file mode 100644 index 0000000..7cdb821 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FacePersonSync.java @@ -0,0 +1,68 @@ +package com.casic.missiles.modular.system.model; + +import java.io.Serializable; + +import com.baomidou.mybatisplus.annotations.TableId; +import com.baomidou.mybatisplus.annotations.TableField; +import com.baomidou.mybatisplus.activerecord.Model; +import com.baomidou.mybatisplus.annotations.TableName; +import java.io.Serializable; + +/** + *

+ * + *

+ * + * @author zyj123 + * @since 2020-07-24 + */ +@TableName("face_person_sync") +public class FacePersonSync extends Model { + + private static final long serialVersionUID = 1L; + + /** + * 人员id + */ + @TableId("PERSON_ID") + private Long personId; + /** + * 人员同步id + */ + @TableField("SYNC_ID") + private Long syncId; + + public FacePersonSync(Long personId, Long syncId) { + this.personId = personId; + this.syncId = syncId; + } + + public Long getPersonId() { + return personId; + } + + public void setPersonId(Long personId) { + this.personId = personId; + } + + public Long getSyncId() { + return syncId; + } + + public void setSyncId(Long syncId) { + this.syncId = syncId; + } + + @Override + protected Serializable pkVal() { + return this.personId; + } + + @Override + public String toString() { + return "FacePersonSync{" + + "personId=" + personId + + ", syncId=" + syncId + + "}"; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FaceSubscribe.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FaceSubscribe.java new file mode 100644 index 0000000..ccc7792 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FaceSubscribe.java @@ -0,0 +1,79 @@ +package com.casic.missiles.modular.system.model; + +import java.io.Serializable; + +import java.util.Date; +import com.baomidou.mybatisplus.annotations.TableId; +import com.baomidou.mybatisplus.annotations.TableField; +import com.baomidou.mybatisplus.activerecord.Model; +import com.baomidou.mybatisplus.annotations.TableName; +import java.io.Serializable; + +/** + *

+ * + *

+ * + * @author zyj123 + * @since 2020-07-25 + */ +@TableName("face_subscribe") +public class FaceSubscribe extends Model { + + private static final long serialVersionUID = 1L; + + /** + * 订阅id + */ + @TableId("SUBSCRIBE_ID") + private Long subscribeId; + /** + * 设备编号 + */ + @TableField("DEVICE_CODE") + private String deviceCode; + /** + * 更新时间 + */ + @TableField("UPDATE_TIME") + private Date updateTime; + + + public Long getSubscribeId() { + return subscribeId; + } + + public void setSubscribeId(Long subscribeId) { + this.subscribeId = subscribeId; + } + + public String getDeviceCode() { + return deviceCode; + } + + public void setDeviceCode(String deviceCode) { + this.deviceCode = deviceCode; + } + + public Date getUpdateTime() { + return updateTime; + } + + public void setUpdateTime(Date updateTime) { + this.updateTime = updateTime; + } + + @Override + protected Serializable pkVal() { + return this.subscribeId; + } + + @Override + public String toString() { + return "FaceSubscribe{" + + "subscribeId=" + subscribeId + + ", deviceCode=" + deviceCode + + ", updateTime=" + updateTime + + "}"; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/request/PersonInfo.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/request/PersonInfo.java new file mode 100644 index 0000000..80d9eff --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/request/PersonInfo.java @@ -0,0 +1,271 @@ +package com.casic.missiles.modular.system.request; + +import com.alibaba.fastjson.annotation.JSONField; +import com.baomidou.mybatisplus.annotations.TableField; +import com.google.gson.annotations.SerializedName; + +import java.util.List; + +public class PersonInfo { + + //@JSONField(name = "PersonID") + @SerializedName("PersonID") + private Long personID; + + //@JSONField(name = "LastChange") + @SerializedName("LastChange") + private Long lastChange; + + //@JSONField(name = "PersonCode") + @SerializedName("PersonCode") + private String personCode; + + //@JSONField(name = "PersonName") + @SerializedName("PersonName") + private String personName; + + //@JSONField(name = "Remarks") + @SerializedName("Remarks") + private String remarks; + + //@JSONField(name = "TimeTemplateNum") + @SerializedName("TimeTemplateNum") + private Integer timeTemplateNum; + + //@JSONField(name = "TimeTemplateList") + @SerializedName("TimeTemplateList") + private List timeTemplateList; + + //@JSONField(name = "IdentificationNum") + @SerializedName("IdentificationNum") + private Integer identificationNum; + + //@JSONField(name = "IdentificationList") + @SerializedName("IdentificationList") + private List identificationList; + + //@JSONField(name = "ImageNum") + @SerializedName("ImageNum") + private Integer imageNum; + + //@JSONField(name = "ImageList") + @SerializedName("ImageList") + private List imageList; + + public Long getPersonID() { + return personID; + } + + public void setPersonID(Long personID) { + this.personID = personID; + } + + public Long getLastChange() { + return lastChange; + } + + public void setLastChange(Long lastChange) { + this.lastChange = lastChange; + } + + public String getPersonCode() { + return personCode; + } + + public void setPersonCode(String personCode) { + this.personCode = personCode; + } + + public String getPersonName() { + return personName; + } + + public void setPersonName(String personName) { + this.personName = personName; + } + + public String getRemarks() { + return remarks; + } + + public void setRemarks(String remarks) { + this.remarks = remarks; + } + + public Integer getTimeTemplateNum() { + return timeTemplateNum; + } + + public void setTimeTemplateNum(Integer timeTemplateNum) { + this.timeTemplateNum = timeTemplateNum; + } + + public List getTimeTemplateList() { + return timeTemplateList; + } + + public void setTimeTemplateList(List timeTemplateList) { + this.timeTemplateList = timeTemplateList; + } + + public Integer getIdentificationNum() { + return identificationNum; + } + + public void setIdentificationNum(Integer identificationNum) { + this.identificationNum = identificationNum; + } + + public List getIdentificationList() { + return identificationList; + } + + public void setIdentificationList(List identificationList) { + this.identificationList = identificationList; + } + + public Integer getImageNum() { + return imageNum; + } + + public void setImageNum(Integer imageNum) { + this.imageNum = imageNum; + } + + public List getImageList() { + return imageList; + } + + public void setImageList(List imageList) { + this.imageList = imageList; + } + + public class TimeTemplate{ + @JSONField(name = "BeginTime") + private Long beginTime; + @JSONField(name = "EndTime") + private Long endTime; + @JSONField(name = "Index") + private Long index; + + public TimeTemplate(Long beginTime, Long endTime, Long index) { + this.beginTime = beginTime; + this.endTime = endTime; + this.index = index; + } + + public Long getBeginTime() { + return beginTime; + } + + public void setBeginTime(Long beginTime) { + this.beginTime = beginTime; + } + + public Long getEndTime() { + return endTime; + } + + public void setEndTime(Long endTime) { + this.endTime = endTime; + } + + public Long getIndex() { + return index; + } + + public void setIndex(Long index) { + this.index = index; + } + } + + public TimeTemplate createTimeTemplate(Long beginTime, Long endTime, Long index){ + return new TimeTemplate(beginTime, endTime, index); + } + + public class IdentificationInfo { + @JSONField(name = "Type") + private Integer type; + @JSONField(name = "Number") + private String number; + + public IdentificationInfo(Integer type, String number) { + this.type = type; + this.number = number; + } + + public Integer getType() { + return type; + } + + public void setType(Integer type) { + this.type = type; + } + + public String getNumber() { + return number; + } + + public void setNumber(String number) { + this.number = number; + } + } + + public IdentificationInfo createIdentificationInfo(Integer type, String number){ + return new IdentificationInfo(type,number); + } + + public class ImageInfo{ + @JSONField(name = "FaceID") + private Long faceID; + @JSONField(name = "Name") + private String name; + @JSONField(name = "Size") + private Long size; + @JSONField(name = "Data") + private String data; + + public ImageInfo(Long faceID, String name, Long size, String data) { + this.faceID = faceID; + this.name = name; + this.size = size; + this.data = data; + } + + public Long getFaceID() { + return faceID; + } + + public void setFaceID(Long faceID) { + this.faceID = faceID; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Long getSize() { + return size; + } + + public void setSize(Long size) { + this.size = size; + } + + public String getData() { + return data; + } + + public void setData(String data) { + this.data = data; + } + } + + public ImageInfo createImageInfo(Long faceID, String name, Long size, String data){ + return new ImageInfo(faceID, name, size, data); + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceBaseResponse.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceBaseResponse.java new file mode 100644 index 0000000..fe93b8a --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceBaseResponse.java @@ -0,0 +1,90 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; +import com.google.gson.annotations.SerializedName; + +public class FaceBaseResponse { + @JSONField(name = "ResponseURL") + @SerializedName("ResponseURL") + private String responseUrl; + + @JSONField(name = "CreatedID") + @SerializedName("CreatedID") + private int createdId; + + @JSONField(name = "ResponseCode") + @SerializedName("ResponseCode") + private int responseCode; + + @JSONField(name = "ResponseString") + @SerializedName("ResponseString") + private String responseString; + + @JSONField(name = "StatusCode") + @SerializedName("StatusCode") + private int statusCode; + + @JSONField(name = "StatusString") + @SerializedName("StatusString") + private String statusString; + + //@JSONField(name = "Data") + @SerializedName("Data") + private T data; + + public String getResponseUrl() { + return responseUrl; + } + + public void setResponseUrl(String responseUrl) { + this.responseUrl = responseUrl; + } + + public int getCreatedId() { + return createdId; + } + + public void setCreatedId(int createdId) { + this.createdId = createdId; + } + + public int getResponseCode() { + return responseCode; + } + + public void setResponseCode(int responseCode) { + this.responseCode = responseCode; + } + + public String getResponseString() { + return responseString; + } + + public void setResponseString(String responseString) { + this.responseString = responseString; + } + + public int getStatusCode() { + return statusCode; + } + + public void setStatusCode(int statusCode) { + this.statusCode = statusCode; + } + + public String getStatusString() { + return statusString; + } + + public void setStatusString(String statusString) { + this.statusString = statusString; + } + + public T getData() { + return data; + } + + public void setData(T data) { + this.data = data; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceInfo.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceInfo.java new file mode 100644 index 0000000..f128c92 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceInfo.java @@ -0,0 +1,128 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; + +import java.util.List; + +public class FaceInfo { + @JSONField(name = "ID") + private Long id; + @JSONField(name = "Timestamp") + private Long timestamp; + @JSONField(name = "CapSrc") + private Long capSrc; + @JSONField(name = "FeatureNum") + private Long featureNum; + @JSONField(name = "FeatureList") + private List featureList; + @JSONField(name = "FeatureVersion") + private String featureVersion; + @JSONField(name = "Feature") + private String feature; + @JSONField(name = "Temperature") + private Float temperature; + @JSONField(name = "MaskFlag") + private Long maskFlag; + @JSONField(name = "PanoImage") + private Object panoImage; + @JSONField(name = "FaceImage") + private Object faceImage; + @JSONField(name = "FaceArea") + private Object faceArea; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Long getTimestamp() { + return timestamp; + } + + public void setTimestamp(Long timestamp) { + this.timestamp = timestamp; + } + + public Long getCapSrc() { + return capSrc; + } + + public void setCapSrc(Long capSrc) { + this.capSrc = capSrc; + } + + public Long getFeatureNum() { + return featureNum; + } + + public void setFeatureNum(Long featureNum) { + this.featureNum = featureNum; + } + + public List getFeatureList() { + return featureList; + } + + public void setFeatureList(List featureList) { + this.featureList = featureList; + } + + public String getFeatureVersion() { + return featureVersion; + } + + public void setFeatureVersion(String featureVersion) { + this.featureVersion = featureVersion; + } + + public String getFeature() { + return feature; + } + + public void setFeature(String feature) { + this.feature = feature; + } + + public Float getTemperature() { + return temperature; + } + + public void setTemperature(Float temperature) { + this.temperature = temperature; + } + + public Long getMaskFlag() { + return maskFlag; + } + + public void setMaskFlag(Long maskFlag) { + this.maskFlag = maskFlag; + } + + public Object getPanoImage() { + return panoImage; + } + + public void setPanoImage(Object panoImage) { + this.panoImage = panoImage; + } + + public Object getFaceImage() { + return faceImage; + } + + public void setFaceImage(Object faceImage) { + this.faceImage = faceImage; + } + + public Object getFaceArea() { + return faceArea; + } + + public void setFaceArea(Object faceArea) { + this.faceArea = faceArea; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/LibMatInfo.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/LibMatInfo.java new file mode 100644 index 0000000..ce6dd33 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/LibMatInfo.java @@ -0,0 +1,69 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; + +public class LibMatInfo { + @JSONField(name = "ID") + private Long id; + @JSONField(name = "LibID") + private Long libId; + @JSONField(name = "LibType") + private Long libType; + @JSONField(name = "MatchStatus") + private Long matchStatus; + @JSONField(name = "MatchPersonID") + private Long matchPersonId; + @JSONField(name = "MatchFaceID") + private Long matchFaceId; + + // MatchPersonInfo 暂时忽略不用 + + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Long getLibId() { + return libId; + } + + public void setLibId(Long libId) { + this.libId = libId; + } + + public Long getLibType() { + return libType; + } + + public void setLibType(Long libType) { + this.libType = libType; + } + + public Long getMatchStatus() { + return matchStatus; + } + + public void setMatchStatus(Long matchStatus) { + this.matchStatus = matchStatus; + } + + public Long getMatchPersonId() { + return matchPersonId; + } + + public void setMatchPersonId(Long matchPersonId) { + this.matchPersonId = matchPersonId; + } + + public Long getMatchFaceId() { + return matchFaceId; + } + + public void setMatchFaceId(Long matchFaceId) { + this.matchFaceId = matchFaceId; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/PersonResponseData.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/PersonResponseData.java new file mode 100644 index 0000000..186faed --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/PersonResponseData.java @@ -0,0 +1,31 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; +import com.google.gson.annotations.SerializedName; + +import java.util.List; + +public class PersonResponseData { + @JSONField(name = "Num") + @SerializedName("Num") + private int num; + @JSONField(name = "PersonList") + @SerializedName("PersonList") + private List personList; + + public int getNum() { + return num; + } + + public void setNum(int num) { + this.num = num; + } + + public List getPersonList() { + return personList; + } + + public void setPersonList(List personList) { + this.personList = personList; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/PersonResponseInfo.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/PersonResponseInfo.java new file mode 100644 index 0000000..7ba3edc --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/PersonResponseInfo.java @@ -0,0 +1,67 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; +import com.google.gson.annotations.SerializedName; + +import java.util.List; + +public class PersonResponseInfo { + @JSONField(name = "PersonID") + @SerializedName("PersonID") + private Long personId; + @JSONField(name = "FaceNum") + @SerializedName("FaceNum") + private Long faceNum; + @JSONField(name = "FaceList") + @SerializedName("FaceList") + private List faceList; + + public Long getPersonId() { + return personId; + } + + public void setPersonId(Long personId) { + this.personId = personId; + } + + public Long getFaceNum() { + return faceNum; + } + + public void setFaceNum(Long faceNum) { + this.faceNum = faceNum; + } + + public List getFaceList() { + return faceList; + } + + public void setFaceList(List faceList) { + this.faceList = faceList; + } + + public class PersonResponseFace{ + @JSONField(name = "FaceID") + @SerializedName("FaceID") + private Long faceId; + @JSONField(name = "ResultCode") + @SerializedName("ResultCode") + private Long resultCode; + + public Long getFaceId() { + return faceId; + } + + public void setFaceId(Long faceId) { + this.faceId = faceId; + } + + public Long getResultCode() { + return resultCode; + } + + public void setResultCode(Long resultCode) { + this.resultCode = resultCode; + } + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/RecordNotification.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/RecordNotification.java new file mode 100644 index 0000000..ca52d29 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/RecordNotification.java @@ -0,0 +1,138 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; + +import java.util.List; + +public class RecordNotification { + @JSONField(name = "Reference") + private String reference; + @JSONField(name = "Seq") + private int seq; + @JSONField(name = "DeviceCode") + private String deviceCode; + @JSONField(name = "Timestamp") + private Long timestamp; + @JSONField(name = "NotificationType") + private int notificationType; + @JSONField(name = "FaceInfoNum") + private int faceInfoNum; + @JSONField(name = "FaceInfoList") + private List faceInfoList; + @JSONField(name = "CardInfoNum") + private int cardInfoNum; + @JSONField(name = "CardInfoList") + private List cardInfoList; + @JSONField(name = "GateInfoNum") + private int gateInfoNum; + @JSONField(name = "GateInfoList") + private List gateInfoList; + @JSONField(name = "LibMatInfoNum") + private int libMatInfoNum; + @JSONField(name = "LibMatInfoList") + private List libMatInfoList; + + public String getReference() { + return reference; + } + + public void setReference(String reference) { + this.reference = reference; + } + + public int getSeq() { + return seq; + } + + public void setSeq(int seq) { + this.seq = seq; + } + + public String getDeviceCode() { + return deviceCode; + } + + public void setDeviceCode(String deviceCode) { + this.deviceCode = deviceCode; + } + + public Long getTimestamp() { + return timestamp; + } + + public void setTimestamp(Long timestamp) { + this.timestamp = timestamp; + } + + public int getNotificationType() { + return notificationType; + } + + public void setNotificationType(int notificationType) { + this.notificationType = notificationType; + } + + public int getFaceInfoNum() { + return faceInfoNum; + } + + public void setFaceInfoNum(int faceInfoNum) { + this.faceInfoNum = faceInfoNum; + } + + public List getFaceInfoList() { + return faceInfoList; + } + + public void setFaceInfoList(List faceInfoList) { + this.faceInfoList = faceInfoList; + } + + public int getCardInfoNum() { + return cardInfoNum; + } + + public void setCardInfoNum(int cardInfoNum) { + this.cardInfoNum = cardInfoNum; + } + + public List getCardInfoList() { + return cardInfoList; + } + + public void setCardInfoList(List cardInfoList) { + this.cardInfoList = cardInfoList; + } + + public int getGateInfoNum() { + return gateInfoNum; + } + + public void setGateInfoNum(int gateInfoNum) { + this.gateInfoNum = gateInfoNum; + } + + public List getGateInfoList() { + return gateInfoList; + } + + public void setGateInfoList(List gateInfoList) { + this.gateInfoList = gateInfoList; + } + + public int getLibMatInfoNum() { + return libMatInfoNum; + } + + public void setLibMatInfoNum(int libMatInfoNum) { + this.libMatInfoNum = libMatInfoNum; + } + + public List getLibMatInfoList() { + return libMatInfoList; + } + + public void setLibMatInfoList(List libMatInfoList) { + this.libMatInfoList = libMatInfoList; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/runner/InitSubscribeRunner.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/runner/InitSubscribeRunner.java new file mode 100644 index 0000000..c7d0565 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/runner/InitSubscribeRunner.java @@ -0,0 +1,43 @@ +package com.casic.missiles.modular.system.runner; + +import com.casic.missiles.modular.system.model.Device; +import com.casic.missiles.modular.system.service.IDeviceSupportService; +import com.casic.missiles.modular.system.service.IFaceSyncService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.ApplicationArguments; +import org.springframework.boot.ApplicationRunner; +import org.springframework.stereotype.Component; + +import java.util.ArrayList; +import java.util.List; + +@Component +public class InitSubscribeRunner implements ApplicationRunner { + private static Logger logger = LoggerFactory.getLogger(InitSubscribeRunner.class); + + @Value("${iris.face.initSubscribe}") + private String initSubscribe; + @Autowired + private IDeviceSupportService deviceSupportService; + @Autowired + private IFaceSyncService faceSyncService; + + /** + * 启动项目时,根据需要初始化设备订阅信息 + * @param applicationArguments + * @throws Exception + */ + @Override + public void run(ApplicationArguments applicationArguments) throws Exception { + logger.info("==================initSubscribe: "); + if(Boolean.valueOf(initSubscribe)){ + List deviceList = deviceSupportService.selectDeviceByType("5"); + List deviceIds = new ArrayList<>(); + deviceList.forEach(device -> deviceIds.add(Long.valueOf(device.getId()))); + faceSyncService.initSubscription(deviceIds); + } + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFacePersonSyncService.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFacePersonSyncService.java new file mode 100644 index 0000000..6b2461b --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFacePersonSyncService.java @@ -0,0 +1,18 @@ +package com.casic.missiles.modular.system.service; + +import com.casic.missiles.modular.system.model.FacePersonSync; +import com.baomidou.mybatisplus.service.IService; + +/** + *

+ * 服务类 + *

+ * + * @author zyj123 + * @since 2020-07-24 + */ +public interface IFacePersonSyncService extends IService { + Long selectSyncId(Long personId); + Long selectPersonId(Long syncId); + Long getMaxSyncId(Long personId); +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFaceSubscribeService.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFaceSubscribeService.java new file mode 100644 index 0000000..e0461ed --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFaceSubscribeService.java @@ -0,0 +1,24 @@ +package com.casic.missiles.modular.system.service; + +import com.casic.missiles.modular.system.model.FaceSubscribe; +import com.baomidou.mybatisplus.service.IService; + +import java.util.List; + +/** + *

+ * 服务类 + *

+ * + * @author zyj123 + * @since 2020-07-25 + */ +public interface IFaceSubscribeService extends IService { + + List selectSubscribeIdsByDevCode(String devCode); + + boolean deleteByDevCode(String devCode); + + boolean insertSubscribe(Long subscribeId, String devCode); + +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFaceSyncService.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFaceSyncService.java new file mode 100644 index 0000000..effd921 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFaceSyncService.java @@ -0,0 +1,21 @@ +package com.casic.missiles.modular.system.service; + +import com.casic.missiles.modular.system.response.RecordNotification; + +import java.util.List; + +public interface IFaceSyncService { + String uploadPerson(List personIds, List deviceIds,String personType); + + String checkPersonPhoto(List personIds); + + void receiveRecord(RecordNotification recordNotification); + + void receiveRecord(String recordNotificationStr); + + String initSubscription(List deviceIds); + + boolean deleteSubscription(String deviceIp, Long subscribeId); + + Long createSubscription(String deviceIp,String ip,String port); +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/Impl/FacePersonSyncServiceImpl.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/Impl/FacePersonSyncServiceImpl.java new file mode 100644 index 0000000..d1d1694 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/Impl/FacePersonSyncServiceImpl.java @@ -0,0 +1,55 @@ +package com.casic.missiles.modular.system.service.Impl; + +import com.baomidou.mybatisplus.mapper.EntityWrapper; +import com.casic.missiles.core.util.ToolUtil; +import com.casic.missiles.modular.system.model.FacePersonSync; +import com.casic.missiles.modular.system.dao.FacePersonSyncMapper; +import com.casic.missiles.modular.system.service.IFacePersonSyncService; +import com.baomidou.mybatisplus.service.impl.ServiceImpl; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +/** + *

+ * 服务实现类 + *

+ * + * @author zyj123 + * @since 2020-07-24 + */ +@Service +public class FacePersonSyncServiceImpl extends ServiceImpl implements IFacePersonSyncService { + + @Override + public Long selectSyncId(Long personId) { + FacePersonSync facePersonSync = this.selectById(personId); + if(ToolUtil.isNotEmpty(facePersonSync)){ + return facePersonSync.getSyncId(); + } + return null; + } + + @Override + public Long selectPersonId(Long syncId) { + EntityWrapper query = new EntityWrapper(); + query.eq("SYNC_ID",syncId); + FacePersonSync facePersonSync = this.selectOne(query); + if(ToolUtil.isNotEmpty(facePersonSync)){ + return facePersonSync.getPersonId(); + } + return null; + } + + @Override + @Transactional + public Long getMaxSyncId(Long personId) { + Long maxId = this.baseMapper.getMaxSyncId(); + if(ToolUtil.isEmpty(maxId)){ + maxId = 1000L; + }else { + maxId = maxId + 1; + } + this.insert(new FacePersonSync(personId,maxId)); + return maxId; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/Impl/FaceSubscribeServiceImpl.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/Impl/FaceSubscribeServiceImpl.java new file mode 100644 index 0000000..c04302d --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/Impl/FaceSubscribeServiceImpl.java @@ -0,0 +1,52 @@ +package com.casic.missiles.modular.system.service.Impl; + +import com.baomidou.mybatisplus.mapper.EntityWrapper; +import com.casic.missiles.modular.system.model.FaceSubscribe; +import com.casic.missiles.modular.system.dao.FaceSubscribeMapper; +import com.casic.missiles.modular.system.service.IFaceSubscribeService; +import com.baomidou.mybatisplus.service.impl.ServiceImpl; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +/** + *

+ * 服务实现类 + *

+ * + * @author zyj123 + * @since 2020-07-25 + */ +@Service +public class FaceSubscribeServiceImpl extends ServiceImpl implements IFaceSubscribeService { + + @Override + public List selectSubscribeIdsByDevCode(String devCode) { + EntityWrapper query = new EntityWrapper(); + query.eq("DEVICE_CODE",devCode); + List faceSubscribes = this.selectList(query); + List subscribeIds = new ArrayList<>(); + for (FaceSubscribe faceSubscribe : faceSubscribes) { + subscribeIds.add(faceSubscribe.getSubscribeId()); + } + return subscribeIds; + } + + @Override + public boolean deleteByDevCode(String devCode) { + EntityWrapper query = new EntityWrapper(); + query.eq("DEVICE_CODE",devCode); + return this.delete(query); + } + + @Override + public boolean insertSubscribe(Long subscribeId, String devCode) { + FaceSubscribe faceSubscribe = new FaceSubscribe(); + faceSubscribe.setDeviceCode(devCode); + faceSubscribe.setSubscribeId(subscribeId); + faceSubscribe.setUpdateTime(new Date()); + return this.insert(faceSubscribe); + } +} diff --git a/casic-face-sync/pom.xml b/casic-face-sync/pom.xml new file mode 100644 index 0000000..24dc884 --- /dev/null +++ b/casic-face-sync/pom.xml @@ -0,0 +1,74 @@ + + + 4.0.0 + + com.casic + casic-iris-parent + 1.0.0-SNAPSHOT + ../pom.xml + + + + casic-face-sync + ${pro.version} + jar + casic-face-sync + + + + + + com.casic + casic-core + ${core.version} + + + + com.casic + casic-admin-support + ${admin.version} + + + com.casic + casic-iris-support + ${pro.version} + + + + org.apache.httpcomponents + httpclient + 4.5.3 + + + + org.apache.httpcomponents + httpcore + 4.4.8 + + + + org.apache.httpcomponents + httpmime + 4.5.3 + + + + com.google.code.gson + gson + + + + + + + + src/main/java + + **/*.xml + + + + + \ No newline at end of file diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/constant/FaceSyncConst.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/constant/FaceSyncConst.java new file mode 100644 index 0000000..352d47d --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/constant/FaceSyncConst.java @@ -0,0 +1,29 @@ +package com.casic.missiles.modular.system.constant; + +public class FaceSyncConst { + + /** + * 单次最大批量上传人员数 + */ + public static final int UPLOAD_MAX_PERSON = 6; + + /** + * 上传人员库 + */ + public static final String UPLOAD_STAFF_LIB = "3"; + public static final String UPLOAD_VISITOR_LIB = "4"; + + public static final String UPLOAD_URL_PREFIX = "/LAPI/V1.0/PeopleLibraries/"; + + public static final String UPLOAD_URL_SUFFIX = "/People"; + + public static final int UPLOAD_PERSONCODE_MAXLENGTH = 15; + + public static final int UPLOAD_REMARK_MAXLENGTH = 63; + + public static final String SUBSCRIBE_URL = "/LAPI/V1.0/System/Event/Subscription/"; + + public static final String STAFF_PERSON_TYPE = "1"; + + public static final String VISITOR_PERSON_TYPE = "0"; +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/controller/FaceSyncController.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/controller/FaceSyncController.java new file mode 100644 index 0000000..1b35431 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/controller/FaceSyncController.java @@ -0,0 +1,117 @@ +package com.casic.missiles.modular.system.controller; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson.serializer.SerializerFeature; +import com.casic.missiles.core.base.response.ResponseData; +import com.casic.missiles.core.common.service.ICommonPermissionService; +import com.casic.missiles.core.common.service.ICommonPersonService; +import com.casic.missiles.core.datascope.DataScope; +import com.casic.missiles.core.util.ToolUtil; +import com.casic.missiles.modular.system.request.PersonInfo; +import com.casic.missiles.modular.system.response.RecordNotification; +import com.casic.missiles.modular.system.service.IFaceSyncService; +import com.casic.missiles.modular.system.service.IIrisPersonSupportService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.*; +import com.casic.missiles.modular.system.constant.FaceSyncConst; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + + + +@Controller +public class FaceSyncController { + private final static Logger logger = LoggerFactory.getLogger(FaceSyncController.class); + + @Autowired + private IFaceSyncService syncService; + @Autowired + private ICommonPersonService commonPersonService; + @Autowired + private IIrisPersonSupportService personSupportService; + @Autowired + private ICommonPermissionService permissionService; + + @RequestMapping("/face/upload") + @ResponseBody + public Object upload(@RequestParam("personIds") List personIds, + @RequestParam("deviceIds") List deviceIds, + @RequestParam("personType")String personType ){ + // 检查数量 +// if(personIds.size()>FaceSyncConst.UPLOAD_MAX_PERSON){ +// return ResponseData.error(String.format("每次最多上传%s个人",FaceSyncConst.UPLOAD_MAX_PERSON)); +// } + // 检查照片格式及大小 + String photoCheck = syncService.checkPersonPhoto(personIds); + if(ToolUtil.isNotEmpty(photoCheck)){ + return ResponseData.error(photoCheck); + } + else{ + // 上传数据 + String error = syncService.uploadPerson(personIds,deviceIds,personType); + if(ToolUtil.isNotEmpty(error)){ + return ResponseData.error(error); + } + } + return ResponseData.success(); + } + + @RequestMapping("/face/uploadAll") + @ResponseBody + public Object uploadAll(@RequestParam("deviceIds") List deviceIds){ + DataScope dataScope = permissionService.getCurrUserDataScope(); + + List staffPersonIds = personSupportService.listIdsByType(dataScope,FaceSyncConst.STAFF_PERSON_TYPE); + List visitorPersonIds = personSupportService.listIdsByType(dataScope,FaceSyncConst.VISITOR_PERSON_TYPE); + // 1.检查照片,分别检查员工、访客 + String staffPhotoCheck = syncService.checkPersonPhoto(staffPersonIds); + if(ToolUtil.isNotEmpty(staffPhotoCheck)){ + return ResponseData.error(staffPhotoCheck); + } + String visitorPhotoCheck = syncService.checkPersonPhoto(visitorPersonIds); + if(ToolUtil.isNotEmpty(visitorPhotoCheck)){ + return ResponseData.error(visitorPhotoCheck); + } + + // 2. 下发数据 + String staffError = syncService.uploadPerson(staffPersonIds,deviceIds,FaceSyncConst.STAFF_PERSON_TYPE); + if(ToolUtil.isNotEmpty(staffError)){ + return ResponseData.error(staffError); + } + String visitorError = syncService.uploadPerson(visitorPersonIds,deviceIds,FaceSyncConst.VISITOR_PERSON_TYPE); + if(ToolUtil.isNotEmpty(visitorError)){ + return ResponseData.error(visitorError); + } + + return ResponseData.success(); + } + + // 错误信息返回 + @RequestMapping("/subsrcibe/init") + @ResponseBody + public Object upload(@RequestParam("deviceIds") List deviceIds){ + String errorMsg = syncService.initSubscription(deviceIds); + if(ToolUtil.isNotEmpty(errorMsg)){ + return ResponseData.error(errorMsg); + } + return ResponseData.success(); + } + + + @RequestMapping(value = "/LAPI/V1.0/System/Event/Notification/PersonVerification", method = RequestMethod.POST) + @ResponseBody + public void verification(@RequestBody String recordNotification){ + logger.info(recordNotification); + RecordNotification record = JSONObject.parseObject(recordNotification,RecordNotification.class); + syncService.receiveRecord(record); + //return ResponseData.success(); + } + + +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FacePersonSyncMapper.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FacePersonSyncMapper.java new file mode 100644 index 0000000..af53702 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FacePersonSyncMapper.java @@ -0,0 +1,17 @@ +package com.casic.missiles.modular.system.dao; + +import com.casic.missiles.modular.system.model.FacePersonSync; +import com.baomidou.mybatisplus.mapper.BaseMapper; + +/** + *

+ * Mapper 接口 + *

+ * + * @author zyj123 + * @since 2020-07-24 + */ +public interface FacePersonSyncMapper extends BaseMapper { + + Long getMaxSyncId(); +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FaceSubscribeMapper.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FaceSubscribeMapper.java new file mode 100644 index 0000000..0c6374a --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FaceSubscribeMapper.java @@ -0,0 +1,16 @@ +package com.casic.missiles.modular.system.dao; + +import com.casic.missiles.modular.system.model.FaceSubscribe; +import com.baomidou.mybatisplus.mapper.BaseMapper; + +/** + *

+ * Mapper 接口 + *

+ * + * @author zyj123 + * @since 2020-07-25 + */ +public interface FaceSubscribeMapper extends BaseMapper { + +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FacePersonSyncMapper.xml b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FacePersonSyncMapper.xml new file mode 100644 index 0000000..ac46ad0 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FacePersonSyncMapper.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + PERSON_ID AS personId, SYNC_ID AS syncId + + + + + diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FaceSubscribeMapper.xml b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FaceSubscribeMapper.xml new file mode 100644 index 0000000..16024e2 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FaceSubscribeMapper.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + SUBSCRIBE_ID AS subscribeId, DEVICE_CODE AS deviceCode, UPDATE_TIME AS updateTime + + + diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FacePersonSync.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FacePersonSync.java new file mode 100644 index 0000000..7cdb821 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FacePersonSync.java @@ -0,0 +1,68 @@ +package com.casic.missiles.modular.system.model; + +import java.io.Serializable; + +import com.baomidou.mybatisplus.annotations.TableId; +import com.baomidou.mybatisplus.annotations.TableField; +import com.baomidou.mybatisplus.activerecord.Model; +import com.baomidou.mybatisplus.annotations.TableName; +import java.io.Serializable; + +/** + *

+ * + *

+ * + * @author zyj123 + * @since 2020-07-24 + */ +@TableName("face_person_sync") +public class FacePersonSync extends Model { + + private static final long serialVersionUID = 1L; + + /** + * 人员id + */ + @TableId("PERSON_ID") + private Long personId; + /** + * 人员同步id + */ + @TableField("SYNC_ID") + private Long syncId; + + public FacePersonSync(Long personId, Long syncId) { + this.personId = personId; + this.syncId = syncId; + } + + public Long getPersonId() { + return personId; + } + + public void setPersonId(Long personId) { + this.personId = personId; + } + + public Long getSyncId() { + return syncId; + } + + public void setSyncId(Long syncId) { + this.syncId = syncId; + } + + @Override + protected Serializable pkVal() { + return this.personId; + } + + @Override + public String toString() { + return "FacePersonSync{" + + "personId=" + personId + + ", syncId=" + syncId + + "}"; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FaceSubscribe.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FaceSubscribe.java new file mode 100644 index 0000000..ccc7792 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FaceSubscribe.java @@ -0,0 +1,79 @@ +package com.casic.missiles.modular.system.model; + +import java.io.Serializable; + +import java.util.Date; +import com.baomidou.mybatisplus.annotations.TableId; +import com.baomidou.mybatisplus.annotations.TableField; +import com.baomidou.mybatisplus.activerecord.Model; +import com.baomidou.mybatisplus.annotations.TableName; +import java.io.Serializable; + +/** + *

+ * + *

+ * + * @author zyj123 + * @since 2020-07-25 + */ +@TableName("face_subscribe") +public class FaceSubscribe extends Model { + + private static final long serialVersionUID = 1L; + + /** + * 订阅id + */ + @TableId("SUBSCRIBE_ID") + private Long subscribeId; + /** + * 设备编号 + */ + @TableField("DEVICE_CODE") + private String deviceCode; + /** + * 更新时间 + */ + @TableField("UPDATE_TIME") + private Date updateTime; + + + public Long getSubscribeId() { + return subscribeId; + } + + public void setSubscribeId(Long subscribeId) { + this.subscribeId = subscribeId; + } + + public String getDeviceCode() { + return deviceCode; + } + + public void setDeviceCode(String deviceCode) { + this.deviceCode = deviceCode; + } + + public Date getUpdateTime() { + return updateTime; + } + + public void setUpdateTime(Date updateTime) { + this.updateTime = updateTime; + } + + @Override + protected Serializable pkVal() { + return this.subscribeId; + } + + @Override + public String toString() { + return "FaceSubscribe{" + + "subscribeId=" + subscribeId + + ", deviceCode=" + deviceCode + + ", updateTime=" + updateTime + + "}"; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/request/PersonInfo.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/request/PersonInfo.java new file mode 100644 index 0000000..80d9eff --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/request/PersonInfo.java @@ -0,0 +1,271 @@ +package com.casic.missiles.modular.system.request; + +import com.alibaba.fastjson.annotation.JSONField; +import com.baomidou.mybatisplus.annotations.TableField; +import com.google.gson.annotations.SerializedName; + +import java.util.List; + +public class PersonInfo { + + //@JSONField(name = "PersonID") + @SerializedName("PersonID") + private Long personID; + + //@JSONField(name = "LastChange") + @SerializedName("LastChange") + private Long lastChange; + + //@JSONField(name = "PersonCode") + @SerializedName("PersonCode") + private String personCode; + + //@JSONField(name = "PersonName") + @SerializedName("PersonName") + private String personName; + + //@JSONField(name = "Remarks") + @SerializedName("Remarks") + private String remarks; + + //@JSONField(name = "TimeTemplateNum") + @SerializedName("TimeTemplateNum") + private Integer timeTemplateNum; + + //@JSONField(name = "TimeTemplateList") + @SerializedName("TimeTemplateList") + private List timeTemplateList; + + //@JSONField(name = "IdentificationNum") + @SerializedName("IdentificationNum") + private Integer identificationNum; + + //@JSONField(name = "IdentificationList") + @SerializedName("IdentificationList") + private List identificationList; + + //@JSONField(name = "ImageNum") + @SerializedName("ImageNum") + private Integer imageNum; + + //@JSONField(name = "ImageList") + @SerializedName("ImageList") + private List imageList; + + public Long getPersonID() { + return personID; + } + + public void setPersonID(Long personID) { + this.personID = personID; + } + + public Long getLastChange() { + return lastChange; + } + + public void setLastChange(Long lastChange) { + this.lastChange = lastChange; + } + + public String getPersonCode() { + return personCode; + } + + public void setPersonCode(String personCode) { + this.personCode = personCode; + } + + public String getPersonName() { + return personName; + } + + public void setPersonName(String personName) { + this.personName = personName; + } + + public String getRemarks() { + return remarks; + } + + public void setRemarks(String remarks) { + this.remarks = remarks; + } + + public Integer getTimeTemplateNum() { + return timeTemplateNum; + } + + public void setTimeTemplateNum(Integer timeTemplateNum) { + this.timeTemplateNum = timeTemplateNum; + } + + public List getTimeTemplateList() { + return timeTemplateList; + } + + public void setTimeTemplateList(List timeTemplateList) { + this.timeTemplateList = timeTemplateList; + } + + public Integer getIdentificationNum() { + return identificationNum; + } + + public void setIdentificationNum(Integer identificationNum) { + this.identificationNum = identificationNum; + } + + public List getIdentificationList() { + return identificationList; + } + + public void setIdentificationList(List identificationList) { + this.identificationList = identificationList; + } + + public Integer getImageNum() { + return imageNum; + } + + public void setImageNum(Integer imageNum) { + this.imageNum = imageNum; + } + + public List getImageList() { + return imageList; + } + + public void setImageList(List imageList) { + this.imageList = imageList; + } + + public class TimeTemplate{ + @JSONField(name = "BeginTime") + private Long beginTime; + @JSONField(name = "EndTime") + private Long endTime; + @JSONField(name = "Index") + private Long index; + + public TimeTemplate(Long beginTime, Long endTime, Long index) { + this.beginTime = beginTime; + this.endTime = endTime; + this.index = index; + } + + public Long getBeginTime() { + return beginTime; + } + + public void setBeginTime(Long beginTime) { + this.beginTime = beginTime; + } + + public Long getEndTime() { + return endTime; + } + + public void setEndTime(Long endTime) { + this.endTime = endTime; + } + + public Long getIndex() { + return index; + } + + public void setIndex(Long index) { + this.index = index; + } + } + + public TimeTemplate createTimeTemplate(Long beginTime, Long endTime, Long index){ + return new TimeTemplate(beginTime, endTime, index); + } + + public class IdentificationInfo { + @JSONField(name = "Type") + private Integer type; + @JSONField(name = "Number") + private String number; + + public IdentificationInfo(Integer type, String number) { + this.type = type; + this.number = number; + } + + public Integer getType() { + return type; + } + + public void setType(Integer type) { + this.type = type; + } + + public String getNumber() { + return number; + } + + public void setNumber(String number) { + this.number = number; + } + } + + public IdentificationInfo createIdentificationInfo(Integer type, String number){ + return new IdentificationInfo(type,number); + } + + public class ImageInfo{ + @JSONField(name = "FaceID") + private Long faceID; + @JSONField(name = "Name") + private String name; + @JSONField(name = "Size") + private Long size; + @JSONField(name = "Data") + private String data; + + public ImageInfo(Long faceID, String name, Long size, String data) { + this.faceID = faceID; + this.name = name; + this.size = size; + this.data = data; + } + + public Long getFaceID() { + return faceID; + } + + public void setFaceID(Long faceID) { + this.faceID = faceID; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Long getSize() { + return size; + } + + public void setSize(Long size) { + this.size = size; + } + + public String getData() { + return data; + } + + public void setData(String data) { + this.data = data; + } + } + + public ImageInfo createImageInfo(Long faceID, String name, Long size, String data){ + return new ImageInfo(faceID, name, size, data); + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceBaseResponse.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceBaseResponse.java new file mode 100644 index 0000000..fe93b8a --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceBaseResponse.java @@ -0,0 +1,90 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; +import com.google.gson.annotations.SerializedName; + +public class FaceBaseResponse { + @JSONField(name = "ResponseURL") + @SerializedName("ResponseURL") + private String responseUrl; + + @JSONField(name = "CreatedID") + @SerializedName("CreatedID") + private int createdId; + + @JSONField(name = "ResponseCode") + @SerializedName("ResponseCode") + private int responseCode; + + @JSONField(name = "ResponseString") + @SerializedName("ResponseString") + private String responseString; + + @JSONField(name = "StatusCode") + @SerializedName("StatusCode") + private int statusCode; + + @JSONField(name = "StatusString") + @SerializedName("StatusString") + private String statusString; + + //@JSONField(name = "Data") + @SerializedName("Data") + private T data; + + public String getResponseUrl() { + return responseUrl; + } + + public void setResponseUrl(String responseUrl) { + this.responseUrl = responseUrl; + } + + public int getCreatedId() { + return createdId; + } + + public void setCreatedId(int createdId) { + this.createdId = createdId; + } + + public int getResponseCode() { + return responseCode; + } + + public void setResponseCode(int responseCode) { + this.responseCode = responseCode; + } + + public String getResponseString() { + return responseString; + } + + public void setResponseString(String responseString) { + this.responseString = responseString; + } + + public int getStatusCode() { + return statusCode; + } + + public void setStatusCode(int statusCode) { + this.statusCode = statusCode; + } + + public String getStatusString() { + return statusString; + } + + public void setStatusString(String statusString) { + this.statusString = statusString; + } + + public T getData() { + return data; + } + + public void setData(T data) { + this.data = data; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceInfo.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceInfo.java new file mode 100644 index 0000000..f128c92 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceInfo.java @@ -0,0 +1,128 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; + +import java.util.List; + +public class FaceInfo { + @JSONField(name = "ID") + private Long id; + @JSONField(name = "Timestamp") + private Long timestamp; + @JSONField(name = "CapSrc") + private Long capSrc; + @JSONField(name = "FeatureNum") + private Long featureNum; + @JSONField(name = "FeatureList") + private List featureList; + @JSONField(name = "FeatureVersion") + private String featureVersion; + @JSONField(name = "Feature") + private String feature; + @JSONField(name = "Temperature") + private Float temperature; + @JSONField(name = "MaskFlag") + private Long maskFlag; + @JSONField(name = "PanoImage") + private Object panoImage; + @JSONField(name = "FaceImage") + private Object faceImage; + @JSONField(name = "FaceArea") + private Object faceArea; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Long getTimestamp() { + return timestamp; + } + + public void setTimestamp(Long timestamp) { + this.timestamp = timestamp; + } + + public Long getCapSrc() { + return capSrc; + } + + public void setCapSrc(Long capSrc) { + this.capSrc = capSrc; + } + + public Long getFeatureNum() { + return featureNum; + } + + public void setFeatureNum(Long featureNum) { + this.featureNum = featureNum; + } + + public List getFeatureList() { + return featureList; + } + + public void setFeatureList(List featureList) { + this.featureList = featureList; + } + + public String getFeatureVersion() { + return featureVersion; + } + + public void setFeatureVersion(String featureVersion) { + this.featureVersion = featureVersion; + } + + public String getFeature() { + return feature; + } + + public void setFeature(String feature) { + this.feature = feature; + } + + public Float getTemperature() { + return temperature; + } + + public void setTemperature(Float temperature) { + this.temperature = temperature; + } + + public Long getMaskFlag() { + return maskFlag; + } + + public void setMaskFlag(Long maskFlag) { + this.maskFlag = maskFlag; + } + + public Object getPanoImage() { + return panoImage; + } + + public void setPanoImage(Object panoImage) { + this.panoImage = panoImage; + } + + public Object getFaceImage() { + return faceImage; + } + + public void setFaceImage(Object faceImage) { + this.faceImage = faceImage; + } + + public Object getFaceArea() { + return faceArea; + } + + public void setFaceArea(Object faceArea) { + this.faceArea = faceArea; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/LibMatInfo.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/LibMatInfo.java new file mode 100644 index 0000000..ce6dd33 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/LibMatInfo.java @@ -0,0 +1,69 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; + +public class LibMatInfo { + @JSONField(name = "ID") + private Long id; + @JSONField(name = "LibID") + private Long libId; + @JSONField(name = "LibType") + private Long libType; + @JSONField(name = "MatchStatus") + private Long matchStatus; + @JSONField(name = "MatchPersonID") + private Long matchPersonId; + @JSONField(name = "MatchFaceID") + private Long matchFaceId; + + // MatchPersonInfo 暂时忽略不用 + + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Long getLibId() { + return libId; + } + + public void setLibId(Long libId) { + this.libId = libId; + } + + public Long getLibType() { + return libType; + } + + public void setLibType(Long libType) { + this.libType = libType; + } + + public Long getMatchStatus() { + return matchStatus; + } + + public void setMatchStatus(Long matchStatus) { + this.matchStatus = matchStatus; + } + + public Long getMatchPersonId() { + return matchPersonId; + } + + public void setMatchPersonId(Long matchPersonId) { + this.matchPersonId = matchPersonId; + } + + public Long getMatchFaceId() { + return matchFaceId; + } + + public void setMatchFaceId(Long matchFaceId) { + this.matchFaceId = matchFaceId; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/PersonResponseData.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/PersonResponseData.java new file mode 100644 index 0000000..186faed --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/PersonResponseData.java @@ -0,0 +1,31 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; +import com.google.gson.annotations.SerializedName; + +import java.util.List; + +public class PersonResponseData { + @JSONField(name = "Num") + @SerializedName("Num") + private int num; + @JSONField(name = "PersonList") + @SerializedName("PersonList") + private List personList; + + public int getNum() { + return num; + } + + public void setNum(int num) { + this.num = num; + } + + public List getPersonList() { + return personList; + } + + public void setPersonList(List personList) { + this.personList = personList; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/PersonResponseInfo.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/PersonResponseInfo.java new file mode 100644 index 0000000..7ba3edc --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/PersonResponseInfo.java @@ -0,0 +1,67 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; +import com.google.gson.annotations.SerializedName; + +import java.util.List; + +public class PersonResponseInfo { + @JSONField(name = "PersonID") + @SerializedName("PersonID") + private Long personId; + @JSONField(name = "FaceNum") + @SerializedName("FaceNum") + private Long faceNum; + @JSONField(name = "FaceList") + @SerializedName("FaceList") + private List faceList; + + public Long getPersonId() { + return personId; + } + + public void setPersonId(Long personId) { + this.personId = personId; + } + + public Long getFaceNum() { + return faceNum; + } + + public void setFaceNum(Long faceNum) { + this.faceNum = faceNum; + } + + public List getFaceList() { + return faceList; + } + + public void setFaceList(List faceList) { + this.faceList = faceList; + } + + public class PersonResponseFace{ + @JSONField(name = "FaceID") + @SerializedName("FaceID") + private Long faceId; + @JSONField(name = "ResultCode") + @SerializedName("ResultCode") + private Long resultCode; + + public Long getFaceId() { + return faceId; + } + + public void setFaceId(Long faceId) { + this.faceId = faceId; + } + + public Long getResultCode() { + return resultCode; + } + + public void setResultCode(Long resultCode) { + this.resultCode = resultCode; + } + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/RecordNotification.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/RecordNotification.java new file mode 100644 index 0000000..ca52d29 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/RecordNotification.java @@ -0,0 +1,138 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; + +import java.util.List; + +public class RecordNotification { + @JSONField(name = "Reference") + private String reference; + @JSONField(name = "Seq") + private int seq; + @JSONField(name = "DeviceCode") + private String deviceCode; + @JSONField(name = "Timestamp") + private Long timestamp; + @JSONField(name = "NotificationType") + private int notificationType; + @JSONField(name = "FaceInfoNum") + private int faceInfoNum; + @JSONField(name = "FaceInfoList") + private List faceInfoList; + @JSONField(name = "CardInfoNum") + private int cardInfoNum; + @JSONField(name = "CardInfoList") + private List cardInfoList; + @JSONField(name = "GateInfoNum") + private int gateInfoNum; + @JSONField(name = "GateInfoList") + private List gateInfoList; + @JSONField(name = "LibMatInfoNum") + private int libMatInfoNum; + @JSONField(name = "LibMatInfoList") + private List libMatInfoList; + + public String getReference() { + return reference; + } + + public void setReference(String reference) { + this.reference = reference; + } + + public int getSeq() { + return seq; + } + + public void setSeq(int seq) { + this.seq = seq; + } + + public String getDeviceCode() { + return deviceCode; + } + + public void setDeviceCode(String deviceCode) { + this.deviceCode = deviceCode; + } + + public Long getTimestamp() { + return timestamp; + } + + public void setTimestamp(Long timestamp) { + this.timestamp = timestamp; + } + + public int getNotificationType() { + return notificationType; + } + + public void setNotificationType(int notificationType) { + this.notificationType = notificationType; + } + + public int getFaceInfoNum() { + return faceInfoNum; + } + + public void setFaceInfoNum(int faceInfoNum) { + this.faceInfoNum = faceInfoNum; + } + + public List getFaceInfoList() { + return faceInfoList; + } + + public void setFaceInfoList(List faceInfoList) { + this.faceInfoList = faceInfoList; + } + + public int getCardInfoNum() { + return cardInfoNum; + } + + public void setCardInfoNum(int cardInfoNum) { + this.cardInfoNum = cardInfoNum; + } + + public List getCardInfoList() { + return cardInfoList; + } + + public void setCardInfoList(List cardInfoList) { + this.cardInfoList = cardInfoList; + } + + public int getGateInfoNum() { + return gateInfoNum; + } + + public void setGateInfoNum(int gateInfoNum) { + this.gateInfoNum = gateInfoNum; + } + + public List getGateInfoList() { + return gateInfoList; + } + + public void setGateInfoList(List gateInfoList) { + this.gateInfoList = gateInfoList; + } + + public int getLibMatInfoNum() { + return libMatInfoNum; + } + + public void setLibMatInfoNum(int libMatInfoNum) { + this.libMatInfoNum = libMatInfoNum; + } + + public List getLibMatInfoList() { + return libMatInfoList; + } + + public void setLibMatInfoList(List libMatInfoList) { + this.libMatInfoList = libMatInfoList; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/runner/InitSubscribeRunner.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/runner/InitSubscribeRunner.java new file mode 100644 index 0000000..c7d0565 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/runner/InitSubscribeRunner.java @@ -0,0 +1,43 @@ +package com.casic.missiles.modular.system.runner; + +import com.casic.missiles.modular.system.model.Device; +import com.casic.missiles.modular.system.service.IDeviceSupportService; +import com.casic.missiles.modular.system.service.IFaceSyncService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.ApplicationArguments; +import org.springframework.boot.ApplicationRunner; +import org.springframework.stereotype.Component; + +import java.util.ArrayList; +import java.util.List; + +@Component +public class InitSubscribeRunner implements ApplicationRunner { + private static Logger logger = LoggerFactory.getLogger(InitSubscribeRunner.class); + + @Value("${iris.face.initSubscribe}") + private String initSubscribe; + @Autowired + private IDeviceSupportService deviceSupportService; + @Autowired + private IFaceSyncService faceSyncService; + + /** + * 启动项目时,根据需要初始化设备订阅信息 + * @param applicationArguments + * @throws Exception + */ + @Override + public void run(ApplicationArguments applicationArguments) throws Exception { + logger.info("==================initSubscribe: "); + if(Boolean.valueOf(initSubscribe)){ + List deviceList = deviceSupportService.selectDeviceByType("5"); + List deviceIds = new ArrayList<>(); + deviceList.forEach(device -> deviceIds.add(Long.valueOf(device.getId()))); + faceSyncService.initSubscription(deviceIds); + } + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFacePersonSyncService.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFacePersonSyncService.java new file mode 100644 index 0000000..6b2461b --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFacePersonSyncService.java @@ -0,0 +1,18 @@ +package com.casic.missiles.modular.system.service; + +import com.casic.missiles.modular.system.model.FacePersonSync; +import com.baomidou.mybatisplus.service.IService; + +/** + *

+ * 服务类 + *

+ * + * @author zyj123 + * @since 2020-07-24 + */ +public interface IFacePersonSyncService extends IService { + Long selectSyncId(Long personId); + Long selectPersonId(Long syncId); + Long getMaxSyncId(Long personId); +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFaceSubscribeService.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFaceSubscribeService.java new file mode 100644 index 0000000..e0461ed --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFaceSubscribeService.java @@ -0,0 +1,24 @@ +package com.casic.missiles.modular.system.service; + +import com.casic.missiles.modular.system.model.FaceSubscribe; +import com.baomidou.mybatisplus.service.IService; + +import java.util.List; + +/** + *

+ * 服务类 + *

+ * + * @author zyj123 + * @since 2020-07-25 + */ +public interface IFaceSubscribeService extends IService { + + List selectSubscribeIdsByDevCode(String devCode); + + boolean deleteByDevCode(String devCode); + + boolean insertSubscribe(Long subscribeId, String devCode); + +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFaceSyncService.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFaceSyncService.java new file mode 100644 index 0000000..effd921 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFaceSyncService.java @@ -0,0 +1,21 @@ +package com.casic.missiles.modular.system.service; + +import com.casic.missiles.modular.system.response.RecordNotification; + +import java.util.List; + +public interface IFaceSyncService { + String uploadPerson(List personIds, List deviceIds,String personType); + + String checkPersonPhoto(List personIds); + + void receiveRecord(RecordNotification recordNotification); + + void receiveRecord(String recordNotificationStr); + + String initSubscription(List deviceIds); + + boolean deleteSubscription(String deviceIp, Long subscribeId); + + Long createSubscription(String deviceIp,String ip,String port); +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/Impl/FacePersonSyncServiceImpl.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/Impl/FacePersonSyncServiceImpl.java new file mode 100644 index 0000000..d1d1694 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/Impl/FacePersonSyncServiceImpl.java @@ -0,0 +1,55 @@ +package com.casic.missiles.modular.system.service.Impl; + +import com.baomidou.mybatisplus.mapper.EntityWrapper; +import com.casic.missiles.core.util.ToolUtil; +import com.casic.missiles.modular.system.model.FacePersonSync; +import com.casic.missiles.modular.system.dao.FacePersonSyncMapper; +import com.casic.missiles.modular.system.service.IFacePersonSyncService; +import com.baomidou.mybatisplus.service.impl.ServiceImpl; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +/** + *

+ * 服务实现类 + *

+ * + * @author zyj123 + * @since 2020-07-24 + */ +@Service +public class FacePersonSyncServiceImpl extends ServiceImpl implements IFacePersonSyncService { + + @Override + public Long selectSyncId(Long personId) { + FacePersonSync facePersonSync = this.selectById(personId); + if(ToolUtil.isNotEmpty(facePersonSync)){ + return facePersonSync.getSyncId(); + } + return null; + } + + @Override + public Long selectPersonId(Long syncId) { + EntityWrapper query = new EntityWrapper(); + query.eq("SYNC_ID",syncId); + FacePersonSync facePersonSync = this.selectOne(query); + if(ToolUtil.isNotEmpty(facePersonSync)){ + return facePersonSync.getPersonId(); + } + return null; + } + + @Override + @Transactional + public Long getMaxSyncId(Long personId) { + Long maxId = this.baseMapper.getMaxSyncId(); + if(ToolUtil.isEmpty(maxId)){ + maxId = 1000L; + }else { + maxId = maxId + 1; + } + this.insert(new FacePersonSync(personId,maxId)); + return maxId; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/Impl/FaceSubscribeServiceImpl.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/Impl/FaceSubscribeServiceImpl.java new file mode 100644 index 0000000..c04302d --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/Impl/FaceSubscribeServiceImpl.java @@ -0,0 +1,52 @@ +package com.casic.missiles.modular.system.service.Impl; + +import com.baomidou.mybatisplus.mapper.EntityWrapper; +import com.casic.missiles.modular.system.model.FaceSubscribe; +import com.casic.missiles.modular.system.dao.FaceSubscribeMapper; +import com.casic.missiles.modular.system.service.IFaceSubscribeService; +import com.baomidou.mybatisplus.service.impl.ServiceImpl; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +/** + *

+ * 服务实现类 + *

+ * + * @author zyj123 + * @since 2020-07-25 + */ +@Service +public class FaceSubscribeServiceImpl extends ServiceImpl implements IFaceSubscribeService { + + @Override + public List selectSubscribeIdsByDevCode(String devCode) { + EntityWrapper query = new EntityWrapper(); + query.eq("DEVICE_CODE",devCode); + List faceSubscribes = this.selectList(query); + List subscribeIds = new ArrayList<>(); + for (FaceSubscribe faceSubscribe : faceSubscribes) { + subscribeIds.add(faceSubscribe.getSubscribeId()); + } + return subscribeIds; + } + + @Override + public boolean deleteByDevCode(String devCode) { + EntityWrapper query = new EntityWrapper(); + query.eq("DEVICE_CODE",devCode); + return this.delete(query); + } + + @Override + public boolean insertSubscribe(Long subscribeId, String devCode) { + FaceSubscribe faceSubscribe = new FaceSubscribe(); + faceSubscribe.setDeviceCode(devCode); + faceSubscribe.setSubscribeId(subscribeId); + faceSubscribe.setUpdateTime(new Date()); + return this.insert(faceSubscribe); + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/Impl/FaceSyncServiceImpl.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/Impl/FaceSyncServiceImpl.java new file mode 100644 index 0000000..8826be5 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/Impl/FaceSyncServiceImpl.java @@ -0,0 +1,465 @@ +package com.casic.missiles.modular.system.service.Impl; + +import com.alibaba.fastjson.JSONObject; +import com.casic.missiles.core.common.service.ICommonPersonService; +import com.casic.missiles.core.util.ToolUtil; +import com.casic.missiles.modular.system.model.Device; +import com.casic.missiles.modular.system.model.FacePersonSync; +import com.casic.missiles.modular.system.model.Person; +import com.casic.missiles.modular.system.model.RecognitionRecords; +import com.casic.missiles.modular.system.request.PersonInfo; +import com.casic.missiles.modular.system.response.*; +import com.casic.missiles.modular.system.service.*; +import com.casic.missiles.modular.system.util.HttpClientUtil; +import com.google.gson.*; +import org.apache.commons.lang3.StringUtils; +import org.omg.CORBA.Object; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import com.casic.missiles.modular.system.constant.FaceSyncConst; +import java.net.InetAddress; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +@Service +public class FaceSyncServiceImpl implements IFaceSyncService { + private static final Logger logger = LoggerFactory.getLogger(FaceSyncServiceImpl.class); + + @Autowired + private IFacePersonSyncService personSyncService; + @Autowired + private ICommonPersonService commonPersonService; + @Autowired + private IPersonPhotoSupportService photoSupportService; + @Autowired + private IDeviceSupportService deviceSupportService; + @Autowired + private IRecordSupportService recordSupportService; + @Autowired + private IFaceSubscribeService subscribeService; + @Value("${server.port}") + private String serverPort; + @Value("${iris.face.serverHost}") + private String serverHost; + + @Override + @Transactional + public String uploadPerson(List personIds,List deviceIds,String personType) { + String error = null; + + try{ + List personInfoList = new ArrayList<>(personIds.size()); + for (Long personId : personIds) { + Person person = commonPersonService.getPersonById(personId); + Long syncId = getPersonSyncId(personId); + String photoData = photoSupportService.selectPhotoDataById(personId); + PersonInfo personInfo = convPersonInfo(person,syncId,photoData); + personInfoList.add(personInfo); + } + + + outterLoop : for (Long deviceId : deviceIds) { + Device device = deviceSupportService.selectById(deviceId); + // 批量下发(单次最多6个,分多次下发) + int batchSize = FaceSyncConst.UPLOAD_MAX_PERSON; + int batchNum = (int)Math.ceil((double)personInfoList.size()/batchSize); + for (int i = 0; i < batchNum; i++) { + int fromIndex = i * batchSize; + int toIndex = (i+1) * batchSize <= personInfoList.size() ? (i+1) * batchSize : personInfoList.size(); + List subPersonInfoList = personInfoList.subList(fromIndex,toIndex); + + // 设置上传body对象 + Gson gson = new GsonBuilder().serializeNulls().create(); + JsonObject body = new JsonObject(); + JsonElement person = gson.toJsonTree(subPersonInfoList); + body.addProperty("Num",subPersonInfoList.size()); + body.add("PersonInfoList",person); + String bodyStr = gson.toJson(body); +// logger.info(String.valueOf(subPersonInfoList.size())); + logger.info(bodyStr); + +// 调用接口上传 + String devIp = device.getDevIp(); + String personLib = null; + if("1".equals(personType)){ + personLib = FaceSyncConst.UPLOAD_STAFF_LIB; + }else { + personLib = FaceSyncConst.UPLOAD_VISITOR_LIB; + } + + String url = "http://".concat(devIp).concat(FaceSyncConst.UPLOAD_URL_PREFIX).concat(personLib).concat(FaceSyncConst.UPLOAD_URL_SUFFIX); + String responseContent = HttpClientUtil.sendHttpPost(url,bodyStr); + logger.info(responseContent); + JsonObject obj = gson.fromJson(responseContent, JsonObject.class); + // 解析返回结果 + FaceBaseResponse> response = gson.fromJson(obj.get("Response"),FaceBaseResponse.class); + if(response.getResponseCode() == 0 && response.getStatusCode() == 0){ + PersonResponseData personResponseData = gson.fromJson(gson.toJson(response.getData()),PersonResponseData.class); + List responseInfos = personResponseData.getPersonList(); + for(int j = 0;j < responseInfos.size();j++){ + PersonResponseInfo personResponseInfo = gson.fromJson(gson.toJson(responseInfos.get(j)),PersonResponseInfo.class);; + if(personResponseInfo.getFaceList().get(0).getResultCode() == 0){ + // 成功 + logger.info(String.format("人脸数据下发成功,人员:%s,设备: %s",personResponseInfo.getPersonId(),device.getDevCode())); + }else{ + error = convErrorCode(personResponseInfo.getFaceList().get(0).getResultCode()); + String personName = commonPersonService.getPersonById(personIds.get(i)).getName(); + error = String.format("下发失败,%s %s",personName,error); + logger.error(error); + break outterLoop; + } + } + }else { + if(response.getResponseCode() != 0 ){ + error = String.format("设备%s下发失败: %s",device.getDevCode(),response.getResponseString()); + logger.error(error); + break; + } + if(response.getStatusCode() != 0){ + error = String.format("设备%s下发失败: %s",device.getDevCode(),response.getStatusString()); + logger.error(error); + break; + } + } + } + } + }catch (Exception e){ + e.printStackTrace(); + logger.error(e.getMessage()); + error = "下发失败"; + } + + return error; + } + + private void updatePersonInfoList(List personInfoList,List personIds){ + for (int i = 0; i < personIds.size(); i++) { + Long syncId = personSyncService.selectSyncId(personIds.get(i)); + if(ToolUtil.isNotEmpty(syncId)){ + PersonInfo personInfo = personInfoList.get(i); + personInfo.setPersonID(syncId); + if(ToolUtil.isNotEmpty(personInfo.getImageList())){ + personInfo.getImageList().get(i).setFaceID(syncId); + } + } + } + } + + private Long getPersonSyncId(Long personId){ + Long syncId = personSyncService.selectSyncId(personId); + if(ToolUtil.isEmpty(syncId)){ + syncId = personSyncService.getMaxSyncId(personId); + } + return syncId; + } + + private PersonInfo convPersonInfo(Person person,Long syncId,String photoData){ + PersonInfo personInfo = new PersonInfo(); + if(ToolUtil.isNotEmpty(syncId)){ + personInfo.setPersonID(syncId); + } + if(ToolUtil.isNotEmpty(person.getUpdatetime())){ + personInfo.setLastChange(person.getUpdatetime().getTime()); + } + if(ToolUtil.isNotEmpty(person.getPersonCode()) && person.getPersonCode().length() <= FaceSyncConst.UPLOAD_PERSONCODE_MAXLENGTH){ + personInfo.setPersonCode(person.getPersonCode()); + }else { + personInfo.setPersonCode(String.valueOf(syncId)); + } + if(ToolUtil.isNotEmpty(person.getName())){ + personInfo.setPersonName(person.getName()); + } + if(ToolUtil.isNotEmpty(person.getRemarks()) && person.getRemarks().length() <= FaceSyncConst.UPLOAD_REMARK_MAXLENGTH){ + personInfo.setRemarks(person.getRemarks()); + }else { + personInfo.setRemarks(""); + } + + // 时间模板 + personInfo.setTimeTemplateNum(0); + List timeTemplateList = new ArrayList<>(); + timeTemplateList.add(personInfo.createTimeTemplate(0L,4294967295L,0L)); + personInfo.setTimeTemplateList(timeTemplateList); + + // 证件列表 + if(ToolUtil.isNotEmpty(person.getIdCardNo())){ + personInfo.setIdentificationNum(1); + List identificationInfoList = new ArrayList<>(); + identificationInfoList.add(personInfo.createIdentificationInfo(1,person.getIdCardNo())); + personInfo.setIdentificationList(identificationInfoList); + }else{ + personInfo.setIdentificationNum(0); + } + + // 图片列表 + if(ToolUtil.isNotEmpty(photoData)){ + personInfo.setImageNum(1); + List imageInfoList = new ArrayList<>(); + // 图片base64码 + if(photoData.startsWith("data") || photoData.startsWith("base64")){ + int splitIndex = photoData.indexOf(","); + photoData = photoData.substring(splitIndex+1); + } + imageInfoList.add(personInfo.createImageInfo(syncId,person.getPhoto(),Long.valueOf(photoData.length()),photoData)); + personInfo.setImageList(imageInfoList); + }else { + personInfo.setImageNum(0); + } + return personInfo; + } + + private String convErrorCode(Long errorCode){ + String errorMsg = ""; + switch (errorCode.intValue()){ + case 1000: + errorMsg = "算法初始化失败"; + break; + case 1001: + errorMsg = "人脸检测失败"; + break; + case 1002: + errorMsg = "图片未检测到人脸"; + break; + case 1003: + errorMsg = "jpeg照片解码失败"; + break; + case 1004: + errorMsg = "图片质量分数不满足"; + break; + case 1005: + errorMsg = "图片缩放失败"; + break; + case 1006: + errorMsg = "未启用智能"; + break; + case 1007: + errorMsg = "导入图片过小"; + break; + case 1008: + errorMsg = "导入图片过大"; + break; + case 1009: + errorMsg = "导入图片分辨率超过1920*1080"; + break; + case 1010: + errorMsg = "导入图片不存在"; + break; + case 1011: + errorMsg = "人脸元素个数已达到上限"; + break; + case 1012: + errorMsg = "智能棒算法模型不匹配"; + break; + case 1013: + errorMsg = "人脸导入库成员证件号非法"; + break; + case 1014: + errorMsg = "人脸导入库成员图片格式错误"; + break; + case 1015: + errorMsg = "通道布控已达设备能力上限"; + break; + case 1016: + errorMsg = "其它客户端正在进行操作人脸库"; + break; + case 1017: + errorMsg = "人脸库文件正在更新中"; + break; + case 1018: + errorMsg = "Json反序列化失败"; + break; + case 1019: + errorMsg = "Base64解码失败"; + break; + case 1020: + errorMsg = "人脸照片,编码后的大小和实际接收到的长度不一致,关注Data和Size大小是否正确"; + break; + default: + break; + } + return errorMsg; + + } + + @Override + public String checkPersonPhoto(List personIds) { + String error = null; + for (Long personId : personIds) { + Person person = commonPersonService.getPersonById(personId); + String photoData = photoSupportService.selectPhotoDataById(personId); + if(ToolUtil.isEmpty(photoData)){ + error = String.format("%s 未上传照片",person.getName()); + break; + } + if(photoData.startsWith("data") || photoData.startsWith("base64")){ + int splitIndex = photoData.indexOf(","); + photoData = photoData.substring(splitIndex+1); + } + if(!photoData.startsWith("/9j")){ + error = String.format("%s人员照片不符合要求,必须为jpg格式",person.getName()); + break; + } + + // 找到等号,把等号也去掉 + int equalIndex = photoData.indexOf('='); + if(equalIndex>=0) { + photoData=photoData.substring(0, equalIndex); + } + // 原来的字符流大小,单位为字节 + int strLength=photoData.length(); + // 计算后得到的文件流大小,单位为字节 + int fileLength=Integer.valueOf(strLength-(strLength/8)*2); + if(fileLength / 1024 < 20){ + error = String.format("%s人员照片不符合要求,照片必须大于20Kb",person.getName()); + break; + } + } + return error; + } + + @Override + public void receiveRecord(RecordNotification recordNotification){ +// if(recordNotification.getFaceInfoNum() != recordNotification.getLibMatInfoNum()){ +// logger.error("采集和匹配数据不一致,识别失败"); +// } else { + String deviceCode = recordNotification.getDeviceCode(); + List recordsList = new ArrayList<>(); + for (int i = 0; i < recordNotification.getLibMatInfoNum(); i++) { + //FaceInfo faceInfo = recordNotification.getFaceInfoList().get(i); + LibMatInfo libMatInfo = recordNotification.getLibMatInfoList().get(i); + if(libMatInfo.getMatchStatus() == 1){ + FaceInfo faceInfo = getFaceInfoByMatchId(recordNotification.getFaceInfoList(),libMatInfo.getId()); + Long personId = personSyncService.selectPersonId(libMatInfo.getMatchPersonId()); + if(ToolUtil.isNotEmpty(personId) && ToolUtil.isNotEmpty(faceInfo)){ + RecognitionRecords record = new RecognitionRecords(); + record.setPersonId(personId); + record.setDatetime(new Date(faceInfo.getTimestamp()*1000)); + record.setDevCode(deviceCode); + if(ToolUtil.isNotEmpty(faceInfo.getTemperature())){ + record.setTemperature(String.valueOf(faceInfo.getTemperature())); + } + record.setOriginalId(libMatInfo.getId()); + record.setSyncTime(new Date()); + + Device device = deviceSupportService.selectDeviceByCode(deviceCode); + if(ToolUtil.isNotEmpty(device)){ + if(ToolUtil.isNotEmpty(device.getDevIp())){ + record.setDevIp(device.getDevIp()); + } + } + + recordsList.add(record); + } + } + } + if(ToolUtil.isNotEmpty(recordsList)){ + recordSupportService.insertBatch(recordsList); + } + } + + @Override + public void receiveRecord(String recordNotificationStr) { + RecordNotification recordNotification = JSONObject.parseObject(recordNotificationStr,RecordNotification.class); + receiveRecord(recordNotification); + } + + public FaceInfo getFaceInfoByMatchId(List faceInfoList ,Long id){ + for (FaceInfo faceInfo : faceInfoList) { + if(faceInfo.getId().equals(id)){ + return faceInfo; + } + } + return null; + } + + @Override + public String initSubscription(List deviceIds) { + try { + List error = new ArrayList<>(); + for (Long deviceId : deviceIds) { + Device device = deviceSupportService.selectById(deviceId); + List subscribeIds = subscribeService.selectSubscribeIdsByDevCode(device.getDevCode());; + // 删除所有id + boolean flag = true; + for (Long subscribeId : subscribeIds) { + flag = flag && deleteSubscription(device.getDevIp(),subscribeId); + } + flag = flag && subscribeService.deleteByDevCode(device.getDevCode()); + // 创建订阅 + Long subscribeId = createSubscription(device.getDevIp(),serverHost,serverPort); + flag = flag && ToolUtil.isNotEmpty(subscribeId); + if(ToolUtil.isNotEmpty(subscribeId)){ + flag = flag && subscribeService.insertSubscribe(subscribeId,device.getDevCode()); + } + if(!flag){ + logger.error(String.format("device %s init subsrciption error",device.getDevCode())); + error.add(device.getDevCode()); + } + } + if(ToolUtil.isNotEmpty(error)){ + return StringUtils.join(error,",").concat("订阅失败"); + }else { + return null; + } + }catch (Exception e){ + e.printStackTrace(); + logger.error(e.getMessage()); + return "订阅失败"; + } + + } + + @Override + public boolean deleteSubscription(String deviceIp, Long subscribeId) { + String url = "http://" + deviceIp + FaceSyncConst.SUBSCRIBE_URL + subscribeId; + String responseContent = HttpClientUtil.sendHttpDelete(url); + logger.info(responseContent); + Gson gson = new Gson(); + JsonObject obj = gson.fromJson(responseContent, JsonObject.class); + logger.info(obj.get("Response").toString()); + FaceBaseResponse response = gson.fromJson(obj.get("Response"),FaceBaseResponse.class); + if(response.getResponseCode() == 0 && response.getStatusCode() == 0){ + return true; + }else { + logger.error(String.format("delele subscribe error, device '%s', subscribeId '%s', response '%s', status '%s'",deviceIp,subscribeId,response.getResponseString(),response.getStatusString())); + return false; + } + } + + @Override + public Long createSubscription(String deviceIp, String ip, String port) { + JsonObject request = new JsonObject(); + request.addProperty("AddressType",0); + request.addProperty("IPAddress",ip); + request.addProperty("Port",Long.valueOf(port)); + request.addProperty("Duration",4294967295L); + request.addProperty("Type",1024); + JsonObject subscribePersonCondition = new JsonObject(); + subscribePersonCondition.addProperty("LibIDNum",65535); + subscribePersonCondition.add("LibIDList",new JsonArray()); + request.add("SubscribePersonCondition",subscribePersonCondition); + Gson gson = new Gson(); + String requestStr = gson.toJson(request); + System.out.println(requestStr); + String url = "http://" + deviceIp + FaceSyncConst.SUBSCRIBE_URL ; + String responseContent = HttpClientUtil.sendHttpPostJson(url,requestStr); + logger.info(responseContent); + JsonObject obj = gson.fromJson(responseContent, JsonObject.class); + FaceBaseResponse response = gson.fromJson(obj.get("Response"),FaceBaseResponse.class); + if(response.getResponseCode() == 0 && response.getStatusCode()==0){ + JsonObject data = gson.fromJson(gson.toJson(response.getData()),JsonObject.class); + Long subsrcibeId = data.get("ID").getAsLong(); + logger.info(String.format("create subscribe success, device '%s', subsrcibeId '%s'",deviceIp,subsrcibeId)); + return subsrcibeId; + }else { + logger.error(String.format("create subscribe error, device '%s', response '%s', status '%s'",deviceIp,response.getResponseString(),response.getStatusString())); + return null; + } + } + +} diff --git a/casic-face-sync/pom.xml b/casic-face-sync/pom.xml new file mode 100644 index 0000000..24dc884 --- /dev/null +++ b/casic-face-sync/pom.xml @@ -0,0 +1,74 @@ + + + 4.0.0 + + com.casic + casic-iris-parent + 1.0.0-SNAPSHOT + ../pom.xml + + + + casic-face-sync + ${pro.version} + jar + casic-face-sync + + + + + + com.casic + casic-core + ${core.version} + + + + com.casic + casic-admin-support + ${admin.version} + + + com.casic + casic-iris-support + ${pro.version} + + + + org.apache.httpcomponents + httpclient + 4.5.3 + + + + org.apache.httpcomponents + httpcore + 4.4.8 + + + + org.apache.httpcomponents + httpmime + 4.5.3 + + + + com.google.code.gson + gson + + + + + + + + src/main/java + + **/*.xml + + + + + \ No newline at end of file diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/constant/FaceSyncConst.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/constant/FaceSyncConst.java new file mode 100644 index 0000000..352d47d --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/constant/FaceSyncConst.java @@ -0,0 +1,29 @@ +package com.casic.missiles.modular.system.constant; + +public class FaceSyncConst { + + /** + * 单次最大批量上传人员数 + */ + public static final int UPLOAD_MAX_PERSON = 6; + + /** + * 上传人员库 + */ + public static final String UPLOAD_STAFF_LIB = "3"; + public static final String UPLOAD_VISITOR_LIB = "4"; + + public static final String UPLOAD_URL_PREFIX = "/LAPI/V1.0/PeopleLibraries/"; + + public static final String UPLOAD_URL_SUFFIX = "/People"; + + public static final int UPLOAD_PERSONCODE_MAXLENGTH = 15; + + public static final int UPLOAD_REMARK_MAXLENGTH = 63; + + public static final String SUBSCRIBE_URL = "/LAPI/V1.0/System/Event/Subscription/"; + + public static final String STAFF_PERSON_TYPE = "1"; + + public static final String VISITOR_PERSON_TYPE = "0"; +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/controller/FaceSyncController.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/controller/FaceSyncController.java new file mode 100644 index 0000000..1b35431 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/controller/FaceSyncController.java @@ -0,0 +1,117 @@ +package com.casic.missiles.modular.system.controller; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson.serializer.SerializerFeature; +import com.casic.missiles.core.base.response.ResponseData; +import com.casic.missiles.core.common.service.ICommonPermissionService; +import com.casic.missiles.core.common.service.ICommonPersonService; +import com.casic.missiles.core.datascope.DataScope; +import com.casic.missiles.core.util.ToolUtil; +import com.casic.missiles.modular.system.request.PersonInfo; +import com.casic.missiles.modular.system.response.RecordNotification; +import com.casic.missiles.modular.system.service.IFaceSyncService; +import com.casic.missiles.modular.system.service.IIrisPersonSupportService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.*; +import com.casic.missiles.modular.system.constant.FaceSyncConst; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + + + +@Controller +public class FaceSyncController { + private final static Logger logger = LoggerFactory.getLogger(FaceSyncController.class); + + @Autowired + private IFaceSyncService syncService; + @Autowired + private ICommonPersonService commonPersonService; + @Autowired + private IIrisPersonSupportService personSupportService; + @Autowired + private ICommonPermissionService permissionService; + + @RequestMapping("/face/upload") + @ResponseBody + public Object upload(@RequestParam("personIds") List personIds, + @RequestParam("deviceIds") List deviceIds, + @RequestParam("personType")String personType ){ + // 检查数量 +// if(personIds.size()>FaceSyncConst.UPLOAD_MAX_PERSON){ +// return ResponseData.error(String.format("每次最多上传%s个人",FaceSyncConst.UPLOAD_MAX_PERSON)); +// } + // 检查照片格式及大小 + String photoCheck = syncService.checkPersonPhoto(personIds); + if(ToolUtil.isNotEmpty(photoCheck)){ + return ResponseData.error(photoCheck); + } + else{ + // 上传数据 + String error = syncService.uploadPerson(personIds,deviceIds,personType); + if(ToolUtil.isNotEmpty(error)){ + return ResponseData.error(error); + } + } + return ResponseData.success(); + } + + @RequestMapping("/face/uploadAll") + @ResponseBody + public Object uploadAll(@RequestParam("deviceIds") List deviceIds){ + DataScope dataScope = permissionService.getCurrUserDataScope(); + + List staffPersonIds = personSupportService.listIdsByType(dataScope,FaceSyncConst.STAFF_PERSON_TYPE); + List visitorPersonIds = personSupportService.listIdsByType(dataScope,FaceSyncConst.VISITOR_PERSON_TYPE); + // 1.检查照片,分别检查员工、访客 + String staffPhotoCheck = syncService.checkPersonPhoto(staffPersonIds); + if(ToolUtil.isNotEmpty(staffPhotoCheck)){ + return ResponseData.error(staffPhotoCheck); + } + String visitorPhotoCheck = syncService.checkPersonPhoto(visitorPersonIds); + if(ToolUtil.isNotEmpty(visitorPhotoCheck)){ + return ResponseData.error(visitorPhotoCheck); + } + + // 2. 下发数据 + String staffError = syncService.uploadPerson(staffPersonIds,deviceIds,FaceSyncConst.STAFF_PERSON_TYPE); + if(ToolUtil.isNotEmpty(staffError)){ + return ResponseData.error(staffError); + } + String visitorError = syncService.uploadPerson(visitorPersonIds,deviceIds,FaceSyncConst.VISITOR_PERSON_TYPE); + if(ToolUtil.isNotEmpty(visitorError)){ + return ResponseData.error(visitorError); + } + + return ResponseData.success(); + } + + // 错误信息返回 + @RequestMapping("/subsrcibe/init") + @ResponseBody + public Object upload(@RequestParam("deviceIds") List deviceIds){ + String errorMsg = syncService.initSubscription(deviceIds); + if(ToolUtil.isNotEmpty(errorMsg)){ + return ResponseData.error(errorMsg); + } + return ResponseData.success(); + } + + + @RequestMapping(value = "/LAPI/V1.0/System/Event/Notification/PersonVerification", method = RequestMethod.POST) + @ResponseBody + public void verification(@RequestBody String recordNotification){ + logger.info(recordNotification); + RecordNotification record = JSONObject.parseObject(recordNotification,RecordNotification.class); + syncService.receiveRecord(record); + //return ResponseData.success(); + } + + +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FacePersonSyncMapper.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FacePersonSyncMapper.java new file mode 100644 index 0000000..af53702 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FacePersonSyncMapper.java @@ -0,0 +1,17 @@ +package com.casic.missiles.modular.system.dao; + +import com.casic.missiles.modular.system.model.FacePersonSync; +import com.baomidou.mybatisplus.mapper.BaseMapper; + +/** + *

+ * Mapper 接口 + *

+ * + * @author zyj123 + * @since 2020-07-24 + */ +public interface FacePersonSyncMapper extends BaseMapper { + + Long getMaxSyncId(); +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FaceSubscribeMapper.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FaceSubscribeMapper.java new file mode 100644 index 0000000..0c6374a --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FaceSubscribeMapper.java @@ -0,0 +1,16 @@ +package com.casic.missiles.modular.system.dao; + +import com.casic.missiles.modular.system.model.FaceSubscribe; +import com.baomidou.mybatisplus.mapper.BaseMapper; + +/** + *

+ * Mapper 接口 + *

+ * + * @author zyj123 + * @since 2020-07-25 + */ +public interface FaceSubscribeMapper extends BaseMapper { + +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FacePersonSyncMapper.xml b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FacePersonSyncMapper.xml new file mode 100644 index 0000000..ac46ad0 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FacePersonSyncMapper.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + PERSON_ID AS personId, SYNC_ID AS syncId + + + + + diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FaceSubscribeMapper.xml b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FaceSubscribeMapper.xml new file mode 100644 index 0000000..16024e2 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FaceSubscribeMapper.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + SUBSCRIBE_ID AS subscribeId, DEVICE_CODE AS deviceCode, UPDATE_TIME AS updateTime + + + diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FacePersonSync.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FacePersonSync.java new file mode 100644 index 0000000..7cdb821 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FacePersonSync.java @@ -0,0 +1,68 @@ +package com.casic.missiles.modular.system.model; + +import java.io.Serializable; + +import com.baomidou.mybatisplus.annotations.TableId; +import com.baomidou.mybatisplus.annotations.TableField; +import com.baomidou.mybatisplus.activerecord.Model; +import com.baomidou.mybatisplus.annotations.TableName; +import java.io.Serializable; + +/** + *

+ * + *

+ * + * @author zyj123 + * @since 2020-07-24 + */ +@TableName("face_person_sync") +public class FacePersonSync extends Model { + + private static final long serialVersionUID = 1L; + + /** + * 人员id + */ + @TableId("PERSON_ID") + private Long personId; + /** + * 人员同步id + */ + @TableField("SYNC_ID") + private Long syncId; + + public FacePersonSync(Long personId, Long syncId) { + this.personId = personId; + this.syncId = syncId; + } + + public Long getPersonId() { + return personId; + } + + public void setPersonId(Long personId) { + this.personId = personId; + } + + public Long getSyncId() { + return syncId; + } + + public void setSyncId(Long syncId) { + this.syncId = syncId; + } + + @Override + protected Serializable pkVal() { + return this.personId; + } + + @Override + public String toString() { + return "FacePersonSync{" + + "personId=" + personId + + ", syncId=" + syncId + + "}"; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FaceSubscribe.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FaceSubscribe.java new file mode 100644 index 0000000..ccc7792 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FaceSubscribe.java @@ -0,0 +1,79 @@ +package com.casic.missiles.modular.system.model; + +import java.io.Serializable; + +import java.util.Date; +import com.baomidou.mybatisplus.annotations.TableId; +import com.baomidou.mybatisplus.annotations.TableField; +import com.baomidou.mybatisplus.activerecord.Model; +import com.baomidou.mybatisplus.annotations.TableName; +import java.io.Serializable; + +/** + *

+ * + *

+ * + * @author zyj123 + * @since 2020-07-25 + */ +@TableName("face_subscribe") +public class FaceSubscribe extends Model { + + private static final long serialVersionUID = 1L; + + /** + * 订阅id + */ + @TableId("SUBSCRIBE_ID") + private Long subscribeId; + /** + * 设备编号 + */ + @TableField("DEVICE_CODE") + private String deviceCode; + /** + * 更新时间 + */ + @TableField("UPDATE_TIME") + private Date updateTime; + + + public Long getSubscribeId() { + return subscribeId; + } + + public void setSubscribeId(Long subscribeId) { + this.subscribeId = subscribeId; + } + + public String getDeviceCode() { + return deviceCode; + } + + public void setDeviceCode(String deviceCode) { + this.deviceCode = deviceCode; + } + + public Date getUpdateTime() { + return updateTime; + } + + public void setUpdateTime(Date updateTime) { + this.updateTime = updateTime; + } + + @Override + protected Serializable pkVal() { + return this.subscribeId; + } + + @Override + public String toString() { + return "FaceSubscribe{" + + "subscribeId=" + subscribeId + + ", deviceCode=" + deviceCode + + ", updateTime=" + updateTime + + "}"; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/request/PersonInfo.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/request/PersonInfo.java new file mode 100644 index 0000000..80d9eff --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/request/PersonInfo.java @@ -0,0 +1,271 @@ +package com.casic.missiles.modular.system.request; + +import com.alibaba.fastjson.annotation.JSONField; +import com.baomidou.mybatisplus.annotations.TableField; +import com.google.gson.annotations.SerializedName; + +import java.util.List; + +public class PersonInfo { + + //@JSONField(name = "PersonID") + @SerializedName("PersonID") + private Long personID; + + //@JSONField(name = "LastChange") + @SerializedName("LastChange") + private Long lastChange; + + //@JSONField(name = "PersonCode") + @SerializedName("PersonCode") + private String personCode; + + //@JSONField(name = "PersonName") + @SerializedName("PersonName") + private String personName; + + //@JSONField(name = "Remarks") + @SerializedName("Remarks") + private String remarks; + + //@JSONField(name = "TimeTemplateNum") + @SerializedName("TimeTemplateNum") + private Integer timeTemplateNum; + + //@JSONField(name = "TimeTemplateList") + @SerializedName("TimeTemplateList") + private List timeTemplateList; + + //@JSONField(name = "IdentificationNum") + @SerializedName("IdentificationNum") + private Integer identificationNum; + + //@JSONField(name = "IdentificationList") + @SerializedName("IdentificationList") + private List identificationList; + + //@JSONField(name = "ImageNum") + @SerializedName("ImageNum") + private Integer imageNum; + + //@JSONField(name = "ImageList") + @SerializedName("ImageList") + private List imageList; + + public Long getPersonID() { + return personID; + } + + public void setPersonID(Long personID) { + this.personID = personID; + } + + public Long getLastChange() { + return lastChange; + } + + public void setLastChange(Long lastChange) { + this.lastChange = lastChange; + } + + public String getPersonCode() { + return personCode; + } + + public void setPersonCode(String personCode) { + this.personCode = personCode; + } + + public String getPersonName() { + return personName; + } + + public void setPersonName(String personName) { + this.personName = personName; + } + + public String getRemarks() { + return remarks; + } + + public void setRemarks(String remarks) { + this.remarks = remarks; + } + + public Integer getTimeTemplateNum() { + return timeTemplateNum; + } + + public void setTimeTemplateNum(Integer timeTemplateNum) { + this.timeTemplateNum = timeTemplateNum; + } + + public List getTimeTemplateList() { + return timeTemplateList; + } + + public void setTimeTemplateList(List timeTemplateList) { + this.timeTemplateList = timeTemplateList; + } + + public Integer getIdentificationNum() { + return identificationNum; + } + + public void setIdentificationNum(Integer identificationNum) { + this.identificationNum = identificationNum; + } + + public List getIdentificationList() { + return identificationList; + } + + public void setIdentificationList(List identificationList) { + this.identificationList = identificationList; + } + + public Integer getImageNum() { + return imageNum; + } + + public void setImageNum(Integer imageNum) { + this.imageNum = imageNum; + } + + public List getImageList() { + return imageList; + } + + public void setImageList(List imageList) { + this.imageList = imageList; + } + + public class TimeTemplate{ + @JSONField(name = "BeginTime") + private Long beginTime; + @JSONField(name = "EndTime") + private Long endTime; + @JSONField(name = "Index") + private Long index; + + public TimeTemplate(Long beginTime, Long endTime, Long index) { + this.beginTime = beginTime; + this.endTime = endTime; + this.index = index; + } + + public Long getBeginTime() { + return beginTime; + } + + public void setBeginTime(Long beginTime) { + this.beginTime = beginTime; + } + + public Long getEndTime() { + return endTime; + } + + public void setEndTime(Long endTime) { + this.endTime = endTime; + } + + public Long getIndex() { + return index; + } + + public void setIndex(Long index) { + this.index = index; + } + } + + public TimeTemplate createTimeTemplate(Long beginTime, Long endTime, Long index){ + return new TimeTemplate(beginTime, endTime, index); + } + + public class IdentificationInfo { + @JSONField(name = "Type") + private Integer type; + @JSONField(name = "Number") + private String number; + + public IdentificationInfo(Integer type, String number) { + this.type = type; + this.number = number; + } + + public Integer getType() { + return type; + } + + public void setType(Integer type) { + this.type = type; + } + + public String getNumber() { + return number; + } + + public void setNumber(String number) { + this.number = number; + } + } + + public IdentificationInfo createIdentificationInfo(Integer type, String number){ + return new IdentificationInfo(type,number); + } + + public class ImageInfo{ + @JSONField(name = "FaceID") + private Long faceID; + @JSONField(name = "Name") + private String name; + @JSONField(name = "Size") + private Long size; + @JSONField(name = "Data") + private String data; + + public ImageInfo(Long faceID, String name, Long size, String data) { + this.faceID = faceID; + this.name = name; + this.size = size; + this.data = data; + } + + public Long getFaceID() { + return faceID; + } + + public void setFaceID(Long faceID) { + this.faceID = faceID; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Long getSize() { + return size; + } + + public void setSize(Long size) { + this.size = size; + } + + public String getData() { + return data; + } + + public void setData(String data) { + this.data = data; + } + } + + public ImageInfo createImageInfo(Long faceID, String name, Long size, String data){ + return new ImageInfo(faceID, name, size, data); + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceBaseResponse.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceBaseResponse.java new file mode 100644 index 0000000..fe93b8a --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceBaseResponse.java @@ -0,0 +1,90 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; +import com.google.gson.annotations.SerializedName; + +public class FaceBaseResponse { + @JSONField(name = "ResponseURL") + @SerializedName("ResponseURL") + private String responseUrl; + + @JSONField(name = "CreatedID") + @SerializedName("CreatedID") + private int createdId; + + @JSONField(name = "ResponseCode") + @SerializedName("ResponseCode") + private int responseCode; + + @JSONField(name = "ResponseString") + @SerializedName("ResponseString") + private String responseString; + + @JSONField(name = "StatusCode") + @SerializedName("StatusCode") + private int statusCode; + + @JSONField(name = "StatusString") + @SerializedName("StatusString") + private String statusString; + + //@JSONField(name = "Data") + @SerializedName("Data") + private T data; + + public String getResponseUrl() { + return responseUrl; + } + + public void setResponseUrl(String responseUrl) { + this.responseUrl = responseUrl; + } + + public int getCreatedId() { + return createdId; + } + + public void setCreatedId(int createdId) { + this.createdId = createdId; + } + + public int getResponseCode() { + return responseCode; + } + + public void setResponseCode(int responseCode) { + this.responseCode = responseCode; + } + + public String getResponseString() { + return responseString; + } + + public void setResponseString(String responseString) { + this.responseString = responseString; + } + + public int getStatusCode() { + return statusCode; + } + + public void setStatusCode(int statusCode) { + this.statusCode = statusCode; + } + + public String getStatusString() { + return statusString; + } + + public void setStatusString(String statusString) { + this.statusString = statusString; + } + + public T getData() { + return data; + } + + public void setData(T data) { + this.data = data; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceInfo.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceInfo.java new file mode 100644 index 0000000..f128c92 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceInfo.java @@ -0,0 +1,128 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; + +import java.util.List; + +public class FaceInfo { + @JSONField(name = "ID") + private Long id; + @JSONField(name = "Timestamp") + private Long timestamp; + @JSONField(name = "CapSrc") + private Long capSrc; + @JSONField(name = "FeatureNum") + private Long featureNum; + @JSONField(name = "FeatureList") + private List featureList; + @JSONField(name = "FeatureVersion") + private String featureVersion; + @JSONField(name = "Feature") + private String feature; + @JSONField(name = "Temperature") + private Float temperature; + @JSONField(name = "MaskFlag") + private Long maskFlag; + @JSONField(name = "PanoImage") + private Object panoImage; + @JSONField(name = "FaceImage") + private Object faceImage; + @JSONField(name = "FaceArea") + private Object faceArea; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Long getTimestamp() { + return timestamp; + } + + public void setTimestamp(Long timestamp) { + this.timestamp = timestamp; + } + + public Long getCapSrc() { + return capSrc; + } + + public void setCapSrc(Long capSrc) { + this.capSrc = capSrc; + } + + public Long getFeatureNum() { + return featureNum; + } + + public void setFeatureNum(Long featureNum) { + this.featureNum = featureNum; + } + + public List getFeatureList() { + return featureList; + } + + public void setFeatureList(List featureList) { + this.featureList = featureList; + } + + public String getFeatureVersion() { + return featureVersion; + } + + public void setFeatureVersion(String featureVersion) { + this.featureVersion = featureVersion; + } + + public String getFeature() { + return feature; + } + + public void setFeature(String feature) { + this.feature = feature; + } + + public Float getTemperature() { + return temperature; + } + + public void setTemperature(Float temperature) { + this.temperature = temperature; + } + + public Long getMaskFlag() { + return maskFlag; + } + + public void setMaskFlag(Long maskFlag) { + this.maskFlag = maskFlag; + } + + public Object getPanoImage() { + return panoImage; + } + + public void setPanoImage(Object panoImage) { + this.panoImage = panoImage; + } + + public Object getFaceImage() { + return faceImage; + } + + public void setFaceImage(Object faceImage) { + this.faceImage = faceImage; + } + + public Object getFaceArea() { + return faceArea; + } + + public void setFaceArea(Object faceArea) { + this.faceArea = faceArea; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/LibMatInfo.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/LibMatInfo.java new file mode 100644 index 0000000..ce6dd33 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/LibMatInfo.java @@ -0,0 +1,69 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; + +public class LibMatInfo { + @JSONField(name = "ID") + private Long id; + @JSONField(name = "LibID") + private Long libId; + @JSONField(name = "LibType") + private Long libType; + @JSONField(name = "MatchStatus") + private Long matchStatus; + @JSONField(name = "MatchPersonID") + private Long matchPersonId; + @JSONField(name = "MatchFaceID") + private Long matchFaceId; + + // MatchPersonInfo 暂时忽略不用 + + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Long getLibId() { + return libId; + } + + public void setLibId(Long libId) { + this.libId = libId; + } + + public Long getLibType() { + return libType; + } + + public void setLibType(Long libType) { + this.libType = libType; + } + + public Long getMatchStatus() { + return matchStatus; + } + + public void setMatchStatus(Long matchStatus) { + this.matchStatus = matchStatus; + } + + public Long getMatchPersonId() { + return matchPersonId; + } + + public void setMatchPersonId(Long matchPersonId) { + this.matchPersonId = matchPersonId; + } + + public Long getMatchFaceId() { + return matchFaceId; + } + + public void setMatchFaceId(Long matchFaceId) { + this.matchFaceId = matchFaceId; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/PersonResponseData.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/PersonResponseData.java new file mode 100644 index 0000000..186faed --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/PersonResponseData.java @@ -0,0 +1,31 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; +import com.google.gson.annotations.SerializedName; + +import java.util.List; + +public class PersonResponseData { + @JSONField(name = "Num") + @SerializedName("Num") + private int num; + @JSONField(name = "PersonList") + @SerializedName("PersonList") + private List personList; + + public int getNum() { + return num; + } + + public void setNum(int num) { + this.num = num; + } + + public List getPersonList() { + return personList; + } + + public void setPersonList(List personList) { + this.personList = personList; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/PersonResponseInfo.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/PersonResponseInfo.java new file mode 100644 index 0000000..7ba3edc --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/PersonResponseInfo.java @@ -0,0 +1,67 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; +import com.google.gson.annotations.SerializedName; + +import java.util.List; + +public class PersonResponseInfo { + @JSONField(name = "PersonID") + @SerializedName("PersonID") + private Long personId; + @JSONField(name = "FaceNum") + @SerializedName("FaceNum") + private Long faceNum; + @JSONField(name = "FaceList") + @SerializedName("FaceList") + private List faceList; + + public Long getPersonId() { + return personId; + } + + public void setPersonId(Long personId) { + this.personId = personId; + } + + public Long getFaceNum() { + return faceNum; + } + + public void setFaceNum(Long faceNum) { + this.faceNum = faceNum; + } + + public List getFaceList() { + return faceList; + } + + public void setFaceList(List faceList) { + this.faceList = faceList; + } + + public class PersonResponseFace{ + @JSONField(name = "FaceID") + @SerializedName("FaceID") + private Long faceId; + @JSONField(name = "ResultCode") + @SerializedName("ResultCode") + private Long resultCode; + + public Long getFaceId() { + return faceId; + } + + public void setFaceId(Long faceId) { + this.faceId = faceId; + } + + public Long getResultCode() { + return resultCode; + } + + public void setResultCode(Long resultCode) { + this.resultCode = resultCode; + } + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/RecordNotification.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/RecordNotification.java new file mode 100644 index 0000000..ca52d29 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/RecordNotification.java @@ -0,0 +1,138 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; + +import java.util.List; + +public class RecordNotification { + @JSONField(name = "Reference") + private String reference; + @JSONField(name = "Seq") + private int seq; + @JSONField(name = "DeviceCode") + private String deviceCode; + @JSONField(name = "Timestamp") + private Long timestamp; + @JSONField(name = "NotificationType") + private int notificationType; + @JSONField(name = "FaceInfoNum") + private int faceInfoNum; + @JSONField(name = "FaceInfoList") + private List faceInfoList; + @JSONField(name = "CardInfoNum") + private int cardInfoNum; + @JSONField(name = "CardInfoList") + private List cardInfoList; + @JSONField(name = "GateInfoNum") + private int gateInfoNum; + @JSONField(name = "GateInfoList") + private List gateInfoList; + @JSONField(name = "LibMatInfoNum") + private int libMatInfoNum; + @JSONField(name = "LibMatInfoList") + private List libMatInfoList; + + public String getReference() { + return reference; + } + + public void setReference(String reference) { + this.reference = reference; + } + + public int getSeq() { + return seq; + } + + public void setSeq(int seq) { + this.seq = seq; + } + + public String getDeviceCode() { + return deviceCode; + } + + public void setDeviceCode(String deviceCode) { + this.deviceCode = deviceCode; + } + + public Long getTimestamp() { + return timestamp; + } + + public void setTimestamp(Long timestamp) { + this.timestamp = timestamp; + } + + public int getNotificationType() { + return notificationType; + } + + public void setNotificationType(int notificationType) { + this.notificationType = notificationType; + } + + public int getFaceInfoNum() { + return faceInfoNum; + } + + public void setFaceInfoNum(int faceInfoNum) { + this.faceInfoNum = faceInfoNum; + } + + public List getFaceInfoList() { + return faceInfoList; + } + + public void setFaceInfoList(List faceInfoList) { + this.faceInfoList = faceInfoList; + } + + public int getCardInfoNum() { + return cardInfoNum; + } + + public void setCardInfoNum(int cardInfoNum) { + this.cardInfoNum = cardInfoNum; + } + + public List getCardInfoList() { + return cardInfoList; + } + + public void setCardInfoList(List cardInfoList) { + this.cardInfoList = cardInfoList; + } + + public int getGateInfoNum() { + return gateInfoNum; + } + + public void setGateInfoNum(int gateInfoNum) { + this.gateInfoNum = gateInfoNum; + } + + public List getGateInfoList() { + return gateInfoList; + } + + public void setGateInfoList(List gateInfoList) { + this.gateInfoList = gateInfoList; + } + + public int getLibMatInfoNum() { + return libMatInfoNum; + } + + public void setLibMatInfoNum(int libMatInfoNum) { + this.libMatInfoNum = libMatInfoNum; + } + + public List getLibMatInfoList() { + return libMatInfoList; + } + + public void setLibMatInfoList(List libMatInfoList) { + this.libMatInfoList = libMatInfoList; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/runner/InitSubscribeRunner.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/runner/InitSubscribeRunner.java new file mode 100644 index 0000000..c7d0565 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/runner/InitSubscribeRunner.java @@ -0,0 +1,43 @@ +package com.casic.missiles.modular.system.runner; + +import com.casic.missiles.modular.system.model.Device; +import com.casic.missiles.modular.system.service.IDeviceSupportService; +import com.casic.missiles.modular.system.service.IFaceSyncService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.ApplicationArguments; +import org.springframework.boot.ApplicationRunner; +import org.springframework.stereotype.Component; + +import java.util.ArrayList; +import java.util.List; + +@Component +public class InitSubscribeRunner implements ApplicationRunner { + private static Logger logger = LoggerFactory.getLogger(InitSubscribeRunner.class); + + @Value("${iris.face.initSubscribe}") + private String initSubscribe; + @Autowired + private IDeviceSupportService deviceSupportService; + @Autowired + private IFaceSyncService faceSyncService; + + /** + * 启动项目时,根据需要初始化设备订阅信息 + * @param applicationArguments + * @throws Exception + */ + @Override + public void run(ApplicationArguments applicationArguments) throws Exception { + logger.info("==================initSubscribe: "); + if(Boolean.valueOf(initSubscribe)){ + List deviceList = deviceSupportService.selectDeviceByType("5"); + List deviceIds = new ArrayList<>(); + deviceList.forEach(device -> deviceIds.add(Long.valueOf(device.getId()))); + faceSyncService.initSubscription(deviceIds); + } + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFacePersonSyncService.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFacePersonSyncService.java new file mode 100644 index 0000000..6b2461b --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFacePersonSyncService.java @@ -0,0 +1,18 @@ +package com.casic.missiles.modular.system.service; + +import com.casic.missiles.modular.system.model.FacePersonSync; +import com.baomidou.mybatisplus.service.IService; + +/** + *

+ * 服务类 + *

+ * + * @author zyj123 + * @since 2020-07-24 + */ +public interface IFacePersonSyncService extends IService { + Long selectSyncId(Long personId); + Long selectPersonId(Long syncId); + Long getMaxSyncId(Long personId); +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFaceSubscribeService.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFaceSubscribeService.java new file mode 100644 index 0000000..e0461ed --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFaceSubscribeService.java @@ -0,0 +1,24 @@ +package com.casic.missiles.modular.system.service; + +import com.casic.missiles.modular.system.model.FaceSubscribe; +import com.baomidou.mybatisplus.service.IService; + +import java.util.List; + +/** + *

+ * 服务类 + *

+ * + * @author zyj123 + * @since 2020-07-25 + */ +public interface IFaceSubscribeService extends IService { + + List selectSubscribeIdsByDevCode(String devCode); + + boolean deleteByDevCode(String devCode); + + boolean insertSubscribe(Long subscribeId, String devCode); + +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFaceSyncService.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFaceSyncService.java new file mode 100644 index 0000000..effd921 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFaceSyncService.java @@ -0,0 +1,21 @@ +package com.casic.missiles.modular.system.service; + +import com.casic.missiles.modular.system.response.RecordNotification; + +import java.util.List; + +public interface IFaceSyncService { + String uploadPerson(List personIds, List deviceIds,String personType); + + String checkPersonPhoto(List personIds); + + void receiveRecord(RecordNotification recordNotification); + + void receiveRecord(String recordNotificationStr); + + String initSubscription(List deviceIds); + + boolean deleteSubscription(String deviceIp, Long subscribeId); + + Long createSubscription(String deviceIp,String ip,String port); +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/Impl/FacePersonSyncServiceImpl.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/Impl/FacePersonSyncServiceImpl.java new file mode 100644 index 0000000..d1d1694 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/Impl/FacePersonSyncServiceImpl.java @@ -0,0 +1,55 @@ +package com.casic.missiles.modular.system.service.Impl; + +import com.baomidou.mybatisplus.mapper.EntityWrapper; +import com.casic.missiles.core.util.ToolUtil; +import com.casic.missiles.modular.system.model.FacePersonSync; +import com.casic.missiles.modular.system.dao.FacePersonSyncMapper; +import com.casic.missiles.modular.system.service.IFacePersonSyncService; +import com.baomidou.mybatisplus.service.impl.ServiceImpl; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +/** + *

+ * 服务实现类 + *

+ * + * @author zyj123 + * @since 2020-07-24 + */ +@Service +public class FacePersonSyncServiceImpl extends ServiceImpl implements IFacePersonSyncService { + + @Override + public Long selectSyncId(Long personId) { + FacePersonSync facePersonSync = this.selectById(personId); + if(ToolUtil.isNotEmpty(facePersonSync)){ + return facePersonSync.getSyncId(); + } + return null; + } + + @Override + public Long selectPersonId(Long syncId) { + EntityWrapper query = new EntityWrapper(); + query.eq("SYNC_ID",syncId); + FacePersonSync facePersonSync = this.selectOne(query); + if(ToolUtil.isNotEmpty(facePersonSync)){ + return facePersonSync.getPersonId(); + } + return null; + } + + @Override + @Transactional + public Long getMaxSyncId(Long personId) { + Long maxId = this.baseMapper.getMaxSyncId(); + if(ToolUtil.isEmpty(maxId)){ + maxId = 1000L; + }else { + maxId = maxId + 1; + } + this.insert(new FacePersonSync(personId,maxId)); + return maxId; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/Impl/FaceSubscribeServiceImpl.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/Impl/FaceSubscribeServiceImpl.java new file mode 100644 index 0000000..c04302d --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/Impl/FaceSubscribeServiceImpl.java @@ -0,0 +1,52 @@ +package com.casic.missiles.modular.system.service.Impl; + +import com.baomidou.mybatisplus.mapper.EntityWrapper; +import com.casic.missiles.modular.system.model.FaceSubscribe; +import com.casic.missiles.modular.system.dao.FaceSubscribeMapper; +import com.casic.missiles.modular.system.service.IFaceSubscribeService; +import com.baomidou.mybatisplus.service.impl.ServiceImpl; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +/** + *

+ * 服务实现类 + *

+ * + * @author zyj123 + * @since 2020-07-25 + */ +@Service +public class FaceSubscribeServiceImpl extends ServiceImpl implements IFaceSubscribeService { + + @Override + public List selectSubscribeIdsByDevCode(String devCode) { + EntityWrapper query = new EntityWrapper(); + query.eq("DEVICE_CODE",devCode); + List faceSubscribes = this.selectList(query); + List subscribeIds = new ArrayList<>(); + for (FaceSubscribe faceSubscribe : faceSubscribes) { + subscribeIds.add(faceSubscribe.getSubscribeId()); + } + return subscribeIds; + } + + @Override + public boolean deleteByDevCode(String devCode) { + EntityWrapper query = new EntityWrapper(); + query.eq("DEVICE_CODE",devCode); + return this.delete(query); + } + + @Override + public boolean insertSubscribe(Long subscribeId, String devCode) { + FaceSubscribe faceSubscribe = new FaceSubscribe(); + faceSubscribe.setDeviceCode(devCode); + faceSubscribe.setSubscribeId(subscribeId); + faceSubscribe.setUpdateTime(new Date()); + return this.insert(faceSubscribe); + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/Impl/FaceSyncServiceImpl.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/Impl/FaceSyncServiceImpl.java new file mode 100644 index 0000000..8826be5 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/Impl/FaceSyncServiceImpl.java @@ -0,0 +1,465 @@ +package com.casic.missiles.modular.system.service.Impl; + +import com.alibaba.fastjson.JSONObject; +import com.casic.missiles.core.common.service.ICommonPersonService; +import com.casic.missiles.core.util.ToolUtil; +import com.casic.missiles.modular.system.model.Device; +import com.casic.missiles.modular.system.model.FacePersonSync; +import com.casic.missiles.modular.system.model.Person; +import com.casic.missiles.modular.system.model.RecognitionRecords; +import com.casic.missiles.modular.system.request.PersonInfo; +import com.casic.missiles.modular.system.response.*; +import com.casic.missiles.modular.system.service.*; +import com.casic.missiles.modular.system.util.HttpClientUtil; +import com.google.gson.*; +import org.apache.commons.lang3.StringUtils; +import org.omg.CORBA.Object; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import com.casic.missiles.modular.system.constant.FaceSyncConst; +import java.net.InetAddress; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +@Service +public class FaceSyncServiceImpl implements IFaceSyncService { + private static final Logger logger = LoggerFactory.getLogger(FaceSyncServiceImpl.class); + + @Autowired + private IFacePersonSyncService personSyncService; + @Autowired + private ICommonPersonService commonPersonService; + @Autowired + private IPersonPhotoSupportService photoSupportService; + @Autowired + private IDeviceSupportService deviceSupportService; + @Autowired + private IRecordSupportService recordSupportService; + @Autowired + private IFaceSubscribeService subscribeService; + @Value("${server.port}") + private String serverPort; + @Value("${iris.face.serverHost}") + private String serverHost; + + @Override + @Transactional + public String uploadPerson(List personIds,List deviceIds,String personType) { + String error = null; + + try{ + List personInfoList = new ArrayList<>(personIds.size()); + for (Long personId : personIds) { + Person person = commonPersonService.getPersonById(personId); + Long syncId = getPersonSyncId(personId); + String photoData = photoSupportService.selectPhotoDataById(personId); + PersonInfo personInfo = convPersonInfo(person,syncId,photoData); + personInfoList.add(personInfo); + } + + + outterLoop : for (Long deviceId : deviceIds) { + Device device = deviceSupportService.selectById(deviceId); + // 批量下发(单次最多6个,分多次下发) + int batchSize = FaceSyncConst.UPLOAD_MAX_PERSON; + int batchNum = (int)Math.ceil((double)personInfoList.size()/batchSize); + for (int i = 0; i < batchNum; i++) { + int fromIndex = i * batchSize; + int toIndex = (i+1) * batchSize <= personInfoList.size() ? (i+1) * batchSize : personInfoList.size(); + List subPersonInfoList = personInfoList.subList(fromIndex,toIndex); + + // 设置上传body对象 + Gson gson = new GsonBuilder().serializeNulls().create(); + JsonObject body = new JsonObject(); + JsonElement person = gson.toJsonTree(subPersonInfoList); + body.addProperty("Num",subPersonInfoList.size()); + body.add("PersonInfoList",person); + String bodyStr = gson.toJson(body); +// logger.info(String.valueOf(subPersonInfoList.size())); + logger.info(bodyStr); + +// 调用接口上传 + String devIp = device.getDevIp(); + String personLib = null; + if("1".equals(personType)){ + personLib = FaceSyncConst.UPLOAD_STAFF_LIB; + }else { + personLib = FaceSyncConst.UPLOAD_VISITOR_LIB; + } + + String url = "http://".concat(devIp).concat(FaceSyncConst.UPLOAD_URL_PREFIX).concat(personLib).concat(FaceSyncConst.UPLOAD_URL_SUFFIX); + String responseContent = HttpClientUtil.sendHttpPost(url,bodyStr); + logger.info(responseContent); + JsonObject obj = gson.fromJson(responseContent, JsonObject.class); + // 解析返回结果 + FaceBaseResponse> response = gson.fromJson(obj.get("Response"),FaceBaseResponse.class); + if(response.getResponseCode() == 0 && response.getStatusCode() == 0){ + PersonResponseData personResponseData = gson.fromJson(gson.toJson(response.getData()),PersonResponseData.class); + List responseInfos = personResponseData.getPersonList(); + for(int j = 0;j < responseInfos.size();j++){ + PersonResponseInfo personResponseInfo = gson.fromJson(gson.toJson(responseInfos.get(j)),PersonResponseInfo.class);; + if(personResponseInfo.getFaceList().get(0).getResultCode() == 0){ + // 成功 + logger.info(String.format("人脸数据下发成功,人员:%s,设备: %s",personResponseInfo.getPersonId(),device.getDevCode())); + }else{ + error = convErrorCode(personResponseInfo.getFaceList().get(0).getResultCode()); + String personName = commonPersonService.getPersonById(personIds.get(i)).getName(); + error = String.format("下发失败,%s %s",personName,error); + logger.error(error); + break outterLoop; + } + } + }else { + if(response.getResponseCode() != 0 ){ + error = String.format("设备%s下发失败: %s",device.getDevCode(),response.getResponseString()); + logger.error(error); + break; + } + if(response.getStatusCode() != 0){ + error = String.format("设备%s下发失败: %s",device.getDevCode(),response.getStatusString()); + logger.error(error); + break; + } + } + } + } + }catch (Exception e){ + e.printStackTrace(); + logger.error(e.getMessage()); + error = "下发失败"; + } + + return error; + } + + private void updatePersonInfoList(List personInfoList,List personIds){ + for (int i = 0; i < personIds.size(); i++) { + Long syncId = personSyncService.selectSyncId(personIds.get(i)); + if(ToolUtil.isNotEmpty(syncId)){ + PersonInfo personInfo = personInfoList.get(i); + personInfo.setPersonID(syncId); + if(ToolUtil.isNotEmpty(personInfo.getImageList())){ + personInfo.getImageList().get(i).setFaceID(syncId); + } + } + } + } + + private Long getPersonSyncId(Long personId){ + Long syncId = personSyncService.selectSyncId(personId); + if(ToolUtil.isEmpty(syncId)){ + syncId = personSyncService.getMaxSyncId(personId); + } + return syncId; + } + + private PersonInfo convPersonInfo(Person person,Long syncId,String photoData){ + PersonInfo personInfo = new PersonInfo(); + if(ToolUtil.isNotEmpty(syncId)){ + personInfo.setPersonID(syncId); + } + if(ToolUtil.isNotEmpty(person.getUpdatetime())){ + personInfo.setLastChange(person.getUpdatetime().getTime()); + } + if(ToolUtil.isNotEmpty(person.getPersonCode()) && person.getPersonCode().length() <= FaceSyncConst.UPLOAD_PERSONCODE_MAXLENGTH){ + personInfo.setPersonCode(person.getPersonCode()); + }else { + personInfo.setPersonCode(String.valueOf(syncId)); + } + if(ToolUtil.isNotEmpty(person.getName())){ + personInfo.setPersonName(person.getName()); + } + if(ToolUtil.isNotEmpty(person.getRemarks()) && person.getRemarks().length() <= FaceSyncConst.UPLOAD_REMARK_MAXLENGTH){ + personInfo.setRemarks(person.getRemarks()); + }else { + personInfo.setRemarks(""); + } + + // 时间模板 + personInfo.setTimeTemplateNum(0); + List timeTemplateList = new ArrayList<>(); + timeTemplateList.add(personInfo.createTimeTemplate(0L,4294967295L,0L)); + personInfo.setTimeTemplateList(timeTemplateList); + + // 证件列表 + if(ToolUtil.isNotEmpty(person.getIdCardNo())){ + personInfo.setIdentificationNum(1); + List identificationInfoList = new ArrayList<>(); + identificationInfoList.add(personInfo.createIdentificationInfo(1,person.getIdCardNo())); + personInfo.setIdentificationList(identificationInfoList); + }else{ + personInfo.setIdentificationNum(0); + } + + // 图片列表 + if(ToolUtil.isNotEmpty(photoData)){ + personInfo.setImageNum(1); + List imageInfoList = new ArrayList<>(); + // 图片base64码 + if(photoData.startsWith("data") || photoData.startsWith("base64")){ + int splitIndex = photoData.indexOf(","); + photoData = photoData.substring(splitIndex+1); + } + imageInfoList.add(personInfo.createImageInfo(syncId,person.getPhoto(),Long.valueOf(photoData.length()),photoData)); + personInfo.setImageList(imageInfoList); + }else { + personInfo.setImageNum(0); + } + return personInfo; + } + + private String convErrorCode(Long errorCode){ + String errorMsg = ""; + switch (errorCode.intValue()){ + case 1000: + errorMsg = "算法初始化失败"; + break; + case 1001: + errorMsg = "人脸检测失败"; + break; + case 1002: + errorMsg = "图片未检测到人脸"; + break; + case 1003: + errorMsg = "jpeg照片解码失败"; + break; + case 1004: + errorMsg = "图片质量分数不满足"; + break; + case 1005: + errorMsg = "图片缩放失败"; + break; + case 1006: + errorMsg = "未启用智能"; + break; + case 1007: + errorMsg = "导入图片过小"; + break; + case 1008: + errorMsg = "导入图片过大"; + break; + case 1009: + errorMsg = "导入图片分辨率超过1920*1080"; + break; + case 1010: + errorMsg = "导入图片不存在"; + break; + case 1011: + errorMsg = "人脸元素个数已达到上限"; + break; + case 1012: + errorMsg = "智能棒算法模型不匹配"; + break; + case 1013: + errorMsg = "人脸导入库成员证件号非法"; + break; + case 1014: + errorMsg = "人脸导入库成员图片格式错误"; + break; + case 1015: + errorMsg = "通道布控已达设备能力上限"; + break; + case 1016: + errorMsg = "其它客户端正在进行操作人脸库"; + break; + case 1017: + errorMsg = "人脸库文件正在更新中"; + break; + case 1018: + errorMsg = "Json反序列化失败"; + break; + case 1019: + errorMsg = "Base64解码失败"; + break; + case 1020: + errorMsg = "人脸照片,编码后的大小和实际接收到的长度不一致,关注Data和Size大小是否正确"; + break; + default: + break; + } + return errorMsg; + + } + + @Override + public String checkPersonPhoto(List personIds) { + String error = null; + for (Long personId : personIds) { + Person person = commonPersonService.getPersonById(personId); + String photoData = photoSupportService.selectPhotoDataById(personId); + if(ToolUtil.isEmpty(photoData)){ + error = String.format("%s 未上传照片",person.getName()); + break; + } + if(photoData.startsWith("data") || photoData.startsWith("base64")){ + int splitIndex = photoData.indexOf(","); + photoData = photoData.substring(splitIndex+1); + } + if(!photoData.startsWith("/9j")){ + error = String.format("%s人员照片不符合要求,必须为jpg格式",person.getName()); + break; + } + + // 找到等号,把等号也去掉 + int equalIndex = photoData.indexOf('='); + if(equalIndex>=0) { + photoData=photoData.substring(0, equalIndex); + } + // 原来的字符流大小,单位为字节 + int strLength=photoData.length(); + // 计算后得到的文件流大小,单位为字节 + int fileLength=Integer.valueOf(strLength-(strLength/8)*2); + if(fileLength / 1024 < 20){ + error = String.format("%s人员照片不符合要求,照片必须大于20Kb",person.getName()); + break; + } + } + return error; + } + + @Override + public void receiveRecord(RecordNotification recordNotification){ +// if(recordNotification.getFaceInfoNum() != recordNotification.getLibMatInfoNum()){ +// logger.error("采集和匹配数据不一致,识别失败"); +// } else { + String deviceCode = recordNotification.getDeviceCode(); + List recordsList = new ArrayList<>(); + for (int i = 0; i < recordNotification.getLibMatInfoNum(); i++) { + //FaceInfo faceInfo = recordNotification.getFaceInfoList().get(i); + LibMatInfo libMatInfo = recordNotification.getLibMatInfoList().get(i); + if(libMatInfo.getMatchStatus() == 1){ + FaceInfo faceInfo = getFaceInfoByMatchId(recordNotification.getFaceInfoList(),libMatInfo.getId()); + Long personId = personSyncService.selectPersonId(libMatInfo.getMatchPersonId()); + if(ToolUtil.isNotEmpty(personId) && ToolUtil.isNotEmpty(faceInfo)){ + RecognitionRecords record = new RecognitionRecords(); + record.setPersonId(personId); + record.setDatetime(new Date(faceInfo.getTimestamp()*1000)); + record.setDevCode(deviceCode); + if(ToolUtil.isNotEmpty(faceInfo.getTemperature())){ + record.setTemperature(String.valueOf(faceInfo.getTemperature())); + } + record.setOriginalId(libMatInfo.getId()); + record.setSyncTime(new Date()); + + Device device = deviceSupportService.selectDeviceByCode(deviceCode); + if(ToolUtil.isNotEmpty(device)){ + if(ToolUtil.isNotEmpty(device.getDevIp())){ + record.setDevIp(device.getDevIp()); + } + } + + recordsList.add(record); + } + } + } + if(ToolUtil.isNotEmpty(recordsList)){ + recordSupportService.insertBatch(recordsList); + } + } + + @Override + public void receiveRecord(String recordNotificationStr) { + RecordNotification recordNotification = JSONObject.parseObject(recordNotificationStr,RecordNotification.class); + receiveRecord(recordNotification); + } + + public FaceInfo getFaceInfoByMatchId(List faceInfoList ,Long id){ + for (FaceInfo faceInfo : faceInfoList) { + if(faceInfo.getId().equals(id)){ + return faceInfo; + } + } + return null; + } + + @Override + public String initSubscription(List deviceIds) { + try { + List error = new ArrayList<>(); + for (Long deviceId : deviceIds) { + Device device = deviceSupportService.selectById(deviceId); + List subscribeIds = subscribeService.selectSubscribeIdsByDevCode(device.getDevCode());; + // 删除所有id + boolean flag = true; + for (Long subscribeId : subscribeIds) { + flag = flag && deleteSubscription(device.getDevIp(),subscribeId); + } + flag = flag && subscribeService.deleteByDevCode(device.getDevCode()); + // 创建订阅 + Long subscribeId = createSubscription(device.getDevIp(),serverHost,serverPort); + flag = flag && ToolUtil.isNotEmpty(subscribeId); + if(ToolUtil.isNotEmpty(subscribeId)){ + flag = flag && subscribeService.insertSubscribe(subscribeId,device.getDevCode()); + } + if(!flag){ + logger.error(String.format("device %s init subsrciption error",device.getDevCode())); + error.add(device.getDevCode()); + } + } + if(ToolUtil.isNotEmpty(error)){ + return StringUtils.join(error,",").concat("订阅失败"); + }else { + return null; + } + }catch (Exception e){ + e.printStackTrace(); + logger.error(e.getMessage()); + return "订阅失败"; + } + + } + + @Override + public boolean deleteSubscription(String deviceIp, Long subscribeId) { + String url = "http://" + deviceIp + FaceSyncConst.SUBSCRIBE_URL + subscribeId; + String responseContent = HttpClientUtil.sendHttpDelete(url); + logger.info(responseContent); + Gson gson = new Gson(); + JsonObject obj = gson.fromJson(responseContent, JsonObject.class); + logger.info(obj.get("Response").toString()); + FaceBaseResponse response = gson.fromJson(obj.get("Response"),FaceBaseResponse.class); + if(response.getResponseCode() == 0 && response.getStatusCode() == 0){ + return true; + }else { + logger.error(String.format("delele subscribe error, device '%s', subscribeId '%s', response '%s', status '%s'",deviceIp,subscribeId,response.getResponseString(),response.getStatusString())); + return false; + } + } + + @Override + public Long createSubscription(String deviceIp, String ip, String port) { + JsonObject request = new JsonObject(); + request.addProperty("AddressType",0); + request.addProperty("IPAddress",ip); + request.addProperty("Port",Long.valueOf(port)); + request.addProperty("Duration",4294967295L); + request.addProperty("Type",1024); + JsonObject subscribePersonCondition = new JsonObject(); + subscribePersonCondition.addProperty("LibIDNum",65535); + subscribePersonCondition.add("LibIDList",new JsonArray()); + request.add("SubscribePersonCondition",subscribePersonCondition); + Gson gson = new Gson(); + String requestStr = gson.toJson(request); + System.out.println(requestStr); + String url = "http://" + deviceIp + FaceSyncConst.SUBSCRIBE_URL ; + String responseContent = HttpClientUtil.sendHttpPostJson(url,requestStr); + logger.info(responseContent); + JsonObject obj = gson.fromJson(responseContent, JsonObject.class); + FaceBaseResponse response = gson.fromJson(obj.get("Response"),FaceBaseResponse.class); + if(response.getResponseCode() == 0 && response.getStatusCode()==0){ + JsonObject data = gson.fromJson(gson.toJson(response.getData()),JsonObject.class); + Long subsrcibeId = data.get("ID").getAsLong(); + logger.info(String.format("create subscribe success, device '%s', subsrcibeId '%s'",deviceIp,subsrcibeId)); + return subsrcibeId; + }else { + logger.error(String.format("create subscribe error, device '%s', response '%s', status '%s'",deviceIp,response.getResponseString(),response.getStatusString())); + return null; + } + } + +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/util/HttpClientUtil.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/util/HttpClientUtil.java new file mode 100644 index 0000000..e258174 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/util/HttpClientUtil.java @@ -0,0 +1,468 @@ +package com.casic.missiles.modular.system.util; + +import java.io.File; +import java.io.IOException; +import java.security.KeyManagementException; +import java.security.KeyStoreException; +import java.security.NoSuchAlgorithmException; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.apache.http.HttpEntity; +import org.apache.http.HttpStatus; +import org.apache.http.client.config.RequestConfig; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpDelete; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.config.Registry; +import org.apache.http.config.RegistryBuilder; +import org.apache.http.conn.socket.ConnectionSocketFactory; +import org.apache.http.conn.socket.PlainConnectionSocketFactory; +import org.apache.http.conn.ssl.SSLConnectionSocketFactory; +import org.apache.http.conn.ssl.SSLContextBuilder; +import org.apache.http.conn.ssl.TrustSelfSignedStrategy; +import org.apache.http.entity.ContentType; +import org.apache.http.entity.StringEntity; +import org.apache.http.entity.mime.MultipartEntityBuilder; +import org.apache.http.entity.mime.content.FileBody; +import org.apache.http.entity.mime.content.StringBody; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.DefaultHttpRequestRetryHandler; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; +import org.apache.http.util.EntityUtils; + +/** + * + * @author H__D + * @date 2016年10月19日 上午11:27:25 + * + */ +public class HttpClientUtil { + + // utf-8字符编码 + public static final String CHARSET_UTF_8 = "utf-8"; + + // HTTP内容类型。 + public static final String CONTENT_TYPE_TEXT_HTML = "text/xml"; + + // HTTP内容类型。相当于form表单的形式,提交数据 + public static final String CONTENT_TYPE_FORM_URL = "application/x-www-form-urlencoded"; + + // HTTP内容类型。相当于form表单的形式,提交数据 + public static final String CONTENT_TYPE_JSON_URL = "application/json;charset=utf-8"; + + + // 连接管理器 + private static PoolingHttpClientConnectionManager pool; + + // 请求配置 + private static RequestConfig requestConfig; + + static { + + try { + //System.out.println("初始化HttpClientTest~~~开始"); + SSLContextBuilder builder = new SSLContextBuilder(); + builder.loadTrustMaterial(null, new TrustSelfSignedStrategy()); + SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory( + builder.build()); + // 配置同时支持 HTTP 和 HTPPS + Registry socketFactoryRegistry = RegistryBuilder. create().register( + "http", PlainConnectionSocketFactory.getSocketFactory()).register( + "https", sslsf).build(); + // 初始化连接管理器 + pool = new PoolingHttpClientConnectionManager( + socketFactoryRegistry); + // 将最大连接数增加到200,实际项目最好从配置文件中读取这个值 + pool.setMaxTotal(200); + // 设置最大路由 + pool.setDefaultMaxPerRoute(2); + // 根据默认超时限制初始化requestConfig + int socketTimeout = 10000; + int connectTimeout = 10000; + int connectionRequestTimeout = 10000; + requestConfig = RequestConfig.custom().setConnectionRequestTimeout( + connectionRequestTimeout).setSocketTimeout(socketTimeout).setConnectTimeout( + connectTimeout).build(); + + //System.out.println("初始化HttpClientTest~~~结束"); + } catch (NoSuchAlgorithmException e) { + e.printStackTrace(); + } catch (KeyStoreException e) { + e.printStackTrace(); + } catch (KeyManagementException e) { + e.printStackTrace(); + } + + + // 设置请求超时时间 + requestConfig = RequestConfig.custom().setSocketTimeout(50000).setConnectTimeout(50000) + .setConnectionRequestTimeout(50000).build(); + } + + public static CloseableHttpClient getHttpClient() { + + CloseableHttpClient httpClient = HttpClients.custom() + // 设置连接池管理 + .setConnectionManager(pool) + // 设置请求配置 + .setDefaultRequestConfig(requestConfig) + // 设置重试次数 + .setRetryHandler(new DefaultHttpRequestRetryHandler(0, false)) + .build(); + + return httpClient; + } + + /** + * 发送Post请求 + * + * @param httpPost + * @return + */ + private static String sendHttpPost(HttpPost httpPost) { + + CloseableHttpClient httpClient = null; + CloseableHttpResponse response = null; + // 响应内容 + String responseContent = null; + try { + // 创建默认的httpClient实例. + httpClient = getHttpClient(); + // 配置请求信息 + httpPost.setConfig(requestConfig); + // 执行请求 + response = httpClient.execute(httpPost); + // 得到响应实例 + HttpEntity entity = response.getEntity(); + + // 可以获得响应头 + // Header[] headers = response.getHeaders(HttpHeaders.CONTENT_TYPE); + // for (Header header : headers) { + // System.out.println(header.getName()); + // } + + // 得到响应类型 + // System.out.println(ContentType.getOrDefault(response.getEntity()).getMimeType()); + + // 判断响应状态 + if (response.getStatusLine().getStatusCode() >= 300) { + throw new Exception( + "HTTP Request is not success, Response code is " + response.getStatusLine().getStatusCode()); + } + + if (HttpStatus.SC_OK == response.getStatusLine().getStatusCode()) { + responseContent = EntityUtils.toString(entity, CHARSET_UTF_8); + EntityUtils.consume(entity); + } + + } catch (Exception e) { + e.printStackTrace(); + } finally { + try { + // 释放资源 + if (response != null) { + response.close(); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + return responseContent; + } + + /** + * 发送Get请求 + * + * @param httpGet + * @return + */ + private static String sendHttpGet(HttpGet httpGet) { + + CloseableHttpClient httpClient = null; + CloseableHttpResponse response = null; + // 响应内容 + String responseContent = null; + try { + // 创建默认的httpClient实例. + httpClient = getHttpClient(); + // 配置请求信息 + httpGet.setConfig(requestConfig); + // 执行请求 + response = httpClient.execute(httpGet); + // 得到响应实例 + HttpEntity entity = response.getEntity(); + + // 可以获得响应头 + // Header[] headers = response.getHeaders(HttpHeaders.CONTENT_TYPE); + // for (Header header : headers) { + // System.out.println(header.getName()); + // } + + // 得到响应类型 + // System.out.println(ContentType.getOrDefault(response.getEntity()).getMimeType()); + + // 判断响应状态 + if (response.getStatusLine().getStatusCode() >= 300) { + throw new Exception( + "HTTP Request is not success, Response code is " + response.getStatusLine().getStatusCode()); + } + + if (HttpStatus.SC_OK == response.getStatusLine().getStatusCode()) { + responseContent = EntityUtils.toString(entity, CHARSET_UTF_8); + EntityUtils.consume(entity); + } + + } catch (Exception e) { + e.printStackTrace(); + } finally { + try { + // 释放资源 + if (response != null) { + response.close(); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + return responseContent; + } + + /** + * 发送Delete请求 + * + * @param httpDelete + * @return + */ + private static String sendHttpDelete(HttpDelete httpDelete) { + + CloseableHttpClient httpClient = null; + CloseableHttpResponse response = null; + // 响应内容 + String responseContent = null; + try { + // 创建默认的httpClient实例. + httpClient = getHttpClient(); + // 配置请求信息 + httpDelete.setConfig(requestConfig); + // 执行请求 + response = httpClient.execute(httpDelete); + // 得到响应实例 + HttpEntity entity = response.getEntity(); + + // 可以获得响应头 + // Header[] headers = response.getHeaders(HttpHeaders.CONTENT_TYPE); + // for (Header header : headers) { + // System.out.println(header.getName()); + // } + + // 得到响应类型 + // System.out.println(ContentType.getOrDefault(response.getEntity()).getMimeType()); + + // 判断响应状态 + if (response.getStatusLine().getStatusCode() >= 300) { + throw new Exception( + "HTTP Request is not success, Response code is " + response.getStatusLine().getStatusCode()); + } + + if (HttpStatus.SC_OK == response.getStatusLine().getStatusCode()) { + responseContent = EntityUtils.toString(entity, CHARSET_UTF_8); + EntityUtils.consume(entity); + } + + } catch (Exception e) { + e.printStackTrace(); + } finally { + try { + // 释放资源 + if (response != null) { + response.close(); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + return responseContent; + } + + + + /** + * 发送 post请求 + * + * @param httpUrl 地址 + */ + public static String sendHttpPost(String httpUrl) { + // 创建httpPost + HttpPost httpPost = new HttpPost(httpUrl); + return sendHttpPost(httpPost); + } + + /** + * 发送 get请求 + * + * @param httpUrl + */ + public static String sendHttpGet(String httpUrl) { + // 创建get请求 + HttpGet httpGet = new HttpGet(httpUrl); + return sendHttpGet(httpGet); + } + + /** + * 发送 DELETE 请求 + * + * @param httpUrl + */ + public static String sendHttpDelete(String httpUrl) { + // 创建delete请求 + HttpDelete httpDelete = new HttpDelete(httpUrl); + return sendHttpDelete(httpDelete); + } + + + + /** + * 发送 post请求(带文件) + * + * @param httpUrl + * 地址 + * @param maps + * 参数 + * @param fileLists + * 附件 + */ + public static String sendHttpPost(String httpUrl, Map maps, List fileLists) { + HttpPost httpPost = new HttpPost(httpUrl);// 创建httpPost + MultipartEntityBuilder meBuilder = MultipartEntityBuilder.create(); + if (maps != null) { + for (String key : maps.keySet()) { + meBuilder.addPart(key, new StringBody(maps.get(key), ContentType.TEXT_PLAIN)); + } + } + if (fileLists != null) { + for (File file : fileLists) { + FileBody fileBody = new FileBody(file); + meBuilder.addPart("files", fileBody); + } + } + HttpEntity reqEntity = meBuilder.build(); + httpPost.setEntity(reqEntity); + return sendHttpPost(httpPost); + } + + /** + * 发送 post请求 + * + * @param httpUrl + * 地址 + * @param params + * 参数(格式:key1=value1&key2=value2) + * + */ + public static String sendHttpPost(String httpUrl, String params) { + HttpPost httpPost = new HttpPost(httpUrl);// 创建httpPost + try { + // 设置参数 + if (params != null && params.trim().length() > 0) { + StringEntity stringEntity = new StringEntity(params, "UTF-8"); + stringEntity.setContentType(CONTENT_TYPE_FORM_URL); + httpPost.setEntity(stringEntity); + } + } catch (Exception e) { + throw e; + } + return sendHttpPost(httpPost); + } + + /** + * 发送 post请求 + * + * @param maps + * 参数 + */ + public static String sendHttpPost(String httpUrl, Map maps) { + String parem = convertStringParamter(maps); + return sendHttpPost(httpUrl, parem); + } + + + + + /** + * 发送 post请求 发送json数据 + * + * @param httpUrl 地址 + * @param paramsJson 参数(格式 json) + * + */ + public static String sendHttpPostJson(String httpUrl, String paramsJson) { + HttpPost httpPost = new HttpPost(httpUrl);// 创建httpPost + try { + // 设置参数 + if (paramsJson != null && paramsJson.trim().length() > 0) { + StringEntity stringEntity = new StringEntity(paramsJson, "UTF-8"); + stringEntity.setContentType(CONTENT_TYPE_JSON_URL); + httpPost.setEntity(stringEntity); + } + } catch (Exception e) { + e.printStackTrace(); + } + return sendHttpPost(httpPost); + } + + /** + * 发送 post请求 发送xml数据 + * + * @param httpUrl 地址 + * @param paramsXml 参数(格式 Xml) + * + */ + public static String sendHttpPostXml(String httpUrl, String paramsXml) { + HttpPost httpPost = new HttpPost(httpUrl);// 创建httpPost + try { + // 设置参数 + if (paramsXml != null && paramsXml.trim().length() > 0) { + StringEntity stringEntity = new StringEntity(paramsXml, "UTF-8"); + stringEntity.setContentType(CONTENT_TYPE_TEXT_HTML); + httpPost.setEntity(stringEntity); + } + } catch (Exception e) { + e.printStackTrace(); + } + return sendHttpPost(httpPost); + } + + + /** + * 将map集合的键值对转化成:key1=value1&key2=value2 的形式 + * + * @param parameterMap 需要转化的键值对集合 + * @return 字符串 + */ + public static String convertStringParamter(Map parameterMap) { + StringBuffer parameterBuffer = new StringBuffer(); + if (parameterMap != null) { + Iterator iterator = parameterMap.keySet().iterator(); + String key = null; + String value = null; + while (iterator.hasNext()) { + key = (String) iterator.next(); + if (parameterMap.get(key) != null) { + value = (String) parameterMap.get(key); + } else { + value = ""; + } + parameterBuffer.append(key).append("=").append(value); + if (iterator.hasNext()) { + parameterBuffer.append("&"); + } + } + } + return parameterBuffer.toString(); + } + +} diff --git a/casic-face-sync/pom.xml b/casic-face-sync/pom.xml new file mode 100644 index 0000000..24dc884 --- /dev/null +++ b/casic-face-sync/pom.xml @@ -0,0 +1,74 @@ + + + 4.0.0 + + com.casic + casic-iris-parent + 1.0.0-SNAPSHOT + ../pom.xml + + + + casic-face-sync + ${pro.version} + jar + casic-face-sync + + + + + + com.casic + casic-core + ${core.version} + + + + com.casic + casic-admin-support + ${admin.version} + + + com.casic + casic-iris-support + ${pro.version} + + + + org.apache.httpcomponents + httpclient + 4.5.3 + + + + org.apache.httpcomponents + httpcore + 4.4.8 + + + + org.apache.httpcomponents + httpmime + 4.5.3 + + + + com.google.code.gson + gson + + + + + + + + src/main/java + + **/*.xml + + + + + \ No newline at end of file diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/constant/FaceSyncConst.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/constant/FaceSyncConst.java new file mode 100644 index 0000000..352d47d --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/constant/FaceSyncConst.java @@ -0,0 +1,29 @@ +package com.casic.missiles.modular.system.constant; + +public class FaceSyncConst { + + /** + * 单次最大批量上传人员数 + */ + public static final int UPLOAD_MAX_PERSON = 6; + + /** + * 上传人员库 + */ + public static final String UPLOAD_STAFF_LIB = "3"; + public static final String UPLOAD_VISITOR_LIB = "4"; + + public static final String UPLOAD_URL_PREFIX = "/LAPI/V1.0/PeopleLibraries/"; + + public static final String UPLOAD_URL_SUFFIX = "/People"; + + public static final int UPLOAD_PERSONCODE_MAXLENGTH = 15; + + public static final int UPLOAD_REMARK_MAXLENGTH = 63; + + public static final String SUBSCRIBE_URL = "/LAPI/V1.0/System/Event/Subscription/"; + + public static final String STAFF_PERSON_TYPE = "1"; + + public static final String VISITOR_PERSON_TYPE = "0"; +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/controller/FaceSyncController.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/controller/FaceSyncController.java new file mode 100644 index 0000000..1b35431 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/controller/FaceSyncController.java @@ -0,0 +1,117 @@ +package com.casic.missiles.modular.system.controller; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson.serializer.SerializerFeature; +import com.casic.missiles.core.base.response.ResponseData; +import com.casic.missiles.core.common.service.ICommonPermissionService; +import com.casic.missiles.core.common.service.ICommonPersonService; +import com.casic.missiles.core.datascope.DataScope; +import com.casic.missiles.core.util.ToolUtil; +import com.casic.missiles.modular.system.request.PersonInfo; +import com.casic.missiles.modular.system.response.RecordNotification; +import com.casic.missiles.modular.system.service.IFaceSyncService; +import com.casic.missiles.modular.system.service.IIrisPersonSupportService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.*; +import com.casic.missiles.modular.system.constant.FaceSyncConst; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + + + +@Controller +public class FaceSyncController { + private final static Logger logger = LoggerFactory.getLogger(FaceSyncController.class); + + @Autowired + private IFaceSyncService syncService; + @Autowired + private ICommonPersonService commonPersonService; + @Autowired + private IIrisPersonSupportService personSupportService; + @Autowired + private ICommonPermissionService permissionService; + + @RequestMapping("/face/upload") + @ResponseBody + public Object upload(@RequestParam("personIds") List personIds, + @RequestParam("deviceIds") List deviceIds, + @RequestParam("personType")String personType ){ + // 检查数量 +// if(personIds.size()>FaceSyncConst.UPLOAD_MAX_PERSON){ +// return ResponseData.error(String.format("每次最多上传%s个人",FaceSyncConst.UPLOAD_MAX_PERSON)); +// } + // 检查照片格式及大小 + String photoCheck = syncService.checkPersonPhoto(personIds); + if(ToolUtil.isNotEmpty(photoCheck)){ + return ResponseData.error(photoCheck); + } + else{ + // 上传数据 + String error = syncService.uploadPerson(personIds,deviceIds,personType); + if(ToolUtil.isNotEmpty(error)){ + return ResponseData.error(error); + } + } + return ResponseData.success(); + } + + @RequestMapping("/face/uploadAll") + @ResponseBody + public Object uploadAll(@RequestParam("deviceIds") List deviceIds){ + DataScope dataScope = permissionService.getCurrUserDataScope(); + + List staffPersonIds = personSupportService.listIdsByType(dataScope,FaceSyncConst.STAFF_PERSON_TYPE); + List visitorPersonIds = personSupportService.listIdsByType(dataScope,FaceSyncConst.VISITOR_PERSON_TYPE); + // 1.检查照片,分别检查员工、访客 + String staffPhotoCheck = syncService.checkPersonPhoto(staffPersonIds); + if(ToolUtil.isNotEmpty(staffPhotoCheck)){ + return ResponseData.error(staffPhotoCheck); + } + String visitorPhotoCheck = syncService.checkPersonPhoto(visitorPersonIds); + if(ToolUtil.isNotEmpty(visitorPhotoCheck)){ + return ResponseData.error(visitorPhotoCheck); + } + + // 2. 下发数据 + String staffError = syncService.uploadPerson(staffPersonIds,deviceIds,FaceSyncConst.STAFF_PERSON_TYPE); + if(ToolUtil.isNotEmpty(staffError)){ + return ResponseData.error(staffError); + } + String visitorError = syncService.uploadPerson(visitorPersonIds,deviceIds,FaceSyncConst.VISITOR_PERSON_TYPE); + if(ToolUtil.isNotEmpty(visitorError)){ + return ResponseData.error(visitorError); + } + + return ResponseData.success(); + } + + // 错误信息返回 + @RequestMapping("/subsrcibe/init") + @ResponseBody + public Object upload(@RequestParam("deviceIds") List deviceIds){ + String errorMsg = syncService.initSubscription(deviceIds); + if(ToolUtil.isNotEmpty(errorMsg)){ + return ResponseData.error(errorMsg); + } + return ResponseData.success(); + } + + + @RequestMapping(value = "/LAPI/V1.0/System/Event/Notification/PersonVerification", method = RequestMethod.POST) + @ResponseBody + public void verification(@RequestBody String recordNotification){ + logger.info(recordNotification); + RecordNotification record = JSONObject.parseObject(recordNotification,RecordNotification.class); + syncService.receiveRecord(record); + //return ResponseData.success(); + } + + +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FacePersonSyncMapper.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FacePersonSyncMapper.java new file mode 100644 index 0000000..af53702 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FacePersonSyncMapper.java @@ -0,0 +1,17 @@ +package com.casic.missiles.modular.system.dao; + +import com.casic.missiles.modular.system.model.FacePersonSync; +import com.baomidou.mybatisplus.mapper.BaseMapper; + +/** + *

+ * Mapper 接口 + *

+ * + * @author zyj123 + * @since 2020-07-24 + */ +public interface FacePersonSyncMapper extends BaseMapper { + + Long getMaxSyncId(); +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FaceSubscribeMapper.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FaceSubscribeMapper.java new file mode 100644 index 0000000..0c6374a --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FaceSubscribeMapper.java @@ -0,0 +1,16 @@ +package com.casic.missiles.modular.system.dao; + +import com.casic.missiles.modular.system.model.FaceSubscribe; +import com.baomidou.mybatisplus.mapper.BaseMapper; + +/** + *

+ * Mapper 接口 + *

+ * + * @author zyj123 + * @since 2020-07-25 + */ +public interface FaceSubscribeMapper extends BaseMapper { + +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FacePersonSyncMapper.xml b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FacePersonSyncMapper.xml new file mode 100644 index 0000000..ac46ad0 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FacePersonSyncMapper.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + PERSON_ID AS personId, SYNC_ID AS syncId + + + + + diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FaceSubscribeMapper.xml b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FaceSubscribeMapper.xml new file mode 100644 index 0000000..16024e2 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FaceSubscribeMapper.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + SUBSCRIBE_ID AS subscribeId, DEVICE_CODE AS deviceCode, UPDATE_TIME AS updateTime + + + diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FacePersonSync.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FacePersonSync.java new file mode 100644 index 0000000..7cdb821 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FacePersonSync.java @@ -0,0 +1,68 @@ +package com.casic.missiles.modular.system.model; + +import java.io.Serializable; + +import com.baomidou.mybatisplus.annotations.TableId; +import com.baomidou.mybatisplus.annotations.TableField; +import com.baomidou.mybatisplus.activerecord.Model; +import com.baomidou.mybatisplus.annotations.TableName; +import java.io.Serializable; + +/** + *

+ * + *

+ * + * @author zyj123 + * @since 2020-07-24 + */ +@TableName("face_person_sync") +public class FacePersonSync extends Model { + + private static final long serialVersionUID = 1L; + + /** + * 人员id + */ + @TableId("PERSON_ID") + private Long personId; + /** + * 人员同步id + */ + @TableField("SYNC_ID") + private Long syncId; + + public FacePersonSync(Long personId, Long syncId) { + this.personId = personId; + this.syncId = syncId; + } + + public Long getPersonId() { + return personId; + } + + public void setPersonId(Long personId) { + this.personId = personId; + } + + public Long getSyncId() { + return syncId; + } + + public void setSyncId(Long syncId) { + this.syncId = syncId; + } + + @Override + protected Serializable pkVal() { + return this.personId; + } + + @Override + public String toString() { + return "FacePersonSync{" + + "personId=" + personId + + ", syncId=" + syncId + + "}"; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FaceSubscribe.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FaceSubscribe.java new file mode 100644 index 0000000..ccc7792 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FaceSubscribe.java @@ -0,0 +1,79 @@ +package com.casic.missiles.modular.system.model; + +import java.io.Serializable; + +import java.util.Date; +import com.baomidou.mybatisplus.annotations.TableId; +import com.baomidou.mybatisplus.annotations.TableField; +import com.baomidou.mybatisplus.activerecord.Model; +import com.baomidou.mybatisplus.annotations.TableName; +import java.io.Serializable; + +/** + *

+ * + *

+ * + * @author zyj123 + * @since 2020-07-25 + */ +@TableName("face_subscribe") +public class FaceSubscribe extends Model { + + private static final long serialVersionUID = 1L; + + /** + * 订阅id + */ + @TableId("SUBSCRIBE_ID") + private Long subscribeId; + /** + * 设备编号 + */ + @TableField("DEVICE_CODE") + private String deviceCode; + /** + * 更新时间 + */ + @TableField("UPDATE_TIME") + private Date updateTime; + + + public Long getSubscribeId() { + return subscribeId; + } + + public void setSubscribeId(Long subscribeId) { + this.subscribeId = subscribeId; + } + + public String getDeviceCode() { + return deviceCode; + } + + public void setDeviceCode(String deviceCode) { + this.deviceCode = deviceCode; + } + + public Date getUpdateTime() { + return updateTime; + } + + public void setUpdateTime(Date updateTime) { + this.updateTime = updateTime; + } + + @Override + protected Serializable pkVal() { + return this.subscribeId; + } + + @Override + public String toString() { + return "FaceSubscribe{" + + "subscribeId=" + subscribeId + + ", deviceCode=" + deviceCode + + ", updateTime=" + updateTime + + "}"; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/request/PersonInfo.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/request/PersonInfo.java new file mode 100644 index 0000000..80d9eff --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/request/PersonInfo.java @@ -0,0 +1,271 @@ +package com.casic.missiles.modular.system.request; + +import com.alibaba.fastjson.annotation.JSONField; +import com.baomidou.mybatisplus.annotations.TableField; +import com.google.gson.annotations.SerializedName; + +import java.util.List; + +public class PersonInfo { + + //@JSONField(name = "PersonID") + @SerializedName("PersonID") + private Long personID; + + //@JSONField(name = "LastChange") + @SerializedName("LastChange") + private Long lastChange; + + //@JSONField(name = "PersonCode") + @SerializedName("PersonCode") + private String personCode; + + //@JSONField(name = "PersonName") + @SerializedName("PersonName") + private String personName; + + //@JSONField(name = "Remarks") + @SerializedName("Remarks") + private String remarks; + + //@JSONField(name = "TimeTemplateNum") + @SerializedName("TimeTemplateNum") + private Integer timeTemplateNum; + + //@JSONField(name = "TimeTemplateList") + @SerializedName("TimeTemplateList") + private List timeTemplateList; + + //@JSONField(name = "IdentificationNum") + @SerializedName("IdentificationNum") + private Integer identificationNum; + + //@JSONField(name = "IdentificationList") + @SerializedName("IdentificationList") + private List identificationList; + + //@JSONField(name = "ImageNum") + @SerializedName("ImageNum") + private Integer imageNum; + + //@JSONField(name = "ImageList") + @SerializedName("ImageList") + private List imageList; + + public Long getPersonID() { + return personID; + } + + public void setPersonID(Long personID) { + this.personID = personID; + } + + public Long getLastChange() { + return lastChange; + } + + public void setLastChange(Long lastChange) { + this.lastChange = lastChange; + } + + public String getPersonCode() { + return personCode; + } + + public void setPersonCode(String personCode) { + this.personCode = personCode; + } + + public String getPersonName() { + return personName; + } + + public void setPersonName(String personName) { + this.personName = personName; + } + + public String getRemarks() { + return remarks; + } + + public void setRemarks(String remarks) { + this.remarks = remarks; + } + + public Integer getTimeTemplateNum() { + return timeTemplateNum; + } + + public void setTimeTemplateNum(Integer timeTemplateNum) { + this.timeTemplateNum = timeTemplateNum; + } + + public List getTimeTemplateList() { + return timeTemplateList; + } + + public void setTimeTemplateList(List timeTemplateList) { + this.timeTemplateList = timeTemplateList; + } + + public Integer getIdentificationNum() { + return identificationNum; + } + + public void setIdentificationNum(Integer identificationNum) { + this.identificationNum = identificationNum; + } + + public List getIdentificationList() { + return identificationList; + } + + public void setIdentificationList(List identificationList) { + this.identificationList = identificationList; + } + + public Integer getImageNum() { + return imageNum; + } + + public void setImageNum(Integer imageNum) { + this.imageNum = imageNum; + } + + public List getImageList() { + return imageList; + } + + public void setImageList(List imageList) { + this.imageList = imageList; + } + + public class TimeTemplate{ + @JSONField(name = "BeginTime") + private Long beginTime; + @JSONField(name = "EndTime") + private Long endTime; + @JSONField(name = "Index") + private Long index; + + public TimeTemplate(Long beginTime, Long endTime, Long index) { + this.beginTime = beginTime; + this.endTime = endTime; + this.index = index; + } + + public Long getBeginTime() { + return beginTime; + } + + public void setBeginTime(Long beginTime) { + this.beginTime = beginTime; + } + + public Long getEndTime() { + return endTime; + } + + public void setEndTime(Long endTime) { + this.endTime = endTime; + } + + public Long getIndex() { + return index; + } + + public void setIndex(Long index) { + this.index = index; + } + } + + public TimeTemplate createTimeTemplate(Long beginTime, Long endTime, Long index){ + return new TimeTemplate(beginTime, endTime, index); + } + + public class IdentificationInfo { + @JSONField(name = "Type") + private Integer type; + @JSONField(name = "Number") + private String number; + + public IdentificationInfo(Integer type, String number) { + this.type = type; + this.number = number; + } + + public Integer getType() { + return type; + } + + public void setType(Integer type) { + this.type = type; + } + + public String getNumber() { + return number; + } + + public void setNumber(String number) { + this.number = number; + } + } + + public IdentificationInfo createIdentificationInfo(Integer type, String number){ + return new IdentificationInfo(type,number); + } + + public class ImageInfo{ + @JSONField(name = "FaceID") + private Long faceID; + @JSONField(name = "Name") + private String name; + @JSONField(name = "Size") + private Long size; + @JSONField(name = "Data") + private String data; + + public ImageInfo(Long faceID, String name, Long size, String data) { + this.faceID = faceID; + this.name = name; + this.size = size; + this.data = data; + } + + public Long getFaceID() { + return faceID; + } + + public void setFaceID(Long faceID) { + this.faceID = faceID; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Long getSize() { + return size; + } + + public void setSize(Long size) { + this.size = size; + } + + public String getData() { + return data; + } + + public void setData(String data) { + this.data = data; + } + } + + public ImageInfo createImageInfo(Long faceID, String name, Long size, String data){ + return new ImageInfo(faceID, name, size, data); + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceBaseResponse.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceBaseResponse.java new file mode 100644 index 0000000..fe93b8a --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceBaseResponse.java @@ -0,0 +1,90 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; +import com.google.gson.annotations.SerializedName; + +public class FaceBaseResponse { + @JSONField(name = "ResponseURL") + @SerializedName("ResponseURL") + private String responseUrl; + + @JSONField(name = "CreatedID") + @SerializedName("CreatedID") + private int createdId; + + @JSONField(name = "ResponseCode") + @SerializedName("ResponseCode") + private int responseCode; + + @JSONField(name = "ResponseString") + @SerializedName("ResponseString") + private String responseString; + + @JSONField(name = "StatusCode") + @SerializedName("StatusCode") + private int statusCode; + + @JSONField(name = "StatusString") + @SerializedName("StatusString") + private String statusString; + + //@JSONField(name = "Data") + @SerializedName("Data") + private T data; + + public String getResponseUrl() { + return responseUrl; + } + + public void setResponseUrl(String responseUrl) { + this.responseUrl = responseUrl; + } + + public int getCreatedId() { + return createdId; + } + + public void setCreatedId(int createdId) { + this.createdId = createdId; + } + + public int getResponseCode() { + return responseCode; + } + + public void setResponseCode(int responseCode) { + this.responseCode = responseCode; + } + + public String getResponseString() { + return responseString; + } + + public void setResponseString(String responseString) { + this.responseString = responseString; + } + + public int getStatusCode() { + return statusCode; + } + + public void setStatusCode(int statusCode) { + this.statusCode = statusCode; + } + + public String getStatusString() { + return statusString; + } + + public void setStatusString(String statusString) { + this.statusString = statusString; + } + + public T getData() { + return data; + } + + public void setData(T data) { + this.data = data; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceInfo.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceInfo.java new file mode 100644 index 0000000..f128c92 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceInfo.java @@ -0,0 +1,128 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; + +import java.util.List; + +public class FaceInfo { + @JSONField(name = "ID") + private Long id; + @JSONField(name = "Timestamp") + private Long timestamp; + @JSONField(name = "CapSrc") + private Long capSrc; + @JSONField(name = "FeatureNum") + private Long featureNum; + @JSONField(name = "FeatureList") + private List featureList; + @JSONField(name = "FeatureVersion") + private String featureVersion; + @JSONField(name = "Feature") + private String feature; + @JSONField(name = "Temperature") + private Float temperature; + @JSONField(name = "MaskFlag") + private Long maskFlag; + @JSONField(name = "PanoImage") + private Object panoImage; + @JSONField(name = "FaceImage") + private Object faceImage; + @JSONField(name = "FaceArea") + private Object faceArea; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Long getTimestamp() { + return timestamp; + } + + public void setTimestamp(Long timestamp) { + this.timestamp = timestamp; + } + + public Long getCapSrc() { + return capSrc; + } + + public void setCapSrc(Long capSrc) { + this.capSrc = capSrc; + } + + public Long getFeatureNum() { + return featureNum; + } + + public void setFeatureNum(Long featureNum) { + this.featureNum = featureNum; + } + + public List getFeatureList() { + return featureList; + } + + public void setFeatureList(List featureList) { + this.featureList = featureList; + } + + public String getFeatureVersion() { + return featureVersion; + } + + public void setFeatureVersion(String featureVersion) { + this.featureVersion = featureVersion; + } + + public String getFeature() { + return feature; + } + + public void setFeature(String feature) { + this.feature = feature; + } + + public Float getTemperature() { + return temperature; + } + + public void setTemperature(Float temperature) { + this.temperature = temperature; + } + + public Long getMaskFlag() { + return maskFlag; + } + + public void setMaskFlag(Long maskFlag) { + this.maskFlag = maskFlag; + } + + public Object getPanoImage() { + return panoImage; + } + + public void setPanoImage(Object panoImage) { + this.panoImage = panoImage; + } + + public Object getFaceImage() { + return faceImage; + } + + public void setFaceImage(Object faceImage) { + this.faceImage = faceImage; + } + + public Object getFaceArea() { + return faceArea; + } + + public void setFaceArea(Object faceArea) { + this.faceArea = faceArea; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/LibMatInfo.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/LibMatInfo.java new file mode 100644 index 0000000..ce6dd33 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/LibMatInfo.java @@ -0,0 +1,69 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; + +public class LibMatInfo { + @JSONField(name = "ID") + private Long id; + @JSONField(name = "LibID") + private Long libId; + @JSONField(name = "LibType") + private Long libType; + @JSONField(name = "MatchStatus") + private Long matchStatus; + @JSONField(name = "MatchPersonID") + private Long matchPersonId; + @JSONField(name = "MatchFaceID") + private Long matchFaceId; + + // MatchPersonInfo 暂时忽略不用 + + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Long getLibId() { + return libId; + } + + public void setLibId(Long libId) { + this.libId = libId; + } + + public Long getLibType() { + return libType; + } + + public void setLibType(Long libType) { + this.libType = libType; + } + + public Long getMatchStatus() { + return matchStatus; + } + + public void setMatchStatus(Long matchStatus) { + this.matchStatus = matchStatus; + } + + public Long getMatchPersonId() { + return matchPersonId; + } + + public void setMatchPersonId(Long matchPersonId) { + this.matchPersonId = matchPersonId; + } + + public Long getMatchFaceId() { + return matchFaceId; + } + + public void setMatchFaceId(Long matchFaceId) { + this.matchFaceId = matchFaceId; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/PersonResponseData.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/PersonResponseData.java new file mode 100644 index 0000000..186faed --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/PersonResponseData.java @@ -0,0 +1,31 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; +import com.google.gson.annotations.SerializedName; + +import java.util.List; + +public class PersonResponseData { + @JSONField(name = "Num") + @SerializedName("Num") + private int num; + @JSONField(name = "PersonList") + @SerializedName("PersonList") + private List personList; + + public int getNum() { + return num; + } + + public void setNum(int num) { + this.num = num; + } + + public List getPersonList() { + return personList; + } + + public void setPersonList(List personList) { + this.personList = personList; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/PersonResponseInfo.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/PersonResponseInfo.java new file mode 100644 index 0000000..7ba3edc --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/PersonResponseInfo.java @@ -0,0 +1,67 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; +import com.google.gson.annotations.SerializedName; + +import java.util.List; + +public class PersonResponseInfo { + @JSONField(name = "PersonID") + @SerializedName("PersonID") + private Long personId; + @JSONField(name = "FaceNum") + @SerializedName("FaceNum") + private Long faceNum; + @JSONField(name = "FaceList") + @SerializedName("FaceList") + private List faceList; + + public Long getPersonId() { + return personId; + } + + public void setPersonId(Long personId) { + this.personId = personId; + } + + public Long getFaceNum() { + return faceNum; + } + + public void setFaceNum(Long faceNum) { + this.faceNum = faceNum; + } + + public List getFaceList() { + return faceList; + } + + public void setFaceList(List faceList) { + this.faceList = faceList; + } + + public class PersonResponseFace{ + @JSONField(name = "FaceID") + @SerializedName("FaceID") + private Long faceId; + @JSONField(name = "ResultCode") + @SerializedName("ResultCode") + private Long resultCode; + + public Long getFaceId() { + return faceId; + } + + public void setFaceId(Long faceId) { + this.faceId = faceId; + } + + public Long getResultCode() { + return resultCode; + } + + public void setResultCode(Long resultCode) { + this.resultCode = resultCode; + } + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/RecordNotification.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/RecordNotification.java new file mode 100644 index 0000000..ca52d29 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/RecordNotification.java @@ -0,0 +1,138 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; + +import java.util.List; + +public class RecordNotification { + @JSONField(name = "Reference") + private String reference; + @JSONField(name = "Seq") + private int seq; + @JSONField(name = "DeviceCode") + private String deviceCode; + @JSONField(name = "Timestamp") + private Long timestamp; + @JSONField(name = "NotificationType") + private int notificationType; + @JSONField(name = "FaceInfoNum") + private int faceInfoNum; + @JSONField(name = "FaceInfoList") + private List faceInfoList; + @JSONField(name = "CardInfoNum") + private int cardInfoNum; + @JSONField(name = "CardInfoList") + private List cardInfoList; + @JSONField(name = "GateInfoNum") + private int gateInfoNum; + @JSONField(name = "GateInfoList") + private List gateInfoList; + @JSONField(name = "LibMatInfoNum") + private int libMatInfoNum; + @JSONField(name = "LibMatInfoList") + private List libMatInfoList; + + public String getReference() { + return reference; + } + + public void setReference(String reference) { + this.reference = reference; + } + + public int getSeq() { + return seq; + } + + public void setSeq(int seq) { + this.seq = seq; + } + + public String getDeviceCode() { + return deviceCode; + } + + public void setDeviceCode(String deviceCode) { + this.deviceCode = deviceCode; + } + + public Long getTimestamp() { + return timestamp; + } + + public void setTimestamp(Long timestamp) { + this.timestamp = timestamp; + } + + public int getNotificationType() { + return notificationType; + } + + public void setNotificationType(int notificationType) { + this.notificationType = notificationType; + } + + public int getFaceInfoNum() { + return faceInfoNum; + } + + public void setFaceInfoNum(int faceInfoNum) { + this.faceInfoNum = faceInfoNum; + } + + public List getFaceInfoList() { + return faceInfoList; + } + + public void setFaceInfoList(List faceInfoList) { + this.faceInfoList = faceInfoList; + } + + public int getCardInfoNum() { + return cardInfoNum; + } + + public void setCardInfoNum(int cardInfoNum) { + this.cardInfoNum = cardInfoNum; + } + + public List getCardInfoList() { + return cardInfoList; + } + + public void setCardInfoList(List cardInfoList) { + this.cardInfoList = cardInfoList; + } + + public int getGateInfoNum() { + return gateInfoNum; + } + + public void setGateInfoNum(int gateInfoNum) { + this.gateInfoNum = gateInfoNum; + } + + public List getGateInfoList() { + return gateInfoList; + } + + public void setGateInfoList(List gateInfoList) { + this.gateInfoList = gateInfoList; + } + + public int getLibMatInfoNum() { + return libMatInfoNum; + } + + public void setLibMatInfoNum(int libMatInfoNum) { + this.libMatInfoNum = libMatInfoNum; + } + + public List getLibMatInfoList() { + return libMatInfoList; + } + + public void setLibMatInfoList(List libMatInfoList) { + this.libMatInfoList = libMatInfoList; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/runner/InitSubscribeRunner.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/runner/InitSubscribeRunner.java new file mode 100644 index 0000000..c7d0565 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/runner/InitSubscribeRunner.java @@ -0,0 +1,43 @@ +package com.casic.missiles.modular.system.runner; + +import com.casic.missiles.modular.system.model.Device; +import com.casic.missiles.modular.system.service.IDeviceSupportService; +import com.casic.missiles.modular.system.service.IFaceSyncService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.ApplicationArguments; +import org.springframework.boot.ApplicationRunner; +import org.springframework.stereotype.Component; + +import java.util.ArrayList; +import java.util.List; + +@Component +public class InitSubscribeRunner implements ApplicationRunner { + private static Logger logger = LoggerFactory.getLogger(InitSubscribeRunner.class); + + @Value("${iris.face.initSubscribe}") + private String initSubscribe; + @Autowired + private IDeviceSupportService deviceSupportService; + @Autowired + private IFaceSyncService faceSyncService; + + /** + * 启动项目时,根据需要初始化设备订阅信息 + * @param applicationArguments + * @throws Exception + */ + @Override + public void run(ApplicationArguments applicationArguments) throws Exception { + logger.info("==================initSubscribe: "); + if(Boolean.valueOf(initSubscribe)){ + List deviceList = deviceSupportService.selectDeviceByType("5"); + List deviceIds = new ArrayList<>(); + deviceList.forEach(device -> deviceIds.add(Long.valueOf(device.getId()))); + faceSyncService.initSubscription(deviceIds); + } + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFacePersonSyncService.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFacePersonSyncService.java new file mode 100644 index 0000000..6b2461b --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFacePersonSyncService.java @@ -0,0 +1,18 @@ +package com.casic.missiles.modular.system.service; + +import com.casic.missiles.modular.system.model.FacePersonSync; +import com.baomidou.mybatisplus.service.IService; + +/** + *

+ * 服务类 + *

+ * + * @author zyj123 + * @since 2020-07-24 + */ +public interface IFacePersonSyncService extends IService { + Long selectSyncId(Long personId); + Long selectPersonId(Long syncId); + Long getMaxSyncId(Long personId); +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFaceSubscribeService.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFaceSubscribeService.java new file mode 100644 index 0000000..e0461ed --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFaceSubscribeService.java @@ -0,0 +1,24 @@ +package com.casic.missiles.modular.system.service; + +import com.casic.missiles.modular.system.model.FaceSubscribe; +import com.baomidou.mybatisplus.service.IService; + +import java.util.List; + +/** + *

+ * 服务类 + *

+ * + * @author zyj123 + * @since 2020-07-25 + */ +public interface IFaceSubscribeService extends IService { + + List selectSubscribeIdsByDevCode(String devCode); + + boolean deleteByDevCode(String devCode); + + boolean insertSubscribe(Long subscribeId, String devCode); + +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFaceSyncService.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFaceSyncService.java new file mode 100644 index 0000000..effd921 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFaceSyncService.java @@ -0,0 +1,21 @@ +package com.casic.missiles.modular.system.service; + +import com.casic.missiles.modular.system.response.RecordNotification; + +import java.util.List; + +public interface IFaceSyncService { + String uploadPerson(List personIds, List deviceIds,String personType); + + String checkPersonPhoto(List personIds); + + void receiveRecord(RecordNotification recordNotification); + + void receiveRecord(String recordNotificationStr); + + String initSubscription(List deviceIds); + + boolean deleteSubscription(String deviceIp, Long subscribeId); + + Long createSubscription(String deviceIp,String ip,String port); +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/Impl/FacePersonSyncServiceImpl.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/Impl/FacePersonSyncServiceImpl.java new file mode 100644 index 0000000..d1d1694 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/Impl/FacePersonSyncServiceImpl.java @@ -0,0 +1,55 @@ +package com.casic.missiles.modular.system.service.Impl; + +import com.baomidou.mybatisplus.mapper.EntityWrapper; +import com.casic.missiles.core.util.ToolUtil; +import com.casic.missiles.modular.system.model.FacePersonSync; +import com.casic.missiles.modular.system.dao.FacePersonSyncMapper; +import com.casic.missiles.modular.system.service.IFacePersonSyncService; +import com.baomidou.mybatisplus.service.impl.ServiceImpl; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +/** + *

+ * 服务实现类 + *

+ * + * @author zyj123 + * @since 2020-07-24 + */ +@Service +public class FacePersonSyncServiceImpl extends ServiceImpl implements IFacePersonSyncService { + + @Override + public Long selectSyncId(Long personId) { + FacePersonSync facePersonSync = this.selectById(personId); + if(ToolUtil.isNotEmpty(facePersonSync)){ + return facePersonSync.getSyncId(); + } + return null; + } + + @Override + public Long selectPersonId(Long syncId) { + EntityWrapper query = new EntityWrapper(); + query.eq("SYNC_ID",syncId); + FacePersonSync facePersonSync = this.selectOne(query); + if(ToolUtil.isNotEmpty(facePersonSync)){ + return facePersonSync.getPersonId(); + } + return null; + } + + @Override + @Transactional + public Long getMaxSyncId(Long personId) { + Long maxId = this.baseMapper.getMaxSyncId(); + if(ToolUtil.isEmpty(maxId)){ + maxId = 1000L; + }else { + maxId = maxId + 1; + } + this.insert(new FacePersonSync(personId,maxId)); + return maxId; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/Impl/FaceSubscribeServiceImpl.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/Impl/FaceSubscribeServiceImpl.java new file mode 100644 index 0000000..c04302d --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/Impl/FaceSubscribeServiceImpl.java @@ -0,0 +1,52 @@ +package com.casic.missiles.modular.system.service.Impl; + +import com.baomidou.mybatisplus.mapper.EntityWrapper; +import com.casic.missiles.modular.system.model.FaceSubscribe; +import com.casic.missiles.modular.system.dao.FaceSubscribeMapper; +import com.casic.missiles.modular.system.service.IFaceSubscribeService; +import com.baomidou.mybatisplus.service.impl.ServiceImpl; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +/** + *

+ * 服务实现类 + *

+ * + * @author zyj123 + * @since 2020-07-25 + */ +@Service +public class FaceSubscribeServiceImpl extends ServiceImpl implements IFaceSubscribeService { + + @Override + public List selectSubscribeIdsByDevCode(String devCode) { + EntityWrapper query = new EntityWrapper(); + query.eq("DEVICE_CODE",devCode); + List faceSubscribes = this.selectList(query); + List subscribeIds = new ArrayList<>(); + for (FaceSubscribe faceSubscribe : faceSubscribes) { + subscribeIds.add(faceSubscribe.getSubscribeId()); + } + return subscribeIds; + } + + @Override + public boolean deleteByDevCode(String devCode) { + EntityWrapper query = new EntityWrapper(); + query.eq("DEVICE_CODE",devCode); + return this.delete(query); + } + + @Override + public boolean insertSubscribe(Long subscribeId, String devCode) { + FaceSubscribe faceSubscribe = new FaceSubscribe(); + faceSubscribe.setDeviceCode(devCode); + faceSubscribe.setSubscribeId(subscribeId); + faceSubscribe.setUpdateTime(new Date()); + return this.insert(faceSubscribe); + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/Impl/FaceSyncServiceImpl.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/Impl/FaceSyncServiceImpl.java new file mode 100644 index 0000000..8826be5 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/Impl/FaceSyncServiceImpl.java @@ -0,0 +1,465 @@ +package com.casic.missiles.modular.system.service.Impl; + +import com.alibaba.fastjson.JSONObject; +import com.casic.missiles.core.common.service.ICommonPersonService; +import com.casic.missiles.core.util.ToolUtil; +import com.casic.missiles.modular.system.model.Device; +import com.casic.missiles.modular.system.model.FacePersonSync; +import com.casic.missiles.modular.system.model.Person; +import com.casic.missiles.modular.system.model.RecognitionRecords; +import com.casic.missiles.modular.system.request.PersonInfo; +import com.casic.missiles.modular.system.response.*; +import com.casic.missiles.modular.system.service.*; +import com.casic.missiles.modular.system.util.HttpClientUtil; +import com.google.gson.*; +import org.apache.commons.lang3.StringUtils; +import org.omg.CORBA.Object; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import com.casic.missiles.modular.system.constant.FaceSyncConst; +import java.net.InetAddress; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +@Service +public class FaceSyncServiceImpl implements IFaceSyncService { + private static final Logger logger = LoggerFactory.getLogger(FaceSyncServiceImpl.class); + + @Autowired + private IFacePersonSyncService personSyncService; + @Autowired + private ICommonPersonService commonPersonService; + @Autowired + private IPersonPhotoSupportService photoSupportService; + @Autowired + private IDeviceSupportService deviceSupportService; + @Autowired + private IRecordSupportService recordSupportService; + @Autowired + private IFaceSubscribeService subscribeService; + @Value("${server.port}") + private String serverPort; + @Value("${iris.face.serverHost}") + private String serverHost; + + @Override + @Transactional + public String uploadPerson(List personIds,List deviceIds,String personType) { + String error = null; + + try{ + List personInfoList = new ArrayList<>(personIds.size()); + for (Long personId : personIds) { + Person person = commonPersonService.getPersonById(personId); + Long syncId = getPersonSyncId(personId); + String photoData = photoSupportService.selectPhotoDataById(personId); + PersonInfo personInfo = convPersonInfo(person,syncId,photoData); + personInfoList.add(personInfo); + } + + + outterLoop : for (Long deviceId : deviceIds) { + Device device = deviceSupportService.selectById(deviceId); + // 批量下发(单次最多6个,分多次下发) + int batchSize = FaceSyncConst.UPLOAD_MAX_PERSON; + int batchNum = (int)Math.ceil((double)personInfoList.size()/batchSize); + for (int i = 0; i < batchNum; i++) { + int fromIndex = i * batchSize; + int toIndex = (i+1) * batchSize <= personInfoList.size() ? (i+1) * batchSize : personInfoList.size(); + List subPersonInfoList = personInfoList.subList(fromIndex,toIndex); + + // 设置上传body对象 + Gson gson = new GsonBuilder().serializeNulls().create(); + JsonObject body = new JsonObject(); + JsonElement person = gson.toJsonTree(subPersonInfoList); + body.addProperty("Num",subPersonInfoList.size()); + body.add("PersonInfoList",person); + String bodyStr = gson.toJson(body); +// logger.info(String.valueOf(subPersonInfoList.size())); + logger.info(bodyStr); + +// 调用接口上传 + String devIp = device.getDevIp(); + String personLib = null; + if("1".equals(personType)){ + personLib = FaceSyncConst.UPLOAD_STAFF_LIB; + }else { + personLib = FaceSyncConst.UPLOAD_VISITOR_LIB; + } + + String url = "http://".concat(devIp).concat(FaceSyncConst.UPLOAD_URL_PREFIX).concat(personLib).concat(FaceSyncConst.UPLOAD_URL_SUFFIX); + String responseContent = HttpClientUtil.sendHttpPost(url,bodyStr); + logger.info(responseContent); + JsonObject obj = gson.fromJson(responseContent, JsonObject.class); + // 解析返回结果 + FaceBaseResponse> response = gson.fromJson(obj.get("Response"),FaceBaseResponse.class); + if(response.getResponseCode() == 0 && response.getStatusCode() == 0){ + PersonResponseData personResponseData = gson.fromJson(gson.toJson(response.getData()),PersonResponseData.class); + List responseInfos = personResponseData.getPersonList(); + for(int j = 0;j < responseInfos.size();j++){ + PersonResponseInfo personResponseInfo = gson.fromJson(gson.toJson(responseInfos.get(j)),PersonResponseInfo.class);; + if(personResponseInfo.getFaceList().get(0).getResultCode() == 0){ + // 成功 + logger.info(String.format("人脸数据下发成功,人员:%s,设备: %s",personResponseInfo.getPersonId(),device.getDevCode())); + }else{ + error = convErrorCode(personResponseInfo.getFaceList().get(0).getResultCode()); + String personName = commonPersonService.getPersonById(personIds.get(i)).getName(); + error = String.format("下发失败,%s %s",personName,error); + logger.error(error); + break outterLoop; + } + } + }else { + if(response.getResponseCode() != 0 ){ + error = String.format("设备%s下发失败: %s",device.getDevCode(),response.getResponseString()); + logger.error(error); + break; + } + if(response.getStatusCode() != 0){ + error = String.format("设备%s下发失败: %s",device.getDevCode(),response.getStatusString()); + logger.error(error); + break; + } + } + } + } + }catch (Exception e){ + e.printStackTrace(); + logger.error(e.getMessage()); + error = "下发失败"; + } + + return error; + } + + private void updatePersonInfoList(List personInfoList,List personIds){ + for (int i = 0; i < personIds.size(); i++) { + Long syncId = personSyncService.selectSyncId(personIds.get(i)); + if(ToolUtil.isNotEmpty(syncId)){ + PersonInfo personInfo = personInfoList.get(i); + personInfo.setPersonID(syncId); + if(ToolUtil.isNotEmpty(personInfo.getImageList())){ + personInfo.getImageList().get(i).setFaceID(syncId); + } + } + } + } + + private Long getPersonSyncId(Long personId){ + Long syncId = personSyncService.selectSyncId(personId); + if(ToolUtil.isEmpty(syncId)){ + syncId = personSyncService.getMaxSyncId(personId); + } + return syncId; + } + + private PersonInfo convPersonInfo(Person person,Long syncId,String photoData){ + PersonInfo personInfo = new PersonInfo(); + if(ToolUtil.isNotEmpty(syncId)){ + personInfo.setPersonID(syncId); + } + if(ToolUtil.isNotEmpty(person.getUpdatetime())){ + personInfo.setLastChange(person.getUpdatetime().getTime()); + } + if(ToolUtil.isNotEmpty(person.getPersonCode()) && person.getPersonCode().length() <= FaceSyncConst.UPLOAD_PERSONCODE_MAXLENGTH){ + personInfo.setPersonCode(person.getPersonCode()); + }else { + personInfo.setPersonCode(String.valueOf(syncId)); + } + if(ToolUtil.isNotEmpty(person.getName())){ + personInfo.setPersonName(person.getName()); + } + if(ToolUtil.isNotEmpty(person.getRemarks()) && person.getRemarks().length() <= FaceSyncConst.UPLOAD_REMARK_MAXLENGTH){ + personInfo.setRemarks(person.getRemarks()); + }else { + personInfo.setRemarks(""); + } + + // 时间模板 + personInfo.setTimeTemplateNum(0); + List timeTemplateList = new ArrayList<>(); + timeTemplateList.add(personInfo.createTimeTemplate(0L,4294967295L,0L)); + personInfo.setTimeTemplateList(timeTemplateList); + + // 证件列表 + if(ToolUtil.isNotEmpty(person.getIdCardNo())){ + personInfo.setIdentificationNum(1); + List identificationInfoList = new ArrayList<>(); + identificationInfoList.add(personInfo.createIdentificationInfo(1,person.getIdCardNo())); + personInfo.setIdentificationList(identificationInfoList); + }else{ + personInfo.setIdentificationNum(0); + } + + // 图片列表 + if(ToolUtil.isNotEmpty(photoData)){ + personInfo.setImageNum(1); + List imageInfoList = new ArrayList<>(); + // 图片base64码 + if(photoData.startsWith("data") || photoData.startsWith("base64")){ + int splitIndex = photoData.indexOf(","); + photoData = photoData.substring(splitIndex+1); + } + imageInfoList.add(personInfo.createImageInfo(syncId,person.getPhoto(),Long.valueOf(photoData.length()),photoData)); + personInfo.setImageList(imageInfoList); + }else { + personInfo.setImageNum(0); + } + return personInfo; + } + + private String convErrorCode(Long errorCode){ + String errorMsg = ""; + switch (errorCode.intValue()){ + case 1000: + errorMsg = "算法初始化失败"; + break; + case 1001: + errorMsg = "人脸检测失败"; + break; + case 1002: + errorMsg = "图片未检测到人脸"; + break; + case 1003: + errorMsg = "jpeg照片解码失败"; + break; + case 1004: + errorMsg = "图片质量分数不满足"; + break; + case 1005: + errorMsg = "图片缩放失败"; + break; + case 1006: + errorMsg = "未启用智能"; + break; + case 1007: + errorMsg = "导入图片过小"; + break; + case 1008: + errorMsg = "导入图片过大"; + break; + case 1009: + errorMsg = "导入图片分辨率超过1920*1080"; + break; + case 1010: + errorMsg = "导入图片不存在"; + break; + case 1011: + errorMsg = "人脸元素个数已达到上限"; + break; + case 1012: + errorMsg = "智能棒算法模型不匹配"; + break; + case 1013: + errorMsg = "人脸导入库成员证件号非法"; + break; + case 1014: + errorMsg = "人脸导入库成员图片格式错误"; + break; + case 1015: + errorMsg = "通道布控已达设备能力上限"; + break; + case 1016: + errorMsg = "其它客户端正在进行操作人脸库"; + break; + case 1017: + errorMsg = "人脸库文件正在更新中"; + break; + case 1018: + errorMsg = "Json反序列化失败"; + break; + case 1019: + errorMsg = "Base64解码失败"; + break; + case 1020: + errorMsg = "人脸照片,编码后的大小和实际接收到的长度不一致,关注Data和Size大小是否正确"; + break; + default: + break; + } + return errorMsg; + + } + + @Override + public String checkPersonPhoto(List personIds) { + String error = null; + for (Long personId : personIds) { + Person person = commonPersonService.getPersonById(personId); + String photoData = photoSupportService.selectPhotoDataById(personId); + if(ToolUtil.isEmpty(photoData)){ + error = String.format("%s 未上传照片",person.getName()); + break; + } + if(photoData.startsWith("data") || photoData.startsWith("base64")){ + int splitIndex = photoData.indexOf(","); + photoData = photoData.substring(splitIndex+1); + } + if(!photoData.startsWith("/9j")){ + error = String.format("%s人员照片不符合要求,必须为jpg格式",person.getName()); + break; + } + + // 找到等号,把等号也去掉 + int equalIndex = photoData.indexOf('='); + if(equalIndex>=0) { + photoData=photoData.substring(0, equalIndex); + } + // 原来的字符流大小,单位为字节 + int strLength=photoData.length(); + // 计算后得到的文件流大小,单位为字节 + int fileLength=Integer.valueOf(strLength-(strLength/8)*2); + if(fileLength / 1024 < 20){ + error = String.format("%s人员照片不符合要求,照片必须大于20Kb",person.getName()); + break; + } + } + return error; + } + + @Override + public void receiveRecord(RecordNotification recordNotification){ +// if(recordNotification.getFaceInfoNum() != recordNotification.getLibMatInfoNum()){ +// logger.error("采集和匹配数据不一致,识别失败"); +// } else { + String deviceCode = recordNotification.getDeviceCode(); + List recordsList = new ArrayList<>(); + for (int i = 0; i < recordNotification.getLibMatInfoNum(); i++) { + //FaceInfo faceInfo = recordNotification.getFaceInfoList().get(i); + LibMatInfo libMatInfo = recordNotification.getLibMatInfoList().get(i); + if(libMatInfo.getMatchStatus() == 1){ + FaceInfo faceInfo = getFaceInfoByMatchId(recordNotification.getFaceInfoList(),libMatInfo.getId()); + Long personId = personSyncService.selectPersonId(libMatInfo.getMatchPersonId()); + if(ToolUtil.isNotEmpty(personId) && ToolUtil.isNotEmpty(faceInfo)){ + RecognitionRecords record = new RecognitionRecords(); + record.setPersonId(personId); + record.setDatetime(new Date(faceInfo.getTimestamp()*1000)); + record.setDevCode(deviceCode); + if(ToolUtil.isNotEmpty(faceInfo.getTemperature())){ + record.setTemperature(String.valueOf(faceInfo.getTemperature())); + } + record.setOriginalId(libMatInfo.getId()); + record.setSyncTime(new Date()); + + Device device = deviceSupportService.selectDeviceByCode(deviceCode); + if(ToolUtil.isNotEmpty(device)){ + if(ToolUtil.isNotEmpty(device.getDevIp())){ + record.setDevIp(device.getDevIp()); + } + } + + recordsList.add(record); + } + } + } + if(ToolUtil.isNotEmpty(recordsList)){ + recordSupportService.insertBatch(recordsList); + } + } + + @Override + public void receiveRecord(String recordNotificationStr) { + RecordNotification recordNotification = JSONObject.parseObject(recordNotificationStr,RecordNotification.class); + receiveRecord(recordNotification); + } + + public FaceInfo getFaceInfoByMatchId(List faceInfoList ,Long id){ + for (FaceInfo faceInfo : faceInfoList) { + if(faceInfo.getId().equals(id)){ + return faceInfo; + } + } + return null; + } + + @Override + public String initSubscription(List deviceIds) { + try { + List error = new ArrayList<>(); + for (Long deviceId : deviceIds) { + Device device = deviceSupportService.selectById(deviceId); + List subscribeIds = subscribeService.selectSubscribeIdsByDevCode(device.getDevCode());; + // 删除所有id + boolean flag = true; + for (Long subscribeId : subscribeIds) { + flag = flag && deleteSubscription(device.getDevIp(),subscribeId); + } + flag = flag && subscribeService.deleteByDevCode(device.getDevCode()); + // 创建订阅 + Long subscribeId = createSubscription(device.getDevIp(),serverHost,serverPort); + flag = flag && ToolUtil.isNotEmpty(subscribeId); + if(ToolUtil.isNotEmpty(subscribeId)){ + flag = flag && subscribeService.insertSubscribe(subscribeId,device.getDevCode()); + } + if(!flag){ + logger.error(String.format("device %s init subsrciption error",device.getDevCode())); + error.add(device.getDevCode()); + } + } + if(ToolUtil.isNotEmpty(error)){ + return StringUtils.join(error,",").concat("订阅失败"); + }else { + return null; + } + }catch (Exception e){ + e.printStackTrace(); + logger.error(e.getMessage()); + return "订阅失败"; + } + + } + + @Override + public boolean deleteSubscription(String deviceIp, Long subscribeId) { + String url = "http://" + deviceIp + FaceSyncConst.SUBSCRIBE_URL + subscribeId; + String responseContent = HttpClientUtil.sendHttpDelete(url); + logger.info(responseContent); + Gson gson = new Gson(); + JsonObject obj = gson.fromJson(responseContent, JsonObject.class); + logger.info(obj.get("Response").toString()); + FaceBaseResponse response = gson.fromJson(obj.get("Response"),FaceBaseResponse.class); + if(response.getResponseCode() == 0 && response.getStatusCode() == 0){ + return true; + }else { + logger.error(String.format("delele subscribe error, device '%s', subscribeId '%s', response '%s', status '%s'",deviceIp,subscribeId,response.getResponseString(),response.getStatusString())); + return false; + } + } + + @Override + public Long createSubscription(String deviceIp, String ip, String port) { + JsonObject request = new JsonObject(); + request.addProperty("AddressType",0); + request.addProperty("IPAddress",ip); + request.addProperty("Port",Long.valueOf(port)); + request.addProperty("Duration",4294967295L); + request.addProperty("Type",1024); + JsonObject subscribePersonCondition = new JsonObject(); + subscribePersonCondition.addProperty("LibIDNum",65535); + subscribePersonCondition.add("LibIDList",new JsonArray()); + request.add("SubscribePersonCondition",subscribePersonCondition); + Gson gson = new Gson(); + String requestStr = gson.toJson(request); + System.out.println(requestStr); + String url = "http://" + deviceIp + FaceSyncConst.SUBSCRIBE_URL ; + String responseContent = HttpClientUtil.sendHttpPostJson(url,requestStr); + logger.info(responseContent); + JsonObject obj = gson.fromJson(responseContent, JsonObject.class); + FaceBaseResponse response = gson.fromJson(obj.get("Response"),FaceBaseResponse.class); + if(response.getResponseCode() == 0 && response.getStatusCode()==0){ + JsonObject data = gson.fromJson(gson.toJson(response.getData()),JsonObject.class); + Long subsrcibeId = data.get("ID").getAsLong(); + logger.info(String.format("create subscribe success, device '%s', subsrcibeId '%s'",deviceIp,subsrcibeId)); + return subsrcibeId; + }else { + logger.error(String.format("create subscribe error, device '%s', response '%s', status '%s'",deviceIp,response.getResponseString(),response.getStatusString())); + return null; + } + } + +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/util/HttpClientUtil.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/util/HttpClientUtil.java new file mode 100644 index 0000000..e258174 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/util/HttpClientUtil.java @@ -0,0 +1,468 @@ +package com.casic.missiles.modular.system.util; + +import java.io.File; +import java.io.IOException; +import java.security.KeyManagementException; +import java.security.KeyStoreException; +import java.security.NoSuchAlgorithmException; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.apache.http.HttpEntity; +import org.apache.http.HttpStatus; +import org.apache.http.client.config.RequestConfig; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpDelete; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.config.Registry; +import org.apache.http.config.RegistryBuilder; +import org.apache.http.conn.socket.ConnectionSocketFactory; +import org.apache.http.conn.socket.PlainConnectionSocketFactory; +import org.apache.http.conn.ssl.SSLConnectionSocketFactory; +import org.apache.http.conn.ssl.SSLContextBuilder; +import org.apache.http.conn.ssl.TrustSelfSignedStrategy; +import org.apache.http.entity.ContentType; +import org.apache.http.entity.StringEntity; +import org.apache.http.entity.mime.MultipartEntityBuilder; +import org.apache.http.entity.mime.content.FileBody; +import org.apache.http.entity.mime.content.StringBody; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.DefaultHttpRequestRetryHandler; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; +import org.apache.http.util.EntityUtils; + +/** + * + * @author H__D + * @date 2016年10月19日 上午11:27:25 + * + */ +public class HttpClientUtil { + + // utf-8字符编码 + public static final String CHARSET_UTF_8 = "utf-8"; + + // HTTP内容类型。 + public static final String CONTENT_TYPE_TEXT_HTML = "text/xml"; + + // HTTP内容类型。相当于form表单的形式,提交数据 + public static final String CONTENT_TYPE_FORM_URL = "application/x-www-form-urlencoded"; + + // HTTP内容类型。相当于form表单的形式,提交数据 + public static final String CONTENT_TYPE_JSON_URL = "application/json;charset=utf-8"; + + + // 连接管理器 + private static PoolingHttpClientConnectionManager pool; + + // 请求配置 + private static RequestConfig requestConfig; + + static { + + try { + //System.out.println("初始化HttpClientTest~~~开始"); + SSLContextBuilder builder = new SSLContextBuilder(); + builder.loadTrustMaterial(null, new TrustSelfSignedStrategy()); + SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory( + builder.build()); + // 配置同时支持 HTTP 和 HTPPS + Registry socketFactoryRegistry = RegistryBuilder. create().register( + "http", PlainConnectionSocketFactory.getSocketFactory()).register( + "https", sslsf).build(); + // 初始化连接管理器 + pool = new PoolingHttpClientConnectionManager( + socketFactoryRegistry); + // 将最大连接数增加到200,实际项目最好从配置文件中读取这个值 + pool.setMaxTotal(200); + // 设置最大路由 + pool.setDefaultMaxPerRoute(2); + // 根据默认超时限制初始化requestConfig + int socketTimeout = 10000; + int connectTimeout = 10000; + int connectionRequestTimeout = 10000; + requestConfig = RequestConfig.custom().setConnectionRequestTimeout( + connectionRequestTimeout).setSocketTimeout(socketTimeout).setConnectTimeout( + connectTimeout).build(); + + //System.out.println("初始化HttpClientTest~~~结束"); + } catch (NoSuchAlgorithmException e) { + e.printStackTrace(); + } catch (KeyStoreException e) { + e.printStackTrace(); + } catch (KeyManagementException e) { + e.printStackTrace(); + } + + + // 设置请求超时时间 + requestConfig = RequestConfig.custom().setSocketTimeout(50000).setConnectTimeout(50000) + .setConnectionRequestTimeout(50000).build(); + } + + public static CloseableHttpClient getHttpClient() { + + CloseableHttpClient httpClient = HttpClients.custom() + // 设置连接池管理 + .setConnectionManager(pool) + // 设置请求配置 + .setDefaultRequestConfig(requestConfig) + // 设置重试次数 + .setRetryHandler(new DefaultHttpRequestRetryHandler(0, false)) + .build(); + + return httpClient; + } + + /** + * 发送Post请求 + * + * @param httpPost + * @return + */ + private static String sendHttpPost(HttpPost httpPost) { + + CloseableHttpClient httpClient = null; + CloseableHttpResponse response = null; + // 响应内容 + String responseContent = null; + try { + // 创建默认的httpClient实例. + httpClient = getHttpClient(); + // 配置请求信息 + httpPost.setConfig(requestConfig); + // 执行请求 + response = httpClient.execute(httpPost); + // 得到响应实例 + HttpEntity entity = response.getEntity(); + + // 可以获得响应头 + // Header[] headers = response.getHeaders(HttpHeaders.CONTENT_TYPE); + // for (Header header : headers) { + // System.out.println(header.getName()); + // } + + // 得到响应类型 + // System.out.println(ContentType.getOrDefault(response.getEntity()).getMimeType()); + + // 判断响应状态 + if (response.getStatusLine().getStatusCode() >= 300) { + throw new Exception( + "HTTP Request is not success, Response code is " + response.getStatusLine().getStatusCode()); + } + + if (HttpStatus.SC_OK == response.getStatusLine().getStatusCode()) { + responseContent = EntityUtils.toString(entity, CHARSET_UTF_8); + EntityUtils.consume(entity); + } + + } catch (Exception e) { + e.printStackTrace(); + } finally { + try { + // 释放资源 + if (response != null) { + response.close(); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + return responseContent; + } + + /** + * 发送Get请求 + * + * @param httpGet + * @return + */ + private static String sendHttpGet(HttpGet httpGet) { + + CloseableHttpClient httpClient = null; + CloseableHttpResponse response = null; + // 响应内容 + String responseContent = null; + try { + // 创建默认的httpClient实例. + httpClient = getHttpClient(); + // 配置请求信息 + httpGet.setConfig(requestConfig); + // 执行请求 + response = httpClient.execute(httpGet); + // 得到响应实例 + HttpEntity entity = response.getEntity(); + + // 可以获得响应头 + // Header[] headers = response.getHeaders(HttpHeaders.CONTENT_TYPE); + // for (Header header : headers) { + // System.out.println(header.getName()); + // } + + // 得到响应类型 + // System.out.println(ContentType.getOrDefault(response.getEntity()).getMimeType()); + + // 判断响应状态 + if (response.getStatusLine().getStatusCode() >= 300) { + throw new Exception( + "HTTP Request is not success, Response code is " + response.getStatusLine().getStatusCode()); + } + + if (HttpStatus.SC_OK == response.getStatusLine().getStatusCode()) { + responseContent = EntityUtils.toString(entity, CHARSET_UTF_8); + EntityUtils.consume(entity); + } + + } catch (Exception e) { + e.printStackTrace(); + } finally { + try { + // 释放资源 + if (response != null) { + response.close(); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + return responseContent; + } + + /** + * 发送Delete请求 + * + * @param httpDelete + * @return + */ + private static String sendHttpDelete(HttpDelete httpDelete) { + + CloseableHttpClient httpClient = null; + CloseableHttpResponse response = null; + // 响应内容 + String responseContent = null; + try { + // 创建默认的httpClient实例. + httpClient = getHttpClient(); + // 配置请求信息 + httpDelete.setConfig(requestConfig); + // 执行请求 + response = httpClient.execute(httpDelete); + // 得到响应实例 + HttpEntity entity = response.getEntity(); + + // 可以获得响应头 + // Header[] headers = response.getHeaders(HttpHeaders.CONTENT_TYPE); + // for (Header header : headers) { + // System.out.println(header.getName()); + // } + + // 得到响应类型 + // System.out.println(ContentType.getOrDefault(response.getEntity()).getMimeType()); + + // 判断响应状态 + if (response.getStatusLine().getStatusCode() >= 300) { + throw new Exception( + "HTTP Request is not success, Response code is " + response.getStatusLine().getStatusCode()); + } + + if (HttpStatus.SC_OK == response.getStatusLine().getStatusCode()) { + responseContent = EntityUtils.toString(entity, CHARSET_UTF_8); + EntityUtils.consume(entity); + } + + } catch (Exception e) { + e.printStackTrace(); + } finally { + try { + // 释放资源 + if (response != null) { + response.close(); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + return responseContent; + } + + + + /** + * 发送 post请求 + * + * @param httpUrl 地址 + */ + public static String sendHttpPost(String httpUrl) { + // 创建httpPost + HttpPost httpPost = new HttpPost(httpUrl); + return sendHttpPost(httpPost); + } + + /** + * 发送 get请求 + * + * @param httpUrl + */ + public static String sendHttpGet(String httpUrl) { + // 创建get请求 + HttpGet httpGet = new HttpGet(httpUrl); + return sendHttpGet(httpGet); + } + + /** + * 发送 DELETE 请求 + * + * @param httpUrl + */ + public static String sendHttpDelete(String httpUrl) { + // 创建delete请求 + HttpDelete httpDelete = new HttpDelete(httpUrl); + return sendHttpDelete(httpDelete); + } + + + + /** + * 发送 post请求(带文件) + * + * @param httpUrl + * 地址 + * @param maps + * 参数 + * @param fileLists + * 附件 + */ + public static String sendHttpPost(String httpUrl, Map maps, List fileLists) { + HttpPost httpPost = new HttpPost(httpUrl);// 创建httpPost + MultipartEntityBuilder meBuilder = MultipartEntityBuilder.create(); + if (maps != null) { + for (String key : maps.keySet()) { + meBuilder.addPart(key, new StringBody(maps.get(key), ContentType.TEXT_PLAIN)); + } + } + if (fileLists != null) { + for (File file : fileLists) { + FileBody fileBody = new FileBody(file); + meBuilder.addPart("files", fileBody); + } + } + HttpEntity reqEntity = meBuilder.build(); + httpPost.setEntity(reqEntity); + return sendHttpPost(httpPost); + } + + /** + * 发送 post请求 + * + * @param httpUrl + * 地址 + * @param params + * 参数(格式:key1=value1&key2=value2) + * + */ + public static String sendHttpPost(String httpUrl, String params) { + HttpPost httpPost = new HttpPost(httpUrl);// 创建httpPost + try { + // 设置参数 + if (params != null && params.trim().length() > 0) { + StringEntity stringEntity = new StringEntity(params, "UTF-8"); + stringEntity.setContentType(CONTENT_TYPE_FORM_URL); + httpPost.setEntity(stringEntity); + } + } catch (Exception e) { + throw e; + } + return sendHttpPost(httpPost); + } + + /** + * 发送 post请求 + * + * @param maps + * 参数 + */ + public static String sendHttpPost(String httpUrl, Map maps) { + String parem = convertStringParamter(maps); + return sendHttpPost(httpUrl, parem); + } + + + + + /** + * 发送 post请求 发送json数据 + * + * @param httpUrl 地址 + * @param paramsJson 参数(格式 json) + * + */ + public static String sendHttpPostJson(String httpUrl, String paramsJson) { + HttpPost httpPost = new HttpPost(httpUrl);// 创建httpPost + try { + // 设置参数 + if (paramsJson != null && paramsJson.trim().length() > 0) { + StringEntity stringEntity = new StringEntity(paramsJson, "UTF-8"); + stringEntity.setContentType(CONTENT_TYPE_JSON_URL); + httpPost.setEntity(stringEntity); + } + } catch (Exception e) { + e.printStackTrace(); + } + return sendHttpPost(httpPost); + } + + /** + * 发送 post请求 发送xml数据 + * + * @param httpUrl 地址 + * @param paramsXml 参数(格式 Xml) + * + */ + public static String sendHttpPostXml(String httpUrl, String paramsXml) { + HttpPost httpPost = new HttpPost(httpUrl);// 创建httpPost + try { + // 设置参数 + if (paramsXml != null && paramsXml.trim().length() > 0) { + StringEntity stringEntity = new StringEntity(paramsXml, "UTF-8"); + stringEntity.setContentType(CONTENT_TYPE_TEXT_HTML); + httpPost.setEntity(stringEntity); + } + } catch (Exception e) { + e.printStackTrace(); + } + return sendHttpPost(httpPost); + } + + + /** + * 将map集合的键值对转化成:key1=value1&key2=value2 的形式 + * + * @param parameterMap 需要转化的键值对集合 + * @return 字符串 + */ + public static String convertStringParamter(Map parameterMap) { + StringBuffer parameterBuffer = new StringBuffer(); + if (parameterMap != null) { + Iterator iterator = parameterMap.keySet().iterator(); + String key = null; + String value = null; + while (iterator.hasNext()) { + key = (String) iterator.next(); + if (parameterMap.get(key) != null) { + value = (String) parameterMap.get(key); + } else { + value = ""; + } + parameterBuffer.append(key).append("=").append(value); + if (iterator.hasNext()) { + parameterBuffer.append("&"); + } + } + } + return parameterBuffer.toString(); + } + +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/util/ImageUtil.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/util/ImageUtil.java new file mode 100644 index 0000000..4586ad1 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/util/ImageUtil.java @@ -0,0 +1,30 @@ +package com.casic.missiles.modular.system.util; + +import javax.imageio.ImageIO; +import java.awt.*; +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.IOException; + +public class ImageUtil { + public static void main(String[] args) { + BufferedImage bufferedImage; + try { + // read image file + bufferedImage = ImageIO.read(new File("C:\\Users\\zhang\\Desktop\\test.png")); + // create a blank, RGB, same width and height, and a white + // background + BufferedImage newBufferedImage = new BufferedImage( + bufferedImage.getWidth(), bufferedImage.getHeight(), + BufferedImage.TYPE_INT_RGB); + // TYPE_INT_RGB:创建一个RBG图像,24位深度,成功将32位图转化成24位 + newBufferedImage.createGraphics().drawImage(bufferedImage, 0, 0, + Color.WHITE, null); + // write to jpeg file + ImageIO.write(newBufferedImage, "jpg", new File("C:\\Users\\zhang\\Desktop\\test.jpg")); + System.out.println("Done"); + } catch (IOException e) { + e.printStackTrace(); + } + } +} diff --git a/casic-face-sync/pom.xml b/casic-face-sync/pom.xml new file mode 100644 index 0000000..24dc884 --- /dev/null +++ b/casic-face-sync/pom.xml @@ -0,0 +1,74 @@ + + + 4.0.0 + + com.casic + casic-iris-parent + 1.0.0-SNAPSHOT + ../pom.xml + + + + casic-face-sync + ${pro.version} + jar + casic-face-sync + + + + + + com.casic + casic-core + ${core.version} + + + + com.casic + casic-admin-support + ${admin.version} + + + com.casic + casic-iris-support + ${pro.version} + + + + org.apache.httpcomponents + httpclient + 4.5.3 + + + + org.apache.httpcomponents + httpcore + 4.4.8 + + + + org.apache.httpcomponents + httpmime + 4.5.3 + + + + com.google.code.gson + gson + + + + + + + + src/main/java + + **/*.xml + + + + + \ No newline at end of file diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/constant/FaceSyncConst.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/constant/FaceSyncConst.java new file mode 100644 index 0000000..352d47d --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/constant/FaceSyncConst.java @@ -0,0 +1,29 @@ +package com.casic.missiles.modular.system.constant; + +public class FaceSyncConst { + + /** + * 单次最大批量上传人员数 + */ + public static final int UPLOAD_MAX_PERSON = 6; + + /** + * 上传人员库 + */ + public static final String UPLOAD_STAFF_LIB = "3"; + public static final String UPLOAD_VISITOR_LIB = "4"; + + public static final String UPLOAD_URL_PREFIX = "/LAPI/V1.0/PeopleLibraries/"; + + public static final String UPLOAD_URL_SUFFIX = "/People"; + + public static final int UPLOAD_PERSONCODE_MAXLENGTH = 15; + + public static final int UPLOAD_REMARK_MAXLENGTH = 63; + + public static final String SUBSCRIBE_URL = "/LAPI/V1.0/System/Event/Subscription/"; + + public static final String STAFF_PERSON_TYPE = "1"; + + public static final String VISITOR_PERSON_TYPE = "0"; +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/controller/FaceSyncController.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/controller/FaceSyncController.java new file mode 100644 index 0000000..1b35431 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/controller/FaceSyncController.java @@ -0,0 +1,117 @@ +package com.casic.missiles.modular.system.controller; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson.serializer.SerializerFeature; +import com.casic.missiles.core.base.response.ResponseData; +import com.casic.missiles.core.common.service.ICommonPermissionService; +import com.casic.missiles.core.common.service.ICommonPersonService; +import com.casic.missiles.core.datascope.DataScope; +import com.casic.missiles.core.util.ToolUtil; +import com.casic.missiles.modular.system.request.PersonInfo; +import com.casic.missiles.modular.system.response.RecordNotification; +import com.casic.missiles.modular.system.service.IFaceSyncService; +import com.casic.missiles.modular.system.service.IIrisPersonSupportService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.*; +import com.casic.missiles.modular.system.constant.FaceSyncConst; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + + + +@Controller +public class FaceSyncController { + private final static Logger logger = LoggerFactory.getLogger(FaceSyncController.class); + + @Autowired + private IFaceSyncService syncService; + @Autowired + private ICommonPersonService commonPersonService; + @Autowired + private IIrisPersonSupportService personSupportService; + @Autowired + private ICommonPermissionService permissionService; + + @RequestMapping("/face/upload") + @ResponseBody + public Object upload(@RequestParam("personIds") List personIds, + @RequestParam("deviceIds") List deviceIds, + @RequestParam("personType")String personType ){ + // 检查数量 +// if(personIds.size()>FaceSyncConst.UPLOAD_MAX_PERSON){ +// return ResponseData.error(String.format("每次最多上传%s个人",FaceSyncConst.UPLOAD_MAX_PERSON)); +// } + // 检查照片格式及大小 + String photoCheck = syncService.checkPersonPhoto(personIds); + if(ToolUtil.isNotEmpty(photoCheck)){ + return ResponseData.error(photoCheck); + } + else{ + // 上传数据 + String error = syncService.uploadPerson(personIds,deviceIds,personType); + if(ToolUtil.isNotEmpty(error)){ + return ResponseData.error(error); + } + } + return ResponseData.success(); + } + + @RequestMapping("/face/uploadAll") + @ResponseBody + public Object uploadAll(@RequestParam("deviceIds") List deviceIds){ + DataScope dataScope = permissionService.getCurrUserDataScope(); + + List staffPersonIds = personSupportService.listIdsByType(dataScope,FaceSyncConst.STAFF_PERSON_TYPE); + List visitorPersonIds = personSupportService.listIdsByType(dataScope,FaceSyncConst.VISITOR_PERSON_TYPE); + // 1.检查照片,分别检查员工、访客 + String staffPhotoCheck = syncService.checkPersonPhoto(staffPersonIds); + if(ToolUtil.isNotEmpty(staffPhotoCheck)){ + return ResponseData.error(staffPhotoCheck); + } + String visitorPhotoCheck = syncService.checkPersonPhoto(visitorPersonIds); + if(ToolUtil.isNotEmpty(visitorPhotoCheck)){ + return ResponseData.error(visitorPhotoCheck); + } + + // 2. 下发数据 + String staffError = syncService.uploadPerson(staffPersonIds,deviceIds,FaceSyncConst.STAFF_PERSON_TYPE); + if(ToolUtil.isNotEmpty(staffError)){ + return ResponseData.error(staffError); + } + String visitorError = syncService.uploadPerson(visitorPersonIds,deviceIds,FaceSyncConst.VISITOR_PERSON_TYPE); + if(ToolUtil.isNotEmpty(visitorError)){ + return ResponseData.error(visitorError); + } + + return ResponseData.success(); + } + + // 错误信息返回 + @RequestMapping("/subsrcibe/init") + @ResponseBody + public Object upload(@RequestParam("deviceIds") List deviceIds){ + String errorMsg = syncService.initSubscription(deviceIds); + if(ToolUtil.isNotEmpty(errorMsg)){ + return ResponseData.error(errorMsg); + } + return ResponseData.success(); + } + + + @RequestMapping(value = "/LAPI/V1.0/System/Event/Notification/PersonVerification", method = RequestMethod.POST) + @ResponseBody + public void verification(@RequestBody String recordNotification){ + logger.info(recordNotification); + RecordNotification record = JSONObject.parseObject(recordNotification,RecordNotification.class); + syncService.receiveRecord(record); + //return ResponseData.success(); + } + + +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FacePersonSyncMapper.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FacePersonSyncMapper.java new file mode 100644 index 0000000..af53702 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FacePersonSyncMapper.java @@ -0,0 +1,17 @@ +package com.casic.missiles.modular.system.dao; + +import com.casic.missiles.modular.system.model.FacePersonSync; +import com.baomidou.mybatisplus.mapper.BaseMapper; + +/** + *

+ * Mapper 接口 + *

+ * + * @author zyj123 + * @since 2020-07-24 + */ +public interface FacePersonSyncMapper extends BaseMapper { + + Long getMaxSyncId(); +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FaceSubscribeMapper.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FaceSubscribeMapper.java new file mode 100644 index 0000000..0c6374a --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FaceSubscribeMapper.java @@ -0,0 +1,16 @@ +package com.casic.missiles.modular.system.dao; + +import com.casic.missiles.modular.system.model.FaceSubscribe; +import com.baomidou.mybatisplus.mapper.BaseMapper; + +/** + *

+ * Mapper 接口 + *

+ * + * @author zyj123 + * @since 2020-07-25 + */ +public interface FaceSubscribeMapper extends BaseMapper { + +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FacePersonSyncMapper.xml b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FacePersonSyncMapper.xml new file mode 100644 index 0000000..ac46ad0 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FacePersonSyncMapper.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + PERSON_ID AS personId, SYNC_ID AS syncId + + + + + diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FaceSubscribeMapper.xml b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FaceSubscribeMapper.xml new file mode 100644 index 0000000..16024e2 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FaceSubscribeMapper.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + SUBSCRIBE_ID AS subscribeId, DEVICE_CODE AS deviceCode, UPDATE_TIME AS updateTime + + + diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FacePersonSync.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FacePersonSync.java new file mode 100644 index 0000000..7cdb821 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FacePersonSync.java @@ -0,0 +1,68 @@ +package com.casic.missiles.modular.system.model; + +import java.io.Serializable; + +import com.baomidou.mybatisplus.annotations.TableId; +import com.baomidou.mybatisplus.annotations.TableField; +import com.baomidou.mybatisplus.activerecord.Model; +import com.baomidou.mybatisplus.annotations.TableName; +import java.io.Serializable; + +/** + *

+ * + *

+ * + * @author zyj123 + * @since 2020-07-24 + */ +@TableName("face_person_sync") +public class FacePersonSync extends Model { + + private static final long serialVersionUID = 1L; + + /** + * 人员id + */ + @TableId("PERSON_ID") + private Long personId; + /** + * 人员同步id + */ + @TableField("SYNC_ID") + private Long syncId; + + public FacePersonSync(Long personId, Long syncId) { + this.personId = personId; + this.syncId = syncId; + } + + public Long getPersonId() { + return personId; + } + + public void setPersonId(Long personId) { + this.personId = personId; + } + + public Long getSyncId() { + return syncId; + } + + public void setSyncId(Long syncId) { + this.syncId = syncId; + } + + @Override + protected Serializable pkVal() { + return this.personId; + } + + @Override + public String toString() { + return "FacePersonSync{" + + "personId=" + personId + + ", syncId=" + syncId + + "}"; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FaceSubscribe.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FaceSubscribe.java new file mode 100644 index 0000000..ccc7792 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FaceSubscribe.java @@ -0,0 +1,79 @@ +package com.casic.missiles.modular.system.model; + +import java.io.Serializable; + +import java.util.Date; +import com.baomidou.mybatisplus.annotations.TableId; +import com.baomidou.mybatisplus.annotations.TableField; +import com.baomidou.mybatisplus.activerecord.Model; +import com.baomidou.mybatisplus.annotations.TableName; +import java.io.Serializable; + +/** + *

+ * + *

+ * + * @author zyj123 + * @since 2020-07-25 + */ +@TableName("face_subscribe") +public class FaceSubscribe extends Model { + + private static final long serialVersionUID = 1L; + + /** + * 订阅id + */ + @TableId("SUBSCRIBE_ID") + private Long subscribeId; + /** + * 设备编号 + */ + @TableField("DEVICE_CODE") + private String deviceCode; + /** + * 更新时间 + */ + @TableField("UPDATE_TIME") + private Date updateTime; + + + public Long getSubscribeId() { + return subscribeId; + } + + public void setSubscribeId(Long subscribeId) { + this.subscribeId = subscribeId; + } + + public String getDeviceCode() { + return deviceCode; + } + + public void setDeviceCode(String deviceCode) { + this.deviceCode = deviceCode; + } + + public Date getUpdateTime() { + return updateTime; + } + + public void setUpdateTime(Date updateTime) { + this.updateTime = updateTime; + } + + @Override + protected Serializable pkVal() { + return this.subscribeId; + } + + @Override + public String toString() { + return "FaceSubscribe{" + + "subscribeId=" + subscribeId + + ", deviceCode=" + deviceCode + + ", updateTime=" + updateTime + + "}"; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/request/PersonInfo.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/request/PersonInfo.java new file mode 100644 index 0000000..80d9eff --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/request/PersonInfo.java @@ -0,0 +1,271 @@ +package com.casic.missiles.modular.system.request; + +import com.alibaba.fastjson.annotation.JSONField; +import com.baomidou.mybatisplus.annotations.TableField; +import com.google.gson.annotations.SerializedName; + +import java.util.List; + +public class PersonInfo { + + //@JSONField(name = "PersonID") + @SerializedName("PersonID") + private Long personID; + + //@JSONField(name = "LastChange") + @SerializedName("LastChange") + private Long lastChange; + + //@JSONField(name = "PersonCode") + @SerializedName("PersonCode") + private String personCode; + + //@JSONField(name = "PersonName") + @SerializedName("PersonName") + private String personName; + + //@JSONField(name = "Remarks") + @SerializedName("Remarks") + private String remarks; + + //@JSONField(name = "TimeTemplateNum") + @SerializedName("TimeTemplateNum") + private Integer timeTemplateNum; + + //@JSONField(name = "TimeTemplateList") + @SerializedName("TimeTemplateList") + private List timeTemplateList; + + //@JSONField(name = "IdentificationNum") + @SerializedName("IdentificationNum") + private Integer identificationNum; + + //@JSONField(name = "IdentificationList") + @SerializedName("IdentificationList") + private List identificationList; + + //@JSONField(name = "ImageNum") + @SerializedName("ImageNum") + private Integer imageNum; + + //@JSONField(name = "ImageList") + @SerializedName("ImageList") + private List imageList; + + public Long getPersonID() { + return personID; + } + + public void setPersonID(Long personID) { + this.personID = personID; + } + + public Long getLastChange() { + return lastChange; + } + + public void setLastChange(Long lastChange) { + this.lastChange = lastChange; + } + + public String getPersonCode() { + return personCode; + } + + public void setPersonCode(String personCode) { + this.personCode = personCode; + } + + public String getPersonName() { + return personName; + } + + public void setPersonName(String personName) { + this.personName = personName; + } + + public String getRemarks() { + return remarks; + } + + public void setRemarks(String remarks) { + this.remarks = remarks; + } + + public Integer getTimeTemplateNum() { + return timeTemplateNum; + } + + public void setTimeTemplateNum(Integer timeTemplateNum) { + this.timeTemplateNum = timeTemplateNum; + } + + public List getTimeTemplateList() { + return timeTemplateList; + } + + public void setTimeTemplateList(List timeTemplateList) { + this.timeTemplateList = timeTemplateList; + } + + public Integer getIdentificationNum() { + return identificationNum; + } + + public void setIdentificationNum(Integer identificationNum) { + this.identificationNum = identificationNum; + } + + public List getIdentificationList() { + return identificationList; + } + + public void setIdentificationList(List identificationList) { + this.identificationList = identificationList; + } + + public Integer getImageNum() { + return imageNum; + } + + public void setImageNum(Integer imageNum) { + this.imageNum = imageNum; + } + + public List getImageList() { + return imageList; + } + + public void setImageList(List imageList) { + this.imageList = imageList; + } + + public class TimeTemplate{ + @JSONField(name = "BeginTime") + private Long beginTime; + @JSONField(name = "EndTime") + private Long endTime; + @JSONField(name = "Index") + private Long index; + + public TimeTemplate(Long beginTime, Long endTime, Long index) { + this.beginTime = beginTime; + this.endTime = endTime; + this.index = index; + } + + public Long getBeginTime() { + return beginTime; + } + + public void setBeginTime(Long beginTime) { + this.beginTime = beginTime; + } + + public Long getEndTime() { + return endTime; + } + + public void setEndTime(Long endTime) { + this.endTime = endTime; + } + + public Long getIndex() { + return index; + } + + public void setIndex(Long index) { + this.index = index; + } + } + + public TimeTemplate createTimeTemplate(Long beginTime, Long endTime, Long index){ + return new TimeTemplate(beginTime, endTime, index); + } + + public class IdentificationInfo { + @JSONField(name = "Type") + private Integer type; + @JSONField(name = "Number") + private String number; + + public IdentificationInfo(Integer type, String number) { + this.type = type; + this.number = number; + } + + public Integer getType() { + return type; + } + + public void setType(Integer type) { + this.type = type; + } + + public String getNumber() { + return number; + } + + public void setNumber(String number) { + this.number = number; + } + } + + public IdentificationInfo createIdentificationInfo(Integer type, String number){ + return new IdentificationInfo(type,number); + } + + public class ImageInfo{ + @JSONField(name = "FaceID") + private Long faceID; + @JSONField(name = "Name") + private String name; + @JSONField(name = "Size") + private Long size; + @JSONField(name = "Data") + private String data; + + public ImageInfo(Long faceID, String name, Long size, String data) { + this.faceID = faceID; + this.name = name; + this.size = size; + this.data = data; + } + + public Long getFaceID() { + return faceID; + } + + public void setFaceID(Long faceID) { + this.faceID = faceID; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Long getSize() { + return size; + } + + public void setSize(Long size) { + this.size = size; + } + + public String getData() { + return data; + } + + public void setData(String data) { + this.data = data; + } + } + + public ImageInfo createImageInfo(Long faceID, String name, Long size, String data){ + return new ImageInfo(faceID, name, size, data); + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceBaseResponse.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceBaseResponse.java new file mode 100644 index 0000000..fe93b8a --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceBaseResponse.java @@ -0,0 +1,90 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; +import com.google.gson.annotations.SerializedName; + +public class FaceBaseResponse { + @JSONField(name = "ResponseURL") + @SerializedName("ResponseURL") + private String responseUrl; + + @JSONField(name = "CreatedID") + @SerializedName("CreatedID") + private int createdId; + + @JSONField(name = "ResponseCode") + @SerializedName("ResponseCode") + private int responseCode; + + @JSONField(name = "ResponseString") + @SerializedName("ResponseString") + private String responseString; + + @JSONField(name = "StatusCode") + @SerializedName("StatusCode") + private int statusCode; + + @JSONField(name = "StatusString") + @SerializedName("StatusString") + private String statusString; + + //@JSONField(name = "Data") + @SerializedName("Data") + private T data; + + public String getResponseUrl() { + return responseUrl; + } + + public void setResponseUrl(String responseUrl) { + this.responseUrl = responseUrl; + } + + public int getCreatedId() { + return createdId; + } + + public void setCreatedId(int createdId) { + this.createdId = createdId; + } + + public int getResponseCode() { + return responseCode; + } + + public void setResponseCode(int responseCode) { + this.responseCode = responseCode; + } + + public String getResponseString() { + return responseString; + } + + public void setResponseString(String responseString) { + this.responseString = responseString; + } + + public int getStatusCode() { + return statusCode; + } + + public void setStatusCode(int statusCode) { + this.statusCode = statusCode; + } + + public String getStatusString() { + return statusString; + } + + public void setStatusString(String statusString) { + this.statusString = statusString; + } + + public T getData() { + return data; + } + + public void setData(T data) { + this.data = data; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceInfo.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceInfo.java new file mode 100644 index 0000000..f128c92 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceInfo.java @@ -0,0 +1,128 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; + +import java.util.List; + +public class FaceInfo { + @JSONField(name = "ID") + private Long id; + @JSONField(name = "Timestamp") + private Long timestamp; + @JSONField(name = "CapSrc") + private Long capSrc; + @JSONField(name = "FeatureNum") + private Long featureNum; + @JSONField(name = "FeatureList") + private List featureList; + @JSONField(name = "FeatureVersion") + private String featureVersion; + @JSONField(name = "Feature") + private String feature; + @JSONField(name = "Temperature") + private Float temperature; + @JSONField(name = "MaskFlag") + private Long maskFlag; + @JSONField(name = "PanoImage") + private Object panoImage; + @JSONField(name = "FaceImage") + private Object faceImage; + @JSONField(name = "FaceArea") + private Object faceArea; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Long getTimestamp() { + return timestamp; + } + + public void setTimestamp(Long timestamp) { + this.timestamp = timestamp; + } + + public Long getCapSrc() { + return capSrc; + } + + public void setCapSrc(Long capSrc) { + this.capSrc = capSrc; + } + + public Long getFeatureNum() { + return featureNum; + } + + public void setFeatureNum(Long featureNum) { + this.featureNum = featureNum; + } + + public List getFeatureList() { + return featureList; + } + + public void setFeatureList(List featureList) { + this.featureList = featureList; + } + + public String getFeatureVersion() { + return featureVersion; + } + + public void setFeatureVersion(String featureVersion) { + this.featureVersion = featureVersion; + } + + public String getFeature() { + return feature; + } + + public void setFeature(String feature) { + this.feature = feature; + } + + public Float getTemperature() { + return temperature; + } + + public void setTemperature(Float temperature) { + this.temperature = temperature; + } + + public Long getMaskFlag() { + return maskFlag; + } + + public void setMaskFlag(Long maskFlag) { + this.maskFlag = maskFlag; + } + + public Object getPanoImage() { + return panoImage; + } + + public void setPanoImage(Object panoImage) { + this.panoImage = panoImage; + } + + public Object getFaceImage() { + return faceImage; + } + + public void setFaceImage(Object faceImage) { + this.faceImage = faceImage; + } + + public Object getFaceArea() { + return faceArea; + } + + public void setFaceArea(Object faceArea) { + this.faceArea = faceArea; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/LibMatInfo.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/LibMatInfo.java new file mode 100644 index 0000000..ce6dd33 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/LibMatInfo.java @@ -0,0 +1,69 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; + +public class LibMatInfo { + @JSONField(name = "ID") + private Long id; + @JSONField(name = "LibID") + private Long libId; + @JSONField(name = "LibType") + private Long libType; + @JSONField(name = "MatchStatus") + private Long matchStatus; + @JSONField(name = "MatchPersonID") + private Long matchPersonId; + @JSONField(name = "MatchFaceID") + private Long matchFaceId; + + // MatchPersonInfo 暂时忽略不用 + + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Long getLibId() { + return libId; + } + + public void setLibId(Long libId) { + this.libId = libId; + } + + public Long getLibType() { + return libType; + } + + public void setLibType(Long libType) { + this.libType = libType; + } + + public Long getMatchStatus() { + return matchStatus; + } + + public void setMatchStatus(Long matchStatus) { + this.matchStatus = matchStatus; + } + + public Long getMatchPersonId() { + return matchPersonId; + } + + public void setMatchPersonId(Long matchPersonId) { + this.matchPersonId = matchPersonId; + } + + public Long getMatchFaceId() { + return matchFaceId; + } + + public void setMatchFaceId(Long matchFaceId) { + this.matchFaceId = matchFaceId; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/PersonResponseData.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/PersonResponseData.java new file mode 100644 index 0000000..186faed --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/PersonResponseData.java @@ -0,0 +1,31 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; +import com.google.gson.annotations.SerializedName; + +import java.util.List; + +public class PersonResponseData { + @JSONField(name = "Num") + @SerializedName("Num") + private int num; + @JSONField(name = "PersonList") + @SerializedName("PersonList") + private List personList; + + public int getNum() { + return num; + } + + public void setNum(int num) { + this.num = num; + } + + public List getPersonList() { + return personList; + } + + public void setPersonList(List personList) { + this.personList = personList; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/PersonResponseInfo.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/PersonResponseInfo.java new file mode 100644 index 0000000..7ba3edc --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/PersonResponseInfo.java @@ -0,0 +1,67 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; +import com.google.gson.annotations.SerializedName; + +import java.util.List; + +public class PersonResponseInfo { + @JSONField(name = "PersonID") + @SerializedName("PersonID") + private Long personId; + @JSONField(name = "FaceNum") + @SerializedName("FaceNum") + private Long faceNum; + @JSONField(name = "FaceList") + @SerializedName("FaceList") + private List faceList; + + public Long getPersonId() { + return personId; + } + + public void setPersonId(Long personId) { + this.personId = personId; + } + + public Long getFaceNum() { + return faceNum; + } + + public void setFaceNum(Long faceNum) { + this.faceNum = faceNum; + } + + public List getFaceList() { + return faceList; + } + + public void setFaceList(List faceList) { + this.faceList = faceList; + } + + public class PersonResponseFace{ + @JSONField(name = "FaceID") + @SerializedName("FaceID") + private Long faceId; + @JSONField(name = "ResultCode") + @SerializedName("ResultCode") + private Long resultCode; + + public Long getFaceId() { + return faceId; + } + + public void setFaceId(Long faceId) { + this.faceId = faceId; + } + + public Long getResultCode() { + return resultCode; + } + + public void setResultCode(Long resultCode) { + this.resultCode = resultCode; + } + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/RecordNotification.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/RecordNotification.java new file mode 100644 index 0000000..ca52d29 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/RecordNotification.java @@ -0,0 +1,138 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; + +import java.util.List; + +public class RecordNotification { + @JSONField(name = "Reference") + private String reference; + @JSONField(name = "Seq") + private int seq; + @JSONField(name = "DeviceCode") + private String deviceCode; + @JSONField(name = "Timestamp") + private Long timestamp; + @JSONField(name = "NotificationType") + private int notificationType; + @JSONField(name = "FaceInfoNum") + private int faceInfoNum; + @JSONField(name = "FaceInfoList") + private List faceInfoList; + @JSONField(name = "CardInfoNum") + private int cardInfoNum; + @JSONField(name = "CardInfoList") + private List cardInfoList; + @JSONField(name = "GateInfoNum") + private int gateInfoNum; + @JSONField(name = "GateInfoList") + private List gateInfoList; + @JSONField(name = "LibMatInfoNum") + private int libMatInfoNum; + @JSONField(name = "LibMatInfoList") + private List libMatInfoList; + + public String getReference() { + return reference; + } + + public void setReference(String reference) { + this.reference = reference; + } + + public int getSeq() { + return seq; + } + + public void setSeq(int seq) { + this.seq = seq; + } + + public String getDeviceCode() { + return deviceCode; + } + + public void setDeviceCode(String deviceCode) { + this.deviceCode = deviceCode; + } + + public Long getTimestamp() { + return timestamp; + } + + public void setTimestamp(Long timestamp) { + this.timestamp = timestamp; + } + + public int getNotificationType() { + return notificationType; + } + + public void setNotificationType(int notificationType) { + this.notificationType = notificationType; + } + + public int getFaceInfoNum() { + return faceInfoNum; + } + + public void setFaceInfoNum(int faceInfoNum) { + this.faceInfoNum = faceInfoNum; + } + + public List getFaceInfoList() { + return faceInfoList; + } + + public void setFaceInfoList(List faceInfoList) { + this.faceInfoList = faceInfoList; + } + + public int getCardInfoNum() { + return cardInfoNum; + } + + public void setCardInfoNum(int cardInfoNum) { + this.cardInfoNum = cardInfoNum; + } + + public List getCardInfoList() { + return cardInfoList; + } + + public void setCardInfoList(List cardInfoList) { + this.cardInfoList = cardInfoList; + } + + public int getGateInfoNum() { + return gateInfoNum; + } + + public void setGateInfoNum(int gateInfoNum) { + this.gateInfoNum = gateInfoNum; + } + + public List getGateInfoList() { + return gateInfoList; + } + + public void setGateInfoList(List gateInfoList) { + this.gateInfoList = gateInfoList; + } + + public int getLibMatInfoNum() { + return libMatInfoNum; + } + + public void setLibMatInfoNum(int libMatInfoNum) { + this.libMatInfoNum = libMatInfoNum; + } + + public List getLibMatInfoList() { + return libMatInfoList; + } + + public void setLibMatInfoList(List libMatInfoList) { + this.libMatInfoList = libMatInfoList; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/runner/InitSubscribeRunner.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/runner/InitSubscribeRunner.java new file mode 100644 index 0000000..c7d0565 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/runner/InitSubscribeRunner.java @@ -0,0 +1,43 @@ +package com.casic.missiles.modular.system.runner; + +import com.casic.missiles.modular.system.model.Device; +import com.casic.missiles.modular.system.service.IDeviceSupportService; +import com.casic.missiles.modular.system.service.IFaceSyncService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.ApplicationArguments; +import org.springframework.boot.ApplicationRunner; +import org.springframework.stereotype.Component; + +import java.util.ArrayList; +import java.util.List; + +@Component +public class InitSubscribeRunner implements ApplicationRunner { + private static Logger logger = LoggerFactory.getLogger(InitSubscribeRunner.class); + + @Value("${iris.face.initSubscribe}") + private String initSubscribe; + @Autowired + private IDeviceSupportService deviceSupportService; + @Autowired + private IFaceSyncService faceSyncService; + + /** + * 启动项目时,根据需要初始化设备订阅信息 + * @param applicationArguments + * @throws Exception + */ + @Override + public void run(ApplicationArguments applicationArguments) throws Exception { + logger.info("==================initSubscribe: "); + if(Boolean.valueOf(initSubscribe)){ + List deviceList = deviceSupportService.selectDeviceByType("5"); + List deviceIds = new ArrayList<>(); + deviceList.forEach(device -> deviceIds.add(Long.valueOf(device.getId()))); + faceSyncService.initSubscription(deviceIds); + } + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFacePersonSyncService.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFacePersonSyncService.java new file mode 100644 index 0000000..6b2461b --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFacePersonSyncService.java @@ -0,0 +1,18 @@ +package com.casic.missiles.modular.system.service; + +import com.casic.missiles.modular.system.model.FacePersonSync; +import com.baomidou.mybatisplus.service.IService; + +/** + *

+ * 服务类 + *

+ * + * @author zyj123 + * @since 2020-07-24 + */ +public interface IFacePersonSyncService extends IService { + Long selectSyncId(Long personId); + Long selectPersonId(Long syncId); + Long getMaxSyncId(Long personId); +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFaceSubscribeService.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFaceSubscribeService.java new file mode 100644 index 0000000..e0461ed --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFaceSubscribeService.java @@ -0,0 +1,24 @@ +package com.casic.missiles.modular.system.service; + +import com.casic.missiles.modular.system.model.FaceSubscribe; +import com.baomidou.mybatisplus.service.IService; + +import java.util.List; + +/** + *

+ * 服务类 + *

+ * + * @author zyj123 + * @since 2020-07-25 + */ +public interface IFaceSubscribeService extends IService { + + List selectSubscribeIdsByDevCode(String devCode); + + boolean deleteByDevCode(String devCode); + + boolean insertSubscribe(Long subscribeId, String devCode); + +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFaceSyncService.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFaceSyncService.java new file mode 100644 index 0000000..effd921 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFaceSyncService.java @@ -0,0 +1,21 @@ +package com.casic.missiles.modular.system.service; + +import com.casic.missiles.modular.system.response.RecordNotification; + +import java.util.List; + +public interface IFaceSyncService { + String uploadPerson(List personIds, List deviceIds,String personType); + + String checkPersonPhoto(List personIds); + + void receiveRecord(RecordNotification recordNotification); + + void receiveRecord(String recordNotificationStr); + + String initSubscription(List deviceIds); + + boolean deleteSubscription(String deviceIp, Long subscribeId); + + Long createSubscription(String deviceIp,String ip,String port); +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/Impl/FacePersonSyncServiceImpl.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/Impl/FacePersonSyncServiceImpl.java new file mode 100644 index 0000000..d1d1694 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/Impl/FacePersonSyncServiceImpl.java @@ -0,0 +1,55 @@ +package com.casic.missiles.modular.system.service.Impl; + +import com.baomidou.mybatisplus.mapper.EntityWrapper; +import com.casic.missiles.core.util.ToolUtil; +import com.casic.missiles.modular.system.model.FacePersonSync; +import com.casic.missiles.modular.system.dao.FacePersonSyncMapper; +import com.casic.missiles.modular.system.service.IFacePersonSyncService; +import com.baomidou.mybatisplus.service.impl.ServiceImpl; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +/** + *

+ * 服务实现类 + *

+ * + * @author zyj123 + * @since 2020-07-24 + */ +@Service +public class FacePersonSyncServiceImpl extends ServiceImpl implements IFacePersonSyncService { + + @Override + public Long selectSyncId(Long personId) { + FacePersonSync facePersonSync = this.selectById(personId); + if(ToolUtil.isNotEmpty(facePersonSync)){ + return facePersonSync.getSyncId(); + } + return null; + } + + @Override + public Long selectPersonId(Long syncId) { + EntityWrapper query = new EntityWrapper(); + query.eq("SYNC_ID",syncId); + FacePersonSync facePersonSync = this.selectOne(query); + if(ToolUtil.isNotEmpty(facePersonSync)){ + return facePersonSync.getPersonId(); + } + return null; + } + + @Override + @Transactional + public Long getMaxSyncId(Long personId) { + Long maxId = this.baseMapper.getMaxSyncId(); + if(ToolUtil.isEmpty(maxId)){ + maxId = 1000L; + }else { + maxId = maxId + 1; + } + this.insert(new FacePersonSync(personId,maxId)); + return maxId; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/Impl/FaceSubscribeServiceImpl.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/Impl/FaceSubscribeServiceImpl.java new file mode 100644 index 0000000..c04302d --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/Impl/FaceSubscribeServiceImpl.java @@ -0,0 +1,52 @@ +package com.casic.missiles.modular.system.service.Impl; + +import com.baomidou.mybatisplus.mapper.EntityWrapper; +import com.casic.missiles.modular.system.model.FaceSubscribe; +import com.casic.missiles.modular.system.dao.FaceSubscribeMapper; +import com.casic.missiles.modular.system.service.IFaceSubscribeService; +import com.baomidou.mybatisplus.service.impl.ServiceImpl; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +/** + *

+ * 服务实现类 + *

+ * + * @author zyj123 + * @since 2020-07-25 + */ +@Service +public class FaceSubscribeServiceImpl extends ServiceImpl implements IFaceSubscribeService { + + @Override + public List selectSubscribeIdsByDevCode(String devCode) { + EntityWrapper query = new EntityWrapper(); + query.eq("DEVICE_CODE",devCode); + List faceSubscribes = this.selectList(query); + List subscribeIds = new ArrayList<>(); + for (FaceSubscribe faceSubscribe : faceSubscribes) { + subscribeIds.add(faceSubscribe.getSubscribeId()); + } + return subscribeIds; + } + + @Override + public boolean deleteByDevCode(String devCode) { + EntityWrapper query = new EntityWrapper(); + query.eq("DEVICE_CODE",devCode); + return this.delete(query); + } + + @Override + public boolean insertSubscribe(Long subscribeId, String devCode) { + FaceSubscribe faceSubscribe = new FaceSubscribe(); + faceSubscribe.setDeviceCode(devCode); + faceSubscribe.setSubscribeId(subscribeId); + faceSubscribe.setUpdateTime(new Date()); + return this.insert(faceSubscribe); + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/Impl/FaceSyncServiceImpl.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/Impl/FaceSyncServiceImpl.java new file mode 100644 index 0000000..8826be5 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/Impl/FaceSyncServiceImpl.java @@ -0,0 +1,465 @@ +package com.casic.missiles.modular.system.service.Impl; + +import com.alibaba.fastjson.JSONObject; +import com.casic.missiles.core.common.service.ICommonPersonService; +import com.casic.missiles.core.util.ToolUtil; +import com.casic.missiles.modular.system.model.Device; +import com.casic.missiles.modular.system.model.FacePersonSync; +import com.casic.missiles.modular.system.model.Person; +import com.casic.missiles.modular.system.model.RecognitionRecords; +import com.casic.missiles.modular.system.request.PersonInfo; +import com.casic.missiles.modular.system.response.*; +import com.casic.missiles.modular.system.service.*; +import com.casic.missiles.modular.system.util.HttpClientUtil; +import com.google.gson.*; +import org.apache.commons.lang3.StringUtils; +import org.omg.CORBA.Object; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import com.casic.missiles.modular.system.constant.FaceSyncConst; +import java.net.InetAddress; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +@Service +public class FaceSyncServiceImpl implements IFaceSyncService { + private static final Logger logger = LoggerFactory.getLogger(FaceSyncServiceImpl.class); + + @Autowired + private IFacePersonSyncService personSyncService; + @Autowired + private ICommonPersonService commonPersonService; + @Autowired + private IPersonPhotoSupportService photoSupportService; + @Autowired + private IDeviceSupportService deviceSupportService; + @Autowired + private IRecordSupportService recordSupportService; + @Autowired + private IFaceSubscribeService subscribeService; + @Value("${server.port}") + private String serverPort; + @Value("${iris.face.serverHost}") + private String serverHost; + + @Override + @Transactional + public String uploadPerson(List personIds,List deviceIds,String personType) { + String error = null; + + try{ + List personInfoList = new ArrayList<>(personIds.size()); + for (Long personId : personIds) { + Person person = commonPersonService.getPersonById(personId); + Long syncId = getPersonSyncId(personId); + String photoData = photoSupportService.selectPhotoDataById(personId); + PersonInfo personInfo = convPersonInfo(person,syncId,photoData); + personInfoList.add(personInfo); + } + + + outterLoop : for (Long deviceId : deviceIds) { + Device device = deviceSupportService.selectById(deviceId); + // 批量下发(单次最多6个,分多次下发) + int batchSize = FaceSyncConst.UPLOAD_MAX_PERSON; + int batchNum = (int)Math.ceil((double)personInfoList.size()/batchSize); + for (int i = 0; i < batchNum; i++) { + int fromIndex = i * batchSize; + int toIndex = (i+1) * batchSize <= personInfoList.size() ? (i+1) * batchSize : personInfoList.size(); + List subPersonInfoList = personInfoList.subList(fromIndex,toIndex); + + // 设置上传body对象 + Gson gson = new GsonBuilder().serializeNulls().create(); + JsonObject body = new JsonObject(); + JsonElement person = gson.toJsonTree(subPersonInfoList); + body.addProperty("Num",subPersonInfoList.size()); + body.add("PersonInfoList",person); + String bodyStr = gson.toJson(body); +// logger.info(String.valueOf(subPersonInfoList.size())); + logger.info(bodyStr); + +// 调用接口上传 + String devIp = device.getDevIp(); + String personLib = null; + if("1".equals(personType)){ + personLib = FaceSyncConst.UPLOAD_STAFF_LIB; + }else { + personLib = FaceSyncConst.UPLOAD_VISITOR_LIB; + } + + String url = "http://".concat(devIp).concat(FaceSyncConst.UPLOAD_URL_PREFIX).concat(personLib).concat(FaceSyncConst.UPLOAD_URL_SUFFIX); + String responseContent = HttpClientUtil.sendHttpPost(url,bodyStr); + logger.info(responseContent); + JsonObject obj = gson.fromJson(responseContent, JsonObject.class); + // 解析返回结果 + FaceBaseResponse> response = gson.fromJson(obj.get("Response"),FaceBaseResponse.class); + if(response.getResponseCode() == 0 && response.getStatusCode() == 0){ + PersonResponseData personResponseData = gson.fromJson(gson.toJson(response.getData()),PersonResponseData.class); + List responseInfos = personResponseData.getPersonList(); + for(int j = 0;j < responseInfos.size();j++){ + PersonResponseInfo personResponseInfo = gson.fromJson(gson.toJson(responseInfos.get(j)),PersonResponseInfo.class);; + if(personResponseInfo.getFaceList().get(0).getResultCode() == 0){ + // 成功 + logger.info(String.format("人脸数据下发成功,人员:%s,设备: %s",personResponseInfo.getPersonId(),device.getDevCode())); + }else{ + error = convErrorCode(personResponseInfo.getFaceList().get(0).getResultCode()); + String personName = commonPersonService.getPersonById(personIds.get(i)).getName(); + error = String.format("下发失败,%s %s",personName,error); + logger.error(error); + break outterLoop; + } + } + }else { + if(response.getResponseCode() != 0 ){ + error = String.format("设备%s下发失败: %s",device.getDevCode(),response.getResponseString()); + logger.error(error); + break; + } + if(response.getStatusCode() != 0){ + error = String.format("设备%s下发失败: %s",device.getDevCode(),response.getStatusString()); + logger.error(error); + break; + } + } + } + } + }catch (Exception e){ + e.printStackTrace(); + logger.error(e.getMessage()); + error = "下发失败"; + } + + return error; + } + + private void updatePersonInfoList(List personInfoList,List personIds){ + for (int i = 0; i < personIds.size(); i++) { + Long syncId = personSyncService.selectSyncId(personIds.get(i)); + if(ToolUtil.isNotEmpty(syncId)){ + PersonInfo personInfo = personInfoList.get(i); + personInfo.setPersonID(syncId); + if(ToolUtil.isNotEmpty(personInfo.getImageList())){ + personInfo.getImageList().get(i).setFaceID(syncId); + } + } + } + } + + private Long getPersonSyncId(Long personId){ + Long syncId = personSyncService.selectSyncId(personId); + if(ToolUtil.isEmpty(syncId)){ + syncId = personSyncService.getMaxSyncId(personId); + } + return syncId; + } + + private PersonInfo convPersonInfo(Person person,Long syncId,String photoData){ + PersonInfo personInfo = new PersonInfo(); + if(ToolUtil.isNotEmpty(syncId)){ + personInfo.setPersonID(syncId); + } + if(ToolUtil.isNotEmpty(person.getUpdatetime())){ + personInfo.setLastChange(person.getUpdatetime().getTime()); + } + if(ToolUtil.isNotEmpty(person.getPersonCode()) && person.getPersonCode().length() <= FaceSyncConst.UPLOAD_PERSONCODE_MAXLENGTH){ + personInfo.setPersonCode(person.getPersonCode()); + }else { + personInfo.setPersonCode(String.valueOf(syncId)); + } + if(ToolUtil.isNotEmpty(person.getName())){ + personInfo.setPersonName(person.getName()); + } + if(ToolUtil.isNotEmpty(person.getRemarks()) && person.getRemarks().length() <= FaceSyncConst.UPLOAD_REMARK_MAXLENGTH){ + personInfo.setRemarks(person.getRemarks()); + }else { + personInfo.setRemarks(""); + } + + // 时间模板 + personInfo.setTimeTemplateNum(0); + List timeTemplateList = new ArrayList<>(); + timeTemplateList.add(personInfo.createTimeTemplate(0L,4294967295L,0L)); + personInfo.setTimeTemplateList(timeTemplateList); + + // 证件列表 + if(ToolUtil.isNotEmpty(person.getIdCardNo())){ + personInfo.setIdentificationNum(1); + List identificationInfoList = new ArrayList<>(); + identificationInfoList.add(personInfo.createIdentificationInfo(1,person.getIdCardNo())); + personInfo.setIdentificationList(identificationInfoList); + }else{ + personInfo.setIdentificationNum(0); + } + + // 图片列表 + if(ToolUtil.isNotEmpty(photoData)){ + personInfo.setImageNum(1); + List imageInfoList = new ArrayList<>(); + // 图片base64码 + if(photoData.startsWith("data") || photoData.startsWith("base64")){ + int splitIndex = photoData.indexOf(","); + photoData = photoData.substring(splitIndex+1); + } + imageInfoList.add(personInfo.createImageInfo(syncId,person.getPhoto(),Long.valueOf(photoData.length()),photoData)); + personInfo.setImageList(imageInfoList); + }else { + personInfo.setImageNum(0); + } + return personInfo; + } + + private String convErrorCode(Long errorCode){ + String errorMsg = ""; + switch (errorCode.intValue()){ + case 1000: + errorMsg = "算法初始化失败"; + break; + case 1001: + errorMsg = "人脸检测失败"; + break; + case 1002: + errorMsg = "图片未检测到人脸"; + break; + case 1003: + errorMsg = "jpeg照片解码失败"; + break; + case 1004: + errorMsg = "图片质量分数不满足"; + break; + case 1005: + errorMsg = "图片缩放失败"; + break; + case 1006: + errorMsg = "未启用智能"; + break; + case 1007: + errorMsg = "导入图片过小"; + break; + case 1008: + errorMsg = "导入图片过大"; + break; + case 1009: + errorMsg = "导入图片分辨率超过1920*1080"; + break; + case 1010: + errorMsg = "导入图片不存在"; + break; + case 1011: + errorMsg = "人脸元素个数已达到上限"; + break; + case 1012: + errorMsg = "智能棒算法模型不匹配"; + break; + case 1013: + errorMsg = "人脸导入库成员证件号非法"; + break; + case 1014: + errorMsg = "人脸导入库成员图片格式错误"; + break; + case 1015: + errorMsg = "通道布控已达设备能力上限"; + break; + case 1016: + errorMsg = "其它客户端正在进行操作人脸库"; + break; + case 1017: + errorMsg = "人脸库文件正在更新中"; + break; + case 1018: + errorMsg = "Json反序列化失败"; + break; + case 1019: + errorMsg = "Base64解码失败"; + break; + case 1020: + errorMsg = "人脸照片,编码后的大小和实际接收到的长度不一致,关注Data和Size大小是否正确"; + break; + default: + break; + } + return errorMsg; + + } + + @Override + public String checkPersonPhoto(List personIds) { + String error = null; + for (Long personId : personIds) { + Person person = commonPersonService.getPersonById(personId); + String photoData = photoSupportService.selectPhotoDataById(personId); + if(ToolUtil.isEmpty(photoData)){ + error = String.format("%s 未上传照片",person.getName()); + break; + } + if(photoData.startsWith("data") || photoData.startsWith("base64")){ + int splitIndex = photoData.indexOf(","); + photoData = photoData.substring(splitIndex+1); + } + if(!photoData.startsWith("/9j")){ + error = String.format("%s人员照片不符合要求,必须为jpg格式",person.getName()); + break; + } + + // 找到等号,把等号也去掉 + int equalIndex = photoData.indexOf('='); + if(equalIndex>=0) { + photoData=photoData.substring(0, equalIndex); + } + // 原来的字符流大小,单位为字节 + int strLength=photoData.length(); + // 计算后得到的文件流大小,单位为字节 + int fileLength=Integer.valueOf(strLength-(strLength/8)*2); + if(fileLength / 1024 < 20){ + error = String.format("%s人员照片不符合要求,照片必须大于20Kb",person.getName()); + break; + } + } + return error; + } + + @Override + public void receiveRecord(RecordNotification recordNotification){ +// if(recordNotification.getFaceInfoNum() != recordNotification.getLibMatInfoNum()){ +// logger.error("采集和匹配数据不一致,识别失败"); +// } else { + String deviceCode = recordNotification.getDeviceCode(); + List recordsList = new ArrayList<>(); + for (int i = 0; i < recordNotification.getLibMatInfoNum(); i++) { + //FaceInfo faceInfo = recordNotification.getFaceInfoList().get(i); + LibMatInfo libMatInfo = recordNotification.getLibMatInfoList().get(i); + if(libMatInfo.getMatchStatus() == 1){ + FaceInfo faceInfo = getFaceInfoByMatchId(recordNotification.getFaceInfoList(),libMatInfo.getId()); + Long personId = personSyncService.selectPersonId(libMatInfo.getMatchPersonId()); + if(ToolUtil.isNotEmpty(personId) && ToolUtil.isNotEmpty(faceInfo)){ + RecognitionRecords record = new RecognitionRecords(); + record.setPersonId(personId); + record.setDatetime(new Date(faceInfo.getTimestamp()*1000)); + record.setDevCode(deviceCode); + if(ToolUtil.isNotEmpty(faceInfo.getTemperature())){ + record.setTemperature(String.valueOf(faceInfo.getTemperature())); + } + record.setOriginalId(libMatInfo.getId()); + record.setSyncTime(new Date()); + + Device device = deviceSupportService.selectDeviceByCode(deviceCode); + if(ToolUtil.isNotEmpty(device)){ + if(ToolUtil.isNotEmpty(device.getDevIp())){ + record.setDevIp(device.getDevIp()); + } + } + + recordsList.add(record); + } + } + } + if(ToolUtil.isNotEmpty(recordsList)){ + recordSupportService.insertBatch(recordsList); + } + } + + @Override + public void receiveRecord(String recordNotificationStr) { + RecordNotification recordNotification = JSONObject.parseObject(recordNotificationStr,RecordNotification.class); + receiveRecord(recordNotification); + } + + public FaceInfo getFaceInfoByMatchId(List faceInfoList ,Long id){ + for (FaceInfo faceInfo : faceInfoList) { + if(faceInfo.getId().equals(id)){ + return faceInfo; + } + } + return null; + } + + @Override + public String initSubscription(List deviceIds) { + try { + List error = new ArrayList<>(); + for (Long deviceId : deviceIds) { + Device device = deviceSupportService.selectById(deviceId); + List subscribeIds = subscribeService.selectSubscribeIdsByDevCode(device.getDevCode());; + // 删除所有id + boolean flag = true; + for (Long subscribeId : subscribeIds) { + flag = flag && deleteSubscription(device.getDevIp(),subscribeId); + } + flag = flag && subscribeService.deleteByDevCode(device.getDevCode()); + // 创建订阅 + Long subscribeId = createSubscription(device.getDevIp(),serverHost,serverPort); + flag = flag && ToolUtil.isNotEmpty(subscribeId); + if(ToolUtil.isNotEmpty(subscribeId)){ + flag = flag && subscribeService.insertSubscribe(subscribeId,device.getDevCode()); + } + if(!flag){ + logger.error(String.format("device %s init subsrciption error",device.getDevCode())); + error.add(device.getDevCode()); + } + } + if(ToolUtil.isNotEmpty(error)){ + return StringUtils.join(error,",").concat("订阅失败"); + }else { + return null; + } + }catch (Exception e){ + e.printStackTrace(); + logger.error(e.getMessage()); + return "订阅失败"; + } + + } + + @Override + public boolean deleteSubscription(String deviceIp, Long subscribeId) { + String url = "http://" + deviceIp + FaceSyncConst.SUBSCRIBE_URL + subscribeId; + String responseContent = HttpClientUtil.sendHttpDelete(url); + logger.info(responseContent); + Gson gson = new Gson(); + JsonObject obj = gson.fromJson(responseContent, JsonObject.class); + logger.info(obj.get("Response").toString()); + FaceBaseResponse response = gson.fromJson(obj.get("Response"),FaceBaseResponse.class); + if(response.getResponseCode() == 0 && response.getStatusCode() == 0){ + return true; + }else { + logger.error(String.format("delele subscribe error, device '%s', subscribeId '%s', response '%s', status '%s'",deviceIp,subscribeId,response.getResponseString(),response.getStatusString())); + return false; + } + } + + @Override + public Long createSubscription(String deviceIp, String ip, String port) { + JsonObject request = new JsonObject(); + request.addProperty("AddressType",0); + request.addProperty("IPAddress",ip); + request.addProperty("Port",Long.valueOf(port)); + request.addProperty("Duration",4294967295L); + request.addProperty("Type",1024); + JsonObject subscribePersonCondition = new JsonObject(); + subscribePersonCondition.addProperty("LibIDNum",65535); + subscribePersonCondition.add("LibIDList",new JsonArray()); + request.add("SubscribePersonCondition",subscribePersonCondition); + Gson gson = new Gson(); + String requestStr = gson.toJson(request); + System.out.println(requestStr); + String url = "http://" + deviceIp + FaceSyncConst.SUBSCRIBE_URL ; + String responseContent = HttpClientUtil.sendHttpPostJson(url,requestStr); + logger.info(responseContent); + JsonObject obj = gson.fromJson(responseContent, JsonObject.class); + FaceBaseResponse response = gson.fromJson(obj.get("Response"),FaceBaseResponse.class); + if(response.getResponseCode() == 0 && response.getStatusCode()==0){ + JsonObject data = gson.fromJson(gson.toJson(response.getData()),JsonObject.class); + Long subsrcibeId = data.get("ID").getAsLong(); + logger.info(String.format("create subscribe success, device '%s', subsrcibeId '%s'",deviceIp,subsrcibeId)); + return subsrcibeId; + }else { + logger.error(String.format("create subscribe error, device '%s', response '%s', status '%s'",deviceIp,response.getResponseString(),response.getStatusString())); + return null; + } + } + +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/util/HttpClientUtil.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/util/HttpClientUtil.java new file mode 100644 index 0000000..e258174 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/util/HttpClientUtil.java @@ -0,0 +1,468 @@ +package com.casic.missiles.modular.system.util; + +import java.io.File; +import java.io.IOException; +import java.security.KeyManagementException; +import java.security.KeyStoreException; +import java.security.NoSuchAlgorithmException; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.apache.http.HttpEntity; +import org.apache.http.HttpStatus; +import org.apache.http.client.config.RequestConfig; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpDelete; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.config.Registry; +import org.apache.http.config.RegistryBuilder; +import org.apache.http.conn.socket.ConnectionSocketFactory; +import org.apache.http.conn.socket.PlainConnectionSocketFactory; +import org.apache.http.conn.ssl.SSLConnectionSocketFactory; +import org.apache.http.conn.ssl.SSLContextBuilder; +import org.apache.http.conn.ssl.TrustSelfSignedStrategy; +import org.apache.http.entity.ContentType; +import org.apache.http.entity.StringEntity; +import org.apache.http.entity.mime.MultipartEntityBuilder; +import org.apache.http.entity.mime.content.FileBody; +import org.apache.http.entity.mime.content.StringBody; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.DefaultHttpRequestRetryHandler; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; +import org.apache.http.util.EntityUtils; + +/** + * + * @author H__D + * @date 2016年10月19日 上午11:27:25 + * + */ +public class HttpClientUtil { + + // utf-8字符编码 + public static final String CHARSET_UTF_8 = "utf-8"; + + // HTTP内容类型。 + public static final String CONTENT_TYPE_TEXT_HTML = "text/xml"; + + // HTTP内容类型。相当于form表单的形式,提交数据 + public static final String CONTENT_TYPE_FORM_URL = "application/x-www-form-urlencoded"; + + // HTTP内容类型。相当于form表单的形式,提交数据 + public static final String CONTENT_TYPE_JSON_URL = "application/json;charset=utf-8"; + + + // 连接管理器 + private static PoolingHttpClientConnectionManager pool; + + // 请求配置 + private static RequestConfig requestConfig; + + static { + + try { + //System.out.println("初始化HttpClientTest~~~开始"); + SSLContextBuilder builder = new SSLContextBuilder(); + builder.loadTrustMaterial(null, new TrustSelfSignedStrategy()); + SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory( + builder.build()); + // 配置同时支持 HTTP 和 HTPPS + Registry socketFactoryRegistry = RegistryBuilder. create().register( + "http", PlainConnectionSocketFactory.getSocketFactory()).register( + "https", sslsf).build(); + // 初始化连接管理器 + pool = new PoolingHttpClientConnectionManager( + socketFactoryRegistry); + // 将最大连接数增加到200,实际项目最好从配置文件中读取这个值 + pool.setMaxTotal(200); + // 设置最大路由 + pool.setDefaultMaxPerRoute(2); + // 根据默认超时限制初始化requestConfig + int socketTimeout = 10000; + int connectTimeout = 10000; + int connectionRequestTimeout = 10000; + requestConfig = RequestConfig.custom().setConnectionRequestTimeout( + connectionRequestTimeout).setSocketTimeout(socketTimeout).setConnectTimeout( + connectTimeout).build(); + + //System.out.println("初始化HttpClientTest~~~结束"); + } catch (NoSuchAlgorithmException e) { + e.printStackTrace(); + } catch (KeyStoreException e) { + e.printStackTrace(); + } catch (KeyManagementException e) { + e.printStackTrace(); + } + + + // 设置请求超时时间 + requestConfig = RequestConfig.custom().setSocketTimeout(50000).setConnectTimeout(50000) + .setConnectionRequestTimeout(50000).build(); + } + + public static CloseableHttpClient getHttpClient() { + + CloseableHttpClient httpClient = HttpClients.custom() + // 设置连接池管理 + .setConnectionManager(pool) + // 设置请求配置 + .setDefaultRequestConfig(requestConfig) + // 设置重试次数 + .setRetryHandler(new DefaultHttpRequestRetryHandler(0, false)) + .build(); + + return httpClient; + } + + /** + * 发送Post请求 + * + * @param httpPost + * @return + */ + private static String sendHttpPost(HttpPost httpPost) { + + CloseableHttpClient httpClient = null; + CloseableHttpResponse response = null; + // 响应内容 + String responseContent = null; + try { + // 创建默认的httpClient实例. + httpClient = getHttpClient(); + // 配置请求信息 + httpPost.setConfig(requestConfig); + // 执行请求 + response = httpClient.execute(httpPost); + // 得到响应实例 + HttpEntity entity = response.getEntity(); + + // 可以获得响应头 + // Header[] headers = response.getHeaders(HttpHeaders.CONTENT_TYPE); + // for (Header header : headers) { + // System.out.println(header.getName()); + // } + + // 得到响应类型 + // System.out.println(ContentType.getOrDefault(response.getEntity()).getMimeType()); + + // 判断响应状态 + if (response.getStatusLine().getStatusCode() >= 300) { + throw new Exception( + "HTTP Request is not success, Response code is " + response.getStatusLine().getStatusCode()); + } + + if (HttpStatus.SC_OK == response.getStatusLine().getStatusCode()) { + responseContent = EntityUtils.toString(entity, CHARSET_UTF_8); + EntityUtils.consume(entity); + } + + } catch (Exception e) { + e.printStackTrace(); + } finally { + try { + // 释放资源 + if (response != null) { + response.close(); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + return responseContent; + } + + /** + * 发送Get请求 + * + * @param httpGet + * @return + */ + private static String sendHttpGet(HttpGet httpGet) { + + CloseableHttpClient httpClient = null; + CloseableHttpResponse response = null; + // 响应内容 + String responseContent = null; + try { + // 创建默认的httpClient实例. + httpClient = getHttpClient(); + // 配置请求信息 + httpGet.setConfig(requestConfig); + // 执行请求 + response = httpClient.execute(httpGet); + // 得到响应实例 + HttpEntity entity = response.getEntity(); + + // 可以获得响应头 + // Header[] headers = response.getHeaders(HttpHeaders.CONTENT_TYPE); + // for (Header header : headers) { + // System.out.println(header.getName()); + // } + + // 得到响应类型 + // System.out.println(ContentType.getOrDefault(response.getEntity()).getMimeType()); + + // 判断响应状态 + if (response.getStatusLine().getStatusCode() >= 300) { + throw new Exception( + "HTTP Request is not success, Response code is " + response.getStatusLine().getStatusCode()); + } + + if (HttpStatus.SC_OK == response.getStatusLine().getStatusCode()) { + responseContent = EntityUtils.toString(entity, CHARSET_UTF_8); + EntityUtils.consume(entity); + } + + } catch (Exception e) { + e.printStackTrace(); + } finally { + try { + // 释放资源 + if (response != null) { + response.close(); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + return responseContent; + } + + /** + * 发送Delete请求 + * + * @param httpDelete + * @return + */ + private static String sendHttpDelete(HttpDelete httpDelete) { + + CloseableHttpClient httpClient = null; + CloseableHttpResponse response = null; + // 响应内容 + String responseContent = null; + try { + // 创建默认的httpClient实例. + httpClient = getHttpClient(); + // 配置请求信息 + httpDelete.setConfig(requestConfig); + // 执行请求 + response = httpClient.execute(httpDelete); + // 得到响应实例 + HttpEntity entity = response.getEntity(); + + // 可以获得响应头 + // Header[] headers = response.getHeaders(HttpHeaders.CONTENT_TYPE); + // for (Header header : headers) { + // System.out.println(header.getName()); + // } + + // 得到响应类型 + // System.out.println(ContentType.getOrDefault(response.getEntity()).getMimeType()); + + // 判断响应状态 + if (response.getStatusLine().getStatusCode() >= 300) { + throw new Exception( + "HTTP Request is not success, Response code is " + response.getStatusLine().getStatusCode()); + } + + if (HttpStatus.SC_OK == response.getStatusLine().getStatusCode()) { + responseContent = EntityUtils.toString(entity, CHARSET_UTF_8); + EntityUtils.consume(entity); + } + + } catch (Exception e) { + e.printStackTrace(); + } finally { + try { + // 释放资源 + if (response != null) { + response.close(); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + return responseContent; + } + + + + /** + * 发送 post请求 + * + * @param httpUrl 地址 + */ + public static String sendHttpPost(String httpUrl) { + // 创建httpPost + HttpPost httpPost = new HttpPost(httpUrl); + return sendHttpPost(httpPost); + } + + /** + * 发送 get请求 + * + * @param httpUrl + */ + public static String sendHttpGet(String httpUrl) { + // 创建get请求 + HttpGet httpGet = new HttpGet(httpUrl); + return sendHttpGet(httpGet); + } + + /** + * 发送 DELETE 请求 + * + * @param httpUrl + */ + public static String sendHttpDelete(String httpUrl) { + // 创建delete请求 + HttpDelete httpDelete = new HttpDelete(httpUrl); + return sendHttpDelete(httpDelete); + } + + + + /** + * 发送 post请求(带文件) + * + * @param httpUrl + * 地址 + * @param maps + * 参数 + * @param fileLists + * 附件 + */ + public static String sendHttpPost(String httpUrl, Map maps, List fileLists) { + HttpPost httpPost = new HttpPost(httpUrl);// 创建httpPost + MultipartEntityBuilder meBuilder = MultipartEntityBuilder.create(); + if (maps != null) { + for (String key : maps.keySet()) { + meBuilder.addPart(key, new StringBody(maps.get(key), ContentType.TEXT_PLAIN)); + } + } + if (fileLists != null) { + for (File file : fileLists) { + FileBody fileBody = new FileBody(file); + meBuilder.addPart("files", fileBody); + } + } + HttpEntity reqEntity = meBuilder.build(); + httpPost.setEntity(reqEntity); + return sendHttpPost(httpPost); + } + + /** + * 发送 post请求 + * + * @param httpUrl + * 地址 + * @param params + * 参数(格式:key1=value1&key2=value2) + * + */ + public static String sendHttpPost(String httpUrl, String params) { + HttpPost httpPost = new HttpPost(httpUrl);// 创建httpPost + try { + // 设置参数 + if (params != null && params.trim().length() > 0) { + StringEntity stringEntity = new StringEntity(params, "UTF-8"); + stringEntity.setContentType(CONTENT_TYPE_FORM_URL); + httpPost.setEntity(stringEntity); + } + } catch (Exception e) { + throw e; + } + return sendHttpPost(httpPost); + } + + /** + * 发送 post请求 + * + * @param maps + * 参数 + */ + public static String sendHttpPost(String httpUrl, Map maps) { + String parem = convertStringParamter(maps); + return sendHttpPost(httpUrl, parem); + } + + + + + /** + * 发送 post请求 发送json数据 + * + * @param httpUrl 地址 + * @param paramsJson 参数(格式 json) + * + */ + public static String sendHttpPostJson(String httpUrl, String paramsJson) { + HttpPost httpPost = new HttpPost(httpUrl);// 创建httpPost + try { + // 设置参数 + if (paramsJson != null && paramsJson.trim().length() > 0) { + StringEntity stringEntity = new StringEntity(paramsJson, "UTF-8"); + stringEntity.setContentType(CONTENT_TYPE_JSON_URL); + httpPost.setEntity(stringEntity); + } + } catch (Exception e) { + e.printStackTrace(); + } + return sendHttpPost(httpPost); + } + + /** + * 发送 post请求 发送xml数据 + * + * @param httpUrl 地址 + * @param paramsXml 参数(格式 Xml) + * + */ + public static String sendHttpPostXml(String httpUrl, String paramsXml) { + HttpPost httpPost = new HttpPost(httpUrl);// 创建httpPost + try { + // 设置参数 + if (paramsXml != null && paramsXml.trim().length() > 0) { + StringEntity stringEntity = new StringEntity(paramsXml, "UTF-8"); + stringEntity.setContentType(CONTENT_TYPE_TEXT_HTML); + httpPost.setEntity(stringEntity); + } + } catch (Exception e) { + e.printStackTrace(); + } + return sendHttpPost(httpPost); + } + + + /** + * 将map集合的键值对转化成:key1=value1&key2=value2 的形式 + * + * @param parameterMap 需要转化的键值对集合 + * @return 字符串 + */ + public static String convertStringParamter(Map parameterMap) { + StringBuffer parameterBuffer = new StringBuffer(); + if (parameterMap != null) { + Iterator iterator = parameterMap.keySet().iterator(); + String key = null; + String value = null; + while (iterator.hasNext()) { + key = (String) iterator.next(); + if (parameterMap.get(key) != null) { + value = (String) parameterMap.get(key); + } else { + value = ""; + } + parameterBuffer.append(key).append("=").append(value); + if (iterator.hasNext()) { + parameterBuffer.append("&"); + } + } + } + return parameterBuffer.toString(); + } + +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/util/ImageUtil.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/util/ImageUtil.java new file mode 100644 index 0000000..4586ad1 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/util/ImageUtil.java @@ -0,0 +1,30 @@ +package com.casic.missiles.modular.system.util; + +import javax.imageio.ImageIO; +import java.awt.*; +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.IOException; + +public class ImageUtil { + public static void main(String[] args) { + BufferedImage bufferedImage; + try { + // read image file + bufferedImage = ImageIO.read(new File("C:\\Users\\zhang\\Desktop\\test.png")); + // create a blank, RGB, same width and height, and a white + // background + BufferedImage newBufferedImage = new BufferedImage( + bufferedImage.getWidth(), bufferedImage.getHeight(), + BufferedImage.TYPE_INT_RGB); + // TYPE_INT_RGB:创建一个RBG图像,24位深度,成功将32位图转化成24位 + newBufferedImage.createGraphics().drawImage(bufferedImage, 0, 0, + Color.WHITE, null); + // write to jpeg file + ImageIO.write(newBufferedImage, "jpg", new File("C:\\Users\\zhang\\Desktop\\test.jpg")); + System.out.println("Done"); + } catch (IOException e) { + e.printStackTrace(); + } + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/util/LocalHostUtil.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/util/LocalHostUtil.java new file mode 100644 index 0000000..1f6c639 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/util/LocalHostUtil.java @@ -0,0 +1,111 @@ +package com.casic.missiles.modular.system.util; + +import java.net.InetAddress; +import java.net.NetworkInterface; +import java.net.SocketException; +import java.net.UnknownHostException; +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.List; + +/** + * 本地主机工具类 + * + * @author zhi + * @since 2019年11月13日09:04:36 + * + */ +public class LocalHostUtil { + + /** + * 获取主机名称 + * + * @return + * @throws UnknownHostException + */ + public static String getHostName() throws UnknownHostException { + return InetAddress.getLocalHost().getHostName(); + } + + /** + * 获取系统首选IP + * + * @return + * @throws UnknownHostException + */ + public static String getLocalIP() throws UnknownHostException { + return InetAddress.getLocalHost().getHostAddress(); + } + + /** + * 获取所有网卡IP,排除回文地址、虚拟地址 + * + * @return + * @throws SocketException + */ + public static String[] getLocalIPs() throws SocketException { + List list = new ArrayList<>(); + Enumeration enumeration = NetworkInterface.getNetworkInterfaces(); + while (enumeration.hasMoreElements()) { + NetworkInterface intf = enumeration.nextElement(); + if (intf.isLoopback() || intf.isVirtual()) { // + continue; + } + Enumeration inets = intf.getInetAddresses(); + while (inets.hasMoreElements()) { + InetAddress addr = inets.nextElement(); + if (addr.isLoopbackAddress() || !addr.isSiteLocalAddress() || addr.isAnyLocalAddress()) { + continue; + } + list.add(addr.getHostAddress()); + } + } + return list.toArray(new String[0]); + } + + /** + * 判断操作系统是否是Windows + * + * @return + */ + public static boolean isWindowsOS() { + boolean isWindowsOS = false; + String osName = System.getProperty("os.name"); + if (osName.toLowerCase().indexOf("windows") > -1) { + isWindowsOS = true; + } + return isWindowsOS; + } + + public static void main(String[] args) { +// try { +// System.out.println("主机是否为Windows系统:" + LocalHostUtil.isWindowsOS()); +// System.out.println("主机名称:" + LocalHostUtil.getHostName()); +// System.out.println("系统首选IP:" + LocalHostUtil.getLocalIP()); +// System.out.println("系统所有IP:" + String.join(",", LocalHostUtil.getLocalIPs())); +// } catch (UnknownHostException e) { +// } catch (Exception e) { +// e.printStackTrace(); +// } + try { + Enumeration faces = NetworkInterface.getNetworkInterfaces(); + while (faces.hasMoreElements()) { // 遍历网络接口 + NetworkInterface face = faces.nextElement(); + if (face.isLoopback() || face.isVirtual() || !face.isUp()) { + continue; + } + System.out.print("网络接口名:" + face.getDisplayName() + ",地址:"); + Enumeration address = face.getInetAddresses(); + while (address.hasMoreElements()) { // 遍历网络地址 + InetAddress addr = address.nextElement(); + if (!addr.isLoopbackAddress() && addr.isSiteLocalAddress() && !addr.isAnyLocalAddress()) { + System.out.print(addr.getHostAddress() + " "); + } + } + System.out.println(""); + } + } catch (SocketException e) { + e.printStackTrace(); + } + } +} diff --git a/casic-face-sync/pom.xml b/casic-face-sync/pom.xml new file mode 100644 index 0000000..24dc884 --- /dev/null +++ b/casic-face-sync/pom.xml @@ -0,0 +1,74 @@ + + + 4.0.0 + + com.casic + casic-iris-parent + 1.0.0-SNAPSHOT + ../pom.xml + + + + casic-face-sync + ${pro.version} + jar + casic-face-sync + + + + + + com.casic + casic-core + ${core.version} + + + + com.casic + casic-admin-support + ${admin.version} + + + com.casic + casic-iris-support + ${pro.version} + + + + org.apache.httpcomponents + httpclient + 4.5.3 + + + + org.apache.httpcomponents + httpcore + 4.4.8 + + + + org.apache.httpcomponents + httpmime + 4.5.3 + + + + com.google.code.gson + gson + + + + + + + + src/main/java + + **/*.xml + + + + + \ No newline at end of file diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/constant/FaceSyncConst.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/constant/FaceSyncConst.java new file mode 100644 index 0000000..352d47d --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/constant/FaceSyncConst.java @@ -0,0 +1,29 @@ +package com.casic.missiles.modular.system.constant; + +public class FaceSyncConst { + + /** + * 单次最大批量上传人员数 + */ + public static final int UPLOAD_MAX_PERSON = 6; + + /** + * 上传人员库 + */ + public static final String UPLOAD_STAFF_LIB = "3"; + public static final String UPLOAD_VISITOR_LIB = "4"; + + public static final String UPLOAD_URL_PREFIX = "/LAPI/V1.0/PeopleLibraries/"; + + public static final String UPLOAD_URL_SUFFIX = "/People"; + + public static final int UPLOAD_PERSONCODE_MAXLENGTH = 15; + + public static final int UPLOAD_REMARK_MAXLENGTH = 63; + + public static final String SUBSCRIBE_URL = "/LAPI/V1.0/System/Event/Subscription/"; + + public static final String STAFF_PERSON_TYPE = "1"; + + public static final String VISITOR_PERSON_TYPE = "0"; +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/controller/FaceSyncController.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/controller/FaceSyncController.java new file mode 100644 index 0000000..1b35431 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/controller/FaceSyncController.java @@ -0,0 +1,117 @@ +package com.casic.missiles.modular.system.controller; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson.serializer.SerializerFeature; +import com.casic.missiles.core.base.response.ResponseData; +import com.casic.missiles.core.common.service.ICommonPermissionService; +import com.casic.missiles.core.common.service.ICommonPersonService; +import com.casic.missiles.core.datascope.DataScope; +import com.casic.missiles.core.util.ToolUtil; +import com.casic.missiles.modular.system.request.PersonInfo; +import com.casic.missiles.modular.system.response.RecordNotification; +import com.casic.missiles.modular.system.service.IFaceSyncService; +import com.casic.missiles.modular.system.service.IIrisPersonSupportService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.*; +import com.casic.missiles.modular.system.constant.FaceSyncConst; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + + + +@Controller +public class FaceSyncController { + private final static Logger logger = LoggerFactory.getLogger(FaceSyncController.class); + + @Autowired + private IFaceSyncService syncService; + @Autowired + private ICommonPersonService commonPersonService; + @Autowired + private IIrisPersonSupportService personSupportService; + @Autowired + private ICommonPermissionService permissionService; + + @RequestMapping("/face/upload") + @ResponseBody + public Object upload(@RequestParam("personIds") List personIds, + @RequestParam("deviceIds") List deviceIds, + @RequestParam("personType")String personType ){ + // 检查数量 +// if(personIds.size()>FaceSyncConst.UPLOAD_MAX_PERSON){ +// return ResponseData.error(String.format("每次最多上传%s个人",FaceSyncConst.UPLOAD_MAX_PERSON)); +// } + // 检查照片格式及大小 + String photoCheck = syncService.checkPersonPhoto(personIds); + if(ToolUtil.isNotEmpty(photoCheck)){ + return ResponseData.error(photoCheck); + } + else{ + // 上传数据 + String error = syncService.uploadPerson(personIds,deviceIds,personType); + if(ToolUtil.isNotEmpty(error)){ + return ResponseData.error(error); + } + } + return ResponseData.success(); + } + + @RequestMapping("/face/uploadAll") + @ResponseBody + public Object uploadAll(@RequestParam("deviceIds") List deviceIds){ + DataScope dataScope = permissionService.getCurrUserDataScope(); + + List staffPersonIds = personSupportService.listIdsByType(dataScope,FaceSyncConst.STAFF_PERSON_TYPE); + List visitorPersonIds = personSupportService.listIdsByType(dataScope,FaceSyncConst.VISITOR_PERSON_TYPE); + // 1.检查照片,分别检查员工、访客 + String staffPhotoCheck = syncService.checkPersonPhoto(staffPersonIds); + if(ToolUtil.isNotEmpty(staffPhotoCheck)){ + return ResponseData.error(staffPhotoCheck); + } + String visitorPhotoCheck = syncService.checkPersonPhoto(visitorPersonIds); + if(ToolUtil.isNotEmpty(visitorPhotoCheck)){ + return ResponseData.error(visitorPhotoCheck); + } + + // 2. 下发数据 + String staffError = syncService.uploadPerson(staffPersonIds,deviceIds,FaceSyncConst.STAFF_PERSON_TYPE); + if(ToolUtil.isNotEmpty(staffError)){ + return ResponseData.error(staffError); + } + String visitorError = syncService.uploadPerson(visitorPersonIds,deviceIds,FaceSyncConst.VISITOR_PERSON_TYPE); + if(ToolUtil.isNotEmpty(visitorError)){ + return ResponseData.error(visitorError); + } + + return ResponseData.success(); + } + + // 错误信息返回 + @RequestMapping("/subsrcibe/init") + @ResponseBody + public Object upload(@RequestParam("deviceIds") List deviceIds){ + String errorMsg = syncService.initSubscription(deviceIds); + if(ToolUtil.isNotEmpty(errorMsg)){ + return ResponseData.error(errorMsg); + } + return ResponseData.success(); + } + + + @RequestMapping(value = "/LAPI/V1.0/System/Event/Notification/PersonVerification", method = RequestMethod.POST) + @ResponseBody + public void verification(@RequestBody String recordNotification){ + logger.info(recordNotification); + RecordNotification record = JSONObject.parseObject(recordNotification,RecordNotification.class); + syncService.receiveRecord(record); + //return ResponseData.success(); + } + + +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FacePersonSyncMapper.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FacePersonSyncMapper.java new file mode 100644 index 0000000..af53702 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FacePersonSyncMapper.java @@ -0,0 +1,17 @@ +package com.casic.missiles.modular.system.dao; + +import com.casic.missiles.modular.system.model.FacePersonSync; +import com.baomidou.mybatisplus.mapper.BaseMapper; + +/** + *

+ * Mapper 接口 + *

+ * + * @author zyj123 + * @since 2020-07-24 + */ +public interface FacePersonSyncMapper extends BaseMapper { + + Long getMaxSyncId(); +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FaceSubscribeMapper.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FaceSubscribeMapper.java new file mode 100644 index 0000000..0c6374a --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FaceSubscribeMapper.java @@ -0,0 +1,16 @@ +package com.casic.missiles.modular.system.dao; + +import com.casic.missiles.modular.system.model.FaceSubscribe; +import com.baomidou.mybatisplus.mapper.BaseMapper; + +/** + *

+ * Mapper 接口 + *

+ * + * @author zyj123 + * @since 2020-07-25 + */ +public interface FaceSubscribeMapper extends BaseMapper { + +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FacePersonSyncMapper.xml b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FacePersonSyncMapper.xml new file mode 100644 index 0000000..ac46ad0 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FacePersonSyncMapper.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + PERSON_ID AS personId, SYNC_ID AS syncId + + + + + diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FaceSubscribeMapper.xml b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FaceSubscribeMapper.xml new file mode 100644 index 0000000..16024e2 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FaceSubscribeMapper.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + SUBSCRIBE_ID AS subscribeId, DEVICE_CODE AS deviceCode, UPDATE_TIME AS updateTime + + + diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FacePersonSync.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FacePersonSync.java new file mode 100644 index 0000000..7cdb821 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FacePersonSync.java @@ -0,0 +1,68 @@ +package com.casic.missiles.modular.system.model; + +import java.io.Serializable; + +import com.baomidou.mybatisplus.annotations.TableId; +import com.baomidou.mybatisplus.annotations.TableField; +import com.baomidou.mybatisplus.activerecord.Model; +import com.baomidou.mybatisplus.annotations.TableName; +import java.io.Serializable; + +/** + *

+ * + *

+ * + * @author zyj123 + * @since 2020-07-24 + */ +@TableName("face_person_sync") +public class FacePersonSync extends Model { + + private static final long serialVersionUID = 1L; + + /** + * 人员id + */ + @TableId("PERSON_ID") + private Long personId; + /** + * 人员同步id + */ + @TableField("SYNC_ID") + private Long syncId; + + public FacePersonSync(Long personId, Long syncId) { + this.personId = personId; + this.syncId = syncId; + } + + public Long getPersonId() { + return personId; + } + + public void setPersonId(Long personId) { + this.personId = personId; + } + + public Long getSyncId() { + return syncId; + } + + public void setSyncId(Long syncId) { + this.syncId = syncId; + } + + @Override + protected Serializable pkVal() { + return this.personId; + } + + @Override + public String toString() { + return "FacePersonSync{" + + "personId=" + personId + + ", syncId=" + syncId + + "}"; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FaceSubscribe.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FaceSubscribe.java new file mode 100644 index 0000000..ccc7792 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FaceSubscribe.java @@ -0,0 +1,79 @@ +package com.casic.missiles.modular.system.model; + +import java.io.Serializable; + +import java.util.Date; +import com.baomidou.mybatisplus.annotations.TableId; +import com.baomidou.mybatisplus.annotations.TableField; +import com.baomidou.mybatisplus.activerecord.Model; +import com.baomidou.mybatisplus.annotations.TableName; +import java.io.Serializable; + +/** + *

+ * + *

+ * + * @author zyj123 + * @since 2020-07-25 + */ +@TableName("face_subscribe") +public class FaceSubscribe extends Model { + + private static final long serialVersionUID = 1L; + + /** + * 订阅id + */ + @TableId("SUBSCRIBE_ID") + private Long subscribeId; + /** + * 设备编号 + */ + @TableField("DEVICE_CODE") + private String deviceCode; + /** + * 更新时间 + */ + @TableField("UPDATE_TIME") + private Date updateTime; + + + public Long getSubscribeId() { + return subscribeId; + } + + public void setSubscribeId(Long subscribeId) { + this.subscribeId = subscribeId; + } + + public String getDeviceCode() { + return deviceCode; + } + + public void setDeviceCode(String deviceCode) { + this.deviceCode = deviceCode; + } + + public Date getUpdateTime() { + return updateTime; + } + + public void setUpdateTime(Date updateTime) { + this.updateTime = updateTime; + } + + @Override + protected Serializable pkVal() { + return this.subscribeId; + } + + @Override + public String toString() { + return "FaceSubscribe{" + + "subscribeId=" + subscribeId + + ", deviceCode=" + deviceCode + + ", updateTime=" + updateTime + + "}"; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/request/PersonInfo.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/request/PersonInfo.java new file mode 100644 index 0000000..80d9eff --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/request/PersonInfo.java @@ -0,0 +1,271 @@ +package com.casic.missiles.modular.system.request; + +import com.alibaba.fastjson.annotation.JSONField; +import com.baomidou.mybatisplus.annotations.TableField; +import com.google.gson.annotations.SerializedName; + +import java.util.List; + +public class PersonInfo { + + //@JSONField(name = "PersonID") + @SerializedName("PersonID") + private Long personID; + + //@JSONField(name = "LastChange") + @SerializedName("LastChange") + private Long lastChange; + + //@JSONField(name = "PersonCode") + @SerializedName("PersonCode") + private String personCode; + + //@JSONField(name = "PersonName") + @SerializedName("PersonName") + private String personName; + + //@JSONField(name = "Remarks") + @SerializedName("Remarks") + private String remarks; + + //@JSONField(name = "TimeTemplateNum") + @SerializedName("TimeTemplateNum") + private Integer timeTemplateNum; + + //@JSONField(name = "TimeTemplateList") + @SerializedName("TimeTemplateList") + private List timeTemplateList; + + //@JSONField(name = "IdentificationNum") + @SerializedName("IdentificationNum") + private Integer identificationNum; + + //@JSONField(name = "IdentificationList") + @SerializedName("IdentificationList") + private List identificationList; + + //@JSONField(name = "ImageNum") + @SerializedName("ImageNum") + private Integer imageNum; + + //@JSONField(name = "ImageList") + @SerializedName("ImageList") + private List imageList; + + public Long getPersonID() { + return personID; + } + + public void setPersonID(Long personID) { + this.personID = personID; + } + + public Long getLastChange() { + return lastChange; + } + + public void setLastChange(Long lastChange) { + this.lastChange = lastChange; + } + + public String getPersonCode() { + return personCode; + } + + public void setPersonCode(String personCode) { + this.personCode = personCode; + } + + public String getPersonName() { + return personName; + } + + public void setPersonName(String personName) { + this.personName = personName; + } + + public String getRemarks() { + return remarks; + } + + public void setRemarks(String remarks) { + this.remarks = remarks; + } + + public Integer getTimeTemplateNum() { + return timeTemplateNum; + } + + public void setTimeTemplateNum(Integer timeTemplateNum) { + this.timeTemplateNum = timeTemplateNum; + } + + public List getTimeTemplateList() { + return timeTemplateList; + } + + public void setTimeTemplateList(List timeTemplateList) { + this.timeTemplateList = timeTemplateList; + } + + public Integer getIdentificationNum() { + return identificationNum; + } + + public void setIdentificationNum(Integer identificationNum) { + this.identificationNum = identificationNum; + } + + public List getIdentificationList() { + return identificationList; + } + + public void setIdentificationList(List identificationList) { + this.identificationList = identificationList; + } + + public Integer getImageNum() { + return imageNum; + } + + public void setImageNum(Integer imageNum) { + this.imageNum = imageNum; + } + + public List getImageList() { + return imageList; + } + + public void setImageList(List imageList) { + this.imageList = imageList; + } + + public class TimeTemplate{ + @JSONField(name = "BeginTime") + private Long beginTime; + @JSONField(name = "EndTime") + private Long endTime; + @JSONField(name = "Index") + private Long index; + + public TimeTemplate(Long beginTime, Long endTime, Long index) { + this.beginTime = beginTime; + this.endTime = endTime; + this.index = index; + } + + public Long getBeginTime() { + return beginTime; + } + + public void setBeginTime(Long beginTime) { + this.beginTime = beginTime; + } + + public Long getEndTime() { + return endTime; + } + + public void setEndTime(Long endTime) { + this.endTime = endTime; + } + + public Long getIndex() { + return index; + } + + public void setIndex(Long index) { + this.index = index; + } + } + + public TimeTemplate createTimeTemplate(Long beginTime, Long endTime, Long index){ + return new TimeTemplate(beginTime, endTime, index); + } + + public class IdentificationInfo { + @JSONField(name = "Type") + private Integer type; + @JSONField(name = "Number") + private String number; + + public IdentificationInfo(Integer type, String number) { + this.type = type; + this.number = number; + } + + public Integer getType() { + return type; + } + + public void setType(Integer type) { + this.type = type; + } + + public String getNumber() { + return number; + } + + public void setNumber(String number) { + this.number = number; + } + } + + public IdentificationInfo createIdentificationInfo(Integer type, String number){ + return new IdentificationInfo(type,number); + } + + public class ImageInfo{ + @JSONField(name = "FaceID") + private Long faceID; + @JSONField(name = "Name") + private String name; + @JSONField(name = "Size") + private Long size; + @JSONField(name = "Data") + private String data; + + public ImageInfo(Long faceID, String name, Long size, String data) { + this.faceID = faceID; + this.name = name; + this.size = size; + this.data = data; + } + + public Long getFaceID() { + return faceID; + } + + public void setFaceID(Long faceID) { + this.faceID = faceID; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Long getSize() { + return size; + } + + public void setSize(Long size) { + this.size = size; + } + + public String getData() { + return data; + } + + public void setData(String data) { + this.data = data; + } + } + + public ImageInfo createImageInfo(Long faceID, String name, Long size, String data){ + return new ImageInfo(faceID, name, size, data); + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceBaseResponse.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceBaseResponse.java new file mode 100644 index 0000000..fe93b8a --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceBaseResponse.java @@ -0,0 +1,90 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; +import com.google.gson.annotations.SerializedName; + +public class FaceBaseResponse { + @JSONField(name = "ResponseURL") + @SerializedName("ResponseURL") + private String responseUrl; + + @JSONField(name = "CreatedID") + @SerializedName("CreatedID") + private int createdId; + + @JSONField(name = "ResponseCode") + @SerializedName("ResponseCode") + private int responseCode; + + @JSONField(name = "ResponseString") + @SerializedName("ResponseString") + private String responseString; + + @JSONField(name = "StatusCode") + @SerializedName("StatusCode") + private int statusCode; + + @JSONField(name = "StatusString") + @SerializedName("StatusString") + private String statusString; + + //@JSONField(name = "Data") + @SerializedName("Data") + private T data; + + public String getResponseUrl() { + return responseUrl; + } + + public void setResponseUrl(String responseUrl) { + this.responseUrl = responseUrl; + } + + public int getCreatedId() { + return createdId; + } + + public void setCreatedId(int createdId) { + this.createdId = createdId; + } + + public int getResponseCode() { + return responseCode; + } + + public void setResponseCode(int responseCode) { + this.responseCode = responseCode; + } + + public String getResponseString() { + return responseString; + } + + public void setResponseString(String responseString) { + this.responseString = responseString; + } + + public int getStatusCode() { + return statusCode; + } + + public void setStatusCode(int statusCode) { + this.statusCode = statusCode; + } + + public String getStatusString() { + return statusString; + } + + public void setStatusString(String statusString) { + this.statusString = statusString; + } + + public T getData() { + return data; + } + + public void setData(T data) { + this.data = data; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceInfo.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceInfo.java new file mode 100644 index 0000000..f128c92 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceInfo.java @@ -0,0 +1,128 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; + +import java.util.List; + +public class FaceInfo { + @JSONField(name = "ID") + private Long id; + @JSONField(name = "Timestamp") + private Long timestamp; + @JSONField(name = "CapSrc") + private Long capSrc; + @JSONField(name = "FeatureNum") + private Long featureNum; + @JSONField(name = "FeatureList") + private List featureList; + @JSONField(name = "FeatureVersion") + private String featureVersion; + @JSONField(name = "Feature") + private String feature; + @JSONField(name = "Temperature") + private Float temperature; + @JSONField(name = "MaskFlag") + private Long maskFlag; + @JSONField(name = "PanoImage") + private Object panoImage; + @JSONField(name = "FaceImage") + private Object faceImage; + @JSONField(name = "FaceArea") + private Object faceArea; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Long getTimestamp() { + return timestamp; + } + + public void setTimestamp(Long timestamp) { + this.timestamp = timestamp; + } + + public Long getCapSrc() { + return capSrc; + } + + public void setCapSrc(Long capSrc) { + this.capSrc = capSrc; + } + + public Long getFeatureNum() { + return featureNum; + } + + public void setFeatureNum(Long featureNum) { + this.featureNum = featureNum; + } + + public List getFeatureList() { + return featureList; + } + + public void setFeatureList(List featureList) { + this.featureList = featureList; + } + + public String getFeatureVersion() { + return featureVersion; + } + + public void setFeatureVersion(String featureVersion) { + this.featureVersion = featureVersion; + } + + public String getFeature() { + return feature; + } + + public void setFeature(String feature) { + this.feature = feature; + } + + public Float getTemperature() { + return temperature; + } + + public void setTemperature(Float temperature) { + this.temperature = temperature; + } + + public Long getMaskFlag() { + return maskFlag; + } + + public void setMaskFlag(Long maskFlag) { + this.maskFlag = maskFlag; + } + + public Object getPanoImage() { + return panoImage; + } + + public void setPanoImage(Object panoImage) { + this.panoImage = panoImage; + } + + public Object getFaceImage() { + return faceImage; + } + + public void setFaceImage(Object faceImage) { + this.faceImage = faceImage; + } + + public Object getFaceArea() { + return faceArea; + } + + public void setFaceArea(Object faceArea) { + this.faceArea = faceArea; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/LibMatInfo.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/LibMatInfo.java new file mode 100644 index 0000000..ce6dd33 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/LibMatInfo.java @@ -0,0 +1,69 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; + +public class LibMatInfo { + @JSONField(name = "ID") + private Long id; + @JSONField(name = "LibID") + private Long libId; + @JSONField(name = "LibType") + private Long libType; + @JSONField(name = "MatchStatus") + private Long matchStatus; + @JSONField(name = "MatchPersonID") + private Long matchPersonId; + @JSONField(name = "MatchFaceID") + private Long matchFaceId; + + // MatchPersonInfo 暂时忽略不用 + + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Long getLibId() { + return libId; + } + + public void setLibId(Long libId) { + this.libId = libId; + } + + public Long getLibType() { + return libType; + } + + public void setLibType(Long libType) { + this.libType = libType; + } + + public Long getMatchStatus() { + return matchStatus; + } + + public void setMatchStatus(Long matchStatus) { + this.matchStatus = matchStatus; + } + + public Long getMatchPersonId() { + return matchPersonId; + } + + public void setMatchPersonId(Long matchPersonId) { + this.matchPersonId = matchPersonId; + } + + public Long getMatchFaceId() { + return matchFaceId; + } + + public void setMatchFaceId(Long matchFaceId) { + this.matchFaceId = matchFaceId; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/PersonResponseData.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/PersonResponseData.java new file mode 100644 index 0000000..186faed --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/PersonResponseData.java @@ -0,0 +1,31 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; +import com.google.gson.annotations.SerializedName; + +import java.util.List; + +public class PersonResponseData { + @JSONField(name = "Num") + @SerializedName("Num") + private int num; + @JSONField(name = "PersonList") + @SerializedName("PersonList") + private List personList; + + public int getNum() { + return num; + } + + public void setNum(int num) { + this.num = num; + } + + public List getPersonList() { + return personList; + } + + public void setPersonList(List personList) { + this.personList = personList; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/PersonResponseInfo.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/PersonResponseInfo.java new file mode 100644 index 0000000..7ba3edc --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/PersonResponseInfo.java @@ -0,0 +1,67 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; +import com.google.gson.annotations.SerializedName; + +import java.util.List; + +public class PersonResponseInfo { + @JSONField(name = "PersonID") + @SerializedName("PersonID") + private Long personId; + @JSONField(name = "FaceNum") + @SerializedName("FaceNum") + private Long faceNum; + @JSONField(name = "FaceList") + @SerializedName("FaceList") + private List faceList; + + public Long getPersonId() { + return personId; + } + + public void setPersonId(Long personId) { + this.personId = personId; + } + + public Long getFaceNum() { + return faceNum; + } + + public void setFaceNum(Long faceNum) { + this.faceNum = faceNum; + } + + public List getFaceList() { + return faceList; + } + + public void setFaceList(List faceList) { + this.faceList = faceList; + } + + public class PersonResponseFace{ + @JSONField(name = "FaceID") + @SerializedName("FaceID") + private Long faceId; + @JSONField(name = "ResultCode") + @SerializedName("ResultCode") + private Long resultCode; + + public Long getFaceId() { + return faceId; + } + + public void setFaceId(Long faceId) { + this.faceId = faceId; + } + + public Long getResultCode() { + return resultCode; + } + + public void setResultCode(Long resultCode) { + this.resultCode = resultCode; + } + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/RecordNotification.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/RecordNotification.java new file mode 100644 index 0000000..ca52d29 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/RecordNotification.java @@ -0,0 +1,138 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; + +import java.util.List; + +public class RecordNotification { + @JSONField(name = "Reference") + private String reference; + @JSONField(name = "Seq") + private int seq; + @JSONField(name = "DeviceCode") + private String deviceCode; + @JSONField(name = "Timestamp") + private Long timestamp; + @JSONField(name = "NotificationType") + private int notificationType; + @JSONField(name = "FaceInfoNum") + private int faceInfoNum; + @JSONField(name = "FaceInfoList") + private List faceInfoList; + @JSONField(name = "CardInfoNum") + private int cardInfoNum; + @JSONField(name = "CardInfoList") + private List cardInfoList; + @JSONField(name = "GateInfoNum") + private int gateInfoNum; + @JSONField(name = "GateInfoList") + private List gateInfoList; + @JSONField(name = "LibMatInfoNum") + private int libMatInfoNum; + @JSONField(name = "LibMatInfoList") + private List libMatInfoList; + + public String getReference() { + return reference; + } + + public void setReference(String reference) { + this.reference = reference; + } + + public int getSeq() { + return seq; + } + + public void setSeq(int seq) { + this.seq = seq; + } + + public String getDeviceCode() { + return deviceCode; + } + + public void setDeviceCode(String deviceCode) { + this.deviceCode = deviceCode; + } + + public Long getTimestamp() { + return timestamp; + } + + public void setTimestamp(Long timestamp) { + this.timestamp = timestamp; + } + + public int getNotificationType() { + return notificationType; + } + + public void setNotificationType(int notificationType) { + this.notificationType = notificationType; + } + + public int getFaceInfoNum() { + return faceInfoNum; + } + + public void setFaceInfoNum(int faceInfoNum) { + this.faceInfoNum = faceInfoNum; + } + + public List getFaceInfoList() { + return faceInfoList; + } + + public void setFaceInfoList(List faceInfoList) { + this.faceInfoList = faceInfoList; + } + + public int getCardInfoNum() { + return cardInfoNum; + } + + public void setCardInfoNum(int cardInfoNum) { + this.cardInfoNum = cardInfoNum; + } + + public List getCardInfoList() { + return cardInfoList; + } + + public void setCardInfoList(List cardInfoList) { + this.cardInfoList = cardInfoList; + } + + public int getGateInfoNum() { + return gateInfoNum; + } + + public void setGateInfoNum(int gateInfoNum) { + this.gateInfoNum = gateInfoNum; + } + + public List getGateInfoList() { + return gateInfoList; + } + + public void setGateInfoList(List gateInfoList) { + this.gateInfoList = gateInfoList; + } + + public int getLibMatInfoNum() { + return libMatInfoNum; + } + + public void setLibMatInfoNum(int libMatInfoNum) { + this.libMatInfoNum = libMatInfoNum; + } + + public List getLibMatInfoList() { + return libMatInfoList; + } + + public void setLibMatInfoList(List libMatInfoList) { + this.libMatInfoList = libMatInfoList; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/runner/InitSubscribeRunner.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/runner/InitSubscribeRunner.java new file mode 100644 index 0000000..c7d0565 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/runner/InitSubscribeRunner.java @@ -0,0 +1,43 @@ +package com.casic.missiles.modular.system.runner; + +import com.casic.missiles.modular.system.model.Device; +import com.casic.missiles.modular.system.service.IDeviceSupportService; +import com.casic.missiles.modular.system.service.IFaceSyncService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.ApplicationArguments; +import org.springframework.boot.ApplicationRunner; +import org.springframework.stereotype.Component; + +import java.util.ArrayList; +import java.util.List; + +@Component +public class InitSubscribeRunner implements ApplicationRunner { + private static Logger logger = LoggerFactory.getLogger(InitSubscribeRunner.class); + + @Value("${iris.face.initSubscribe}") + private String initSubscribe; + @Autowired + private IDeviceSupportService deviceSupportService; + @Autowired + private IFaceSyncService faceSyncService; + + /** + * 启动项目时,根据需要初始化设备订阅信息 + * @param applicationArguments + * @throws Exception + */ + @Override + public void run(ApplicationArguments applicationArguments) throws Exception { + logger.info("==================initSubscribe: "); + if(Boolean.valueOf(initSubscribe)){ + List deviceList = deviceSupportService.selectDeviceByType("5"); + List deviceIds = new ArrayList<>(); + deviceList.forEach(device -> deviceIds.add(Long.valueOf(device.getId()))); + faceSyncService.initSubscription(deviceIds); + } + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFacePersonSyncService.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFacePersonSyncService.java new file mode 100644 index 0000000..6b2461b --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFacePersonSyncService.java @@ -0,0 +1,18 @@ +package com.casic.missiles.modular.system.service; + +import com.casic.missiles.modular.system.model.FacePersonSync; +import com.baomidou.mybatisplus.service.IService; + +/** + *

+ * 服务类 + *

+ * + * @author zyj123 + * @since 2020-07-24 + */ +public interface IFacePersonSyncService extends IService { + Long selectSyncId(Long personId); + Long selectPersonId(Long syncId); + Long getMaxSyncId(Long personId); +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFaceSubscribeService.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFaceSubscribeService.java new file mode 100644 index 0000000..e0461ed --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFaceSubscribeService.java @@ -0,0 +1,24 @@ +package com.casic.missiles.modular.system.service; + +import com.casic.missiles.modular.system.model.FaceSubscribe; +import com.baomidou.mybatisplus.service.IService; + +import java.util.List; + +/** + *

+ * 服务类 + *

+ * + * @author zyj123 + * @since 2020-07-25 + */ +public interface IFaceSubscribeService extends IService { + + List selectSubscribeIdsByDevCode(String devCode); + + boolean deleteByDevCode(String devCode); + + boolean insertSubscribe(Long subscribeId, String devCode); + +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFaceSyncService.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFaceSyncService.java new file mode 100644 index 0000000..effd921 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFaceSyncService.java @@ -0,0 +1,21 @@ +package com.casic.missiles.modular.system.service; + +import com.casic.missiles.modular.system.response.RecordNotification; + +import java.util.List; + +public interface IFaceSyncService { + String uploadPerson(List personIds, List deviceIds,String personType); + + String checkPersonPhoto(List personIds); + + void receiveRecord(RecordNotification recordNotification); + + void receiveRecord(String recordNotificationStr); + + String initSubscription(List deviceIds); + + boolean deleteSubscription(String deviceIp, Long subscribeId); + + Long createSubscription(String deviceIp,String ip,String port); +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/Impl/FacePersonSyncServiceImpl.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/Impl/FacePersonSyncServiceImpl.java new file mode 100644 index 0000000..d1d1694 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/Impl/FacePersonSyncServiceImpl.java @@ -0,0 +1,55 @@ +package com.casic.missiles.modular.system.service.Impl; + +import com.baomidou.mybatisplus.mapper.EntityWrapper; +import com.casic.missiles.core.util.ToolUtil; +import com.casic.missiles.modular.system.model.FacePersonSync; +import com.casic.missiles.modular.system.dao.FacePersonSyncMapper; +import com.casic.missiles.modular.system.service.IFacePersonSyncService; +import com.baomidou.mybatisplus.service.impl.ServiceImpl; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +/** + *

+ * 服务实现类 + *

+ * + * @author zyj123 + * @since 2020-07-24 + */ +@Service +public class FacePersonSyncServiceImpl extends ServiceImpl implements IFacePersonSyncService { + + @Override + public Long selectSyncId(Long personId) { + FacePersonSync facePersonSync = this.selectById(personId); + if(ToolUtil.isNotEmpty(facePersonSync)){ + return facePersonSync.getSyncId(); + } + return null; + } + + @Override + public Long selectPersonId(Long syncId) { + EntityWrapper query = new EntityWrapper(); + query.eq("SYNC_ID",syncId); + FacePersonSync facePersonSync = this.selectOne(query); + if(ToolUtil.isNotEmpty(facePersonSync)){ + return facePersonSync.getPersonId(); + } + return null; + } + + @Override + @Transactional + public Long getMaxSyncId(Long personId) { + Long maxId = this.baseMapper.getMaxSyncId(); + if(ToolUtil.isEmpty(maxId)){ + maxId = 1000L; + }else { + maxId = maxId + 1; + } + this.insert(new FacePersonSync(personId,maxId)); + return maxId; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/Impl/FaceSubscribeServiceImpl.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/Impl/FaceSubscribeServiceImpl.java new file mode 100644 index 0000000..c04302d --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/Impl/FaceSubscribeServiceImpl.java @@ -0,0 +1,52 @@ +package com.casic.missiles.modular.system.service.Impl; + +import com.baomidou.mybatisplus.mapper.EntityWrapper; +import com.casic.missiles.modular.system.model.FaceSubscribe; +import com.casic.missiles.modular.system.dao.FaceSubscribeMapper; +import com.casic.missiles.modular.system.service.IFaceSubscribeService; +import com.baomidou.mybatisplus.service.impl.ServiceImpl; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +/** + *

+ * 服务实现类 + *

+ * + * @author zyj123 + * @since 2020-07-25 + */ +@Service +public class FaceSubscribeServiceImpl extends ServiceImpl implements IFaceSubscribeService { + + @Override + public List selectSubscribeIdsByDevCode(String devCode) { + EntityWrapper query = new EntityWrapper(); + query.eq("DEVICE_CODE",devCode); + List faceSubscribes = this.selectList(query); + List subscribeIds = new ArrayList<>(); + for (FaceSubscribe faceSubscribe : faceSubscribes) { + subscribeIds.add(faceSubscribe.getSubscribeId()); + } + return subscribeIds; + } + + @Override + public boolean deleteByDevCode(String devCode) { + EntityWrapper query = new EntityWrapper(); + query.eq("DEVICE_CODE",devCode); + return this.delete(query); + } + + @Override + public boolean insertSubscribe(Long subscribeId, String devCode) { + FaceSubscribe faceSubscribe = new FaceSubscribe(); + faceSubscribe.setDeviceCode(devCode); + faceSubscribe.setSubscribeId(subscribeId); + faceSubscribe.setUpdateTime(new Date()); + return this.insert(faceSubscribe); + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/Impl/FaceSyncServiceImpl.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/Impl/FaceSyncServiceImpl.java new file mode 100644 index 0000000..8826be5 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/Impl/FaceSyncServiceImpl.java @@ -0,0 +1,465 @@ +package com.casic.missiles.modular.system.service.Impl; + +import com.alibaba.fastjson.JSONObject; +import com.casic.missiles.core.common.service.ICommonPersonService; +import com.casic.missiles.core.util.ToolUtil; +import com.casic.missiles.modular.system.model.Device; +import com.casic.missiles.modular.system.model.FacePersonSync; +import com.casic.missiles.modular.system.model.Person; +import com.casic.missiles.modular.system.model.RecognitionRecords; +import com.casic.missiles.modular.system.request.PersonInfo; +import com.casic.missiles.modular.system.response.*; +import com.casic.missiles.modular.system.service.*; +import com.casic.missiles.modular.system.util.HttpClientUtil; +import com.google.gson.*; +import org.apache.commons.lang3.StringUtils; +import org.omg.CORBA.Object; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import com.casic.missiles.modular.system.constant.FaceSyncConst; +import java.net.InetAddress; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +@Service +public class FaceSyncServiceImpl implements IFaceSyncService { + private static final Logger logger = LoggerFactory.getLogger(FaceSyncServiceImpl.class); + + @Autowired + private IFacePersonSyncService personSyncService; + @Autowired + private ICommonPersonService commonPersonService; + @Autowired + private IPersonPhotoSupportService photoSupportService; + @Autowired + private IDeviceSupportService deviceSupportService; + @Autowired + private IRecordSupportService recordSupportService; + @Autowired + private IFaceSubscribeService subscribeService; + @Value("${server.port}") + private String serverPort; + @Value("${iris.face.serverHost}") + private String serverHost; + + @Override + @Transactional + public String uploadPerson(List personIds,List deviceIds,String personType) { + String error = null; + + try{ + List personInfoList = new ArrayList<>(personIds.size()); + for (Long personId : personIds) { + Person person = commonPersonService.getPersonById(personId); + Long syncId = getPersonSyncId(personId); + String photoData = photoSupportService.selectPhotoDataById(personId); + PersonInfo personInfo = convPersonInfo(person,syncId,photoData); + personInfoList.add(personInfo); + } + + + outterLoop : for (Long deviceId : deviceIds) { + Device device = deviceSupportService.selectById(deviceId); + // 批量下发(单次最多6个,分多次下发) + int batchSize = FaceSyncConst.UPLOAD_MAX_PERSON; + int batchNum = (int)Math.ceil((double)personInfoList.size()/batchSize); + for (int i = 0; i < batchNum; i++) { + int fromIndex = i * batchSize; + int toIndex = (i+1) * batchSize <= personInfoList.size() ? (i+1) * batchSize : personInfoList.size(); + List subPersonInfoList = personInfoList.subList(fromIndex,toIndex); + + // 设置上传body对象 + Gson gson = new GsonBuilder().serializeNulls().create(); + JsonObject body = new JsonObject(); + JsonElement person = gson.toJsonTree(subPersonInfoList); + body.addProperty("Num",subPersonInfoList.size()); + body.add("PersonInfoList",person); + String bodyStr = gson.toJson(body); +// logger.info(String.valueOf(subPersonInfoList.size())); + logger.info(bodyStr); + +// 调用接口上传 + String devIp = device.getDevIp(); + String personLib = null; + if("1".equals(personType)){ + personLib = FaceSyncConst.UPLOAD_STAFF_LIB; + }else { + personLib = FaceSyncConst.UPLOAD_VISITOR_LIB; + } + + String url = "http://".concat(devIp).concat(FaceSyncConst.UPLOAD_URL_PREFIX).concat(personLib).concat(FaceSyncConst.UPLOAD_URL_SUFFIX); + String responseContent = HttpClientUtil.sendHttpPost(url,bodyStr); + logger.info(responseContent); + JsonObject obj = gson.fromJson(responseContent, JsonObject.class); + // 解析返回结果 + FaceBaseResponse> response = gson.fromJson(obj.get("Response"),FaceBaseResponse.class); + if(response.getResponseCode() == 0 && response.getStatusCode() == 0){ + PersonResponseData personResponseData = gson.fromJson(gson.toJson(response.getData()),PersonResponseData.class); + List responseInfos = personResponseData.getPersonList(); + for(int j = 0;j < responseInfos.size();j++){ + PersonResponseInfo personResponseInfo = gson.fromJson(gson.toJson(responseInfos.get(j)),PersonResponseInfo.class);; + if(personResponseInfo.getFaceList().get(0).getResultCode() == 0){ + // 成功 + logger.info(String.format("人脸数据下发成功,人员:%s,设备: %s",personResponseInfo.getPersonId(),device.getDevCode())); + }else{ + error = convErrorCode(personResponseInfo.getFaceList().get(0).getResultCode()); + String personName = commonPersonService.getPersonById(personIds.get(i)).getName(); + error = String.format("下发失败,%s %s",personName,error); + logger.error(error); + break outterLoop; + } + } + }else { + if(response.getResponseCode() != 0 ){ + error = String.format("设备%s下发失败: %s",device.getDevCode(),response.getResponseString()); + logger.error(error); + break; + } + if(response.getStatusCode() != 0){ + error = String.format("设备%s下发失败: %s",device.getDevCode(),response.getStatusString()); + logger.error(error); + break; + } + } + } + } + }catch (Exception e){ + e.printStackTrace(); + logger.error(e.getMessage()); + error = "下发失败"; + } + + return error; + } + + private void updatePersonInfoList(List personInfoList,List personIds){ + for (int i = 0; i < personIds.size(); i++) { + Long syncId = personSyncService.selectSyncId(personIds.get(i)); + if(ToolUtil.isNotEmpty(syncId)){ + PersonInfo personInfo = personInfoList.get(i); + personInfo.setPersonID(syncId); + if(ToolUtil.isNotEmpty(personInfo.getImageList())){ + personInfo.getImageList().get(i).setFaceID(syncId); + } + } + } + } + + private Long getPersonSyncId(Long personId){ + Long syncId = personSyncService.selectSyncId(personId); + if(ToolUtil.isEmpty(syncId)){ + syncId = personSyncService.getMaxSyncId(personId); + } + return syncId; + } + + private PersonInfo convPersonInfo(Person person,Long syncId,String photoData){ + PersonInfo personInfo = new PersonInfo(); + if(ToolUtil.isNotEmpty(syncId)){ + personInfo.setPersonID(syncId); + } + if(ToolUtil.isNotEmpty(person.getUpdatetime())){ + personInfo.setLastChange(person.getUpdatetime().getTime()); + } + if(ToolUtil.isNotEmpty(person.getPersonCode()) && person.getPersonCode().length() <= FaceSyncConst.UPLOAD_PERSONCODE_MAXLENGTH){ + personInfo.setPersonCode(person.getPersonCode()); + }else { + personInfo.setPersonCode(String.valueOf(syncId)); + } + if(ToolUtil.isNotEmpty(person.getName())){ + personInfo.setPersonName(person.getName()); + } + if(ToolUtil.isNotEmpty(person.getRemarks()) && person.getRemarks().length() <= FaceSyncConst.UPLOAD_REMARK_MAXLENGTH){ + personInfo.setRemarks(person.getRemarks()); + }else { + personInfo.setRemarks(""); + } + + // 时间模板 + personInfo.setTimeTemplateNum(0); + List timeTemplateList = new ArrayList<>(); + timeTemplateList.add(personInfo.createTimeTemplate(0L,4294967295L,0L)); + personInfo.setTimeTemplateList(timeTemplateList); + + // 证件列表 + if(ToolUtil.isNotEmpty(person.getIdCardNo())){ + personInfo.setIdentificationNum(1); + List identificationInfoList = new ArrayList<>(); + identificationInfoList.add(personInfo.createIdentificationInfo(1,person.getIdCardNo())); + personInfo.setIdentificationList(identificationInfoList); + }else{ + personInfo.setIdentificationNum(0); + } + + // 图片列表 + if(ToolUtil.isNotEmpty(photoData)){ + personInfo.setImageNum(1); + List imageInfoList = new ArrayList<>(); + // 图片base64码 + if(photoData.startsWith("data") || photoData.startsWith("base64")){ + int splitIndex = photoData.indexOf(","); + photoData = photoData.substring(splitIndex+1); + } + imageInfoList.add(personInfo.createImageInfo(syncId,person.getPhoto(),Long.valueOf(photoData.length()),photoData)); + personInfo.setImageList(imageInfoList); + }else { + personInfo.setImageNum(0); + } + return personInfo; + } + + private String convErrorCode(Long errorCode){ + String errorMsg = ""; + switch (errorCode.intValue()){ + case 1000: + errorMsg = "算法初始化失败"; + break; + case 1001: + errorMsg = "人脸检测失败"; + break; + case 1002: + errorMsg = "图片未检测到人脸"; + break; + case 1003: + errorMsg = "jpeg照片解码失败"; + break; + case 1004: + errorMsg = "图片质量分数不满足"; + break; + case 1005: + errorMsg = "图片缩放失败"; + break; + case 1006: + errorMsg = "未启用智能"; + break; + case 1007: + errorMsg = "导入图片过小"; + break; + case 1008: + errorMsg = "导入图片过大"; + break; + case 1009: + errorMsg = "导入图片分辨率超过1920*1080"; + break; + case 1010: + errorMsg = "导入图片不存在"; + break; + case 1011: + errorMsg = "人脸元素个数已达到上限"; + break; + case 1012: + errorMsg = "智能棒算法模型不匹配"; + break; + case 1013: + errorMsg = "人脸导入库成员证件号非法"; + break; + case 1014: + errorMsg = "人脸导入库成员图片格式错误"; + break; + case 1015: + errorMsg = "通道布控已达设备能力上限"; + break; + case 1016: + errorMsg = "其它客户端正在进行操作人脸库"; + break; + case 1017: + errorMsg = "人脸库文件正在更新中"; + break; + case 1018: + errorMsg = "Json反序列化失败"; + break; + case 1019: + errorMsg = "Base64解码失败"; + break; + case 1020: + errorMsg = "人脸照片,编码后的大小和实际接收到的长度不一致,关注Data和Size大小是否正确"; + break; + default: + break; + } + return errorMsg; + + } + + @Override + public String checkPersonPhoto(List personIds) { + String error = null; + for (Long personId : personIds) { + Person person = commonPersonService.getPersonById(personId); + String photoData = photoSupportService.selectPhotoDataById(personId); + if(ToolUtil.isEmpty(photoData)){ + error = String.format("%s 未上传照片",person.getName()); + break; + } + if(photoData.startsWith("data") || photoData.startsWith("base64")){ + int splitIndex = photoData.indexOf(","); + photoData = photoData.substring(splitIndex+1); + } + if(!photoData.startsWith("/9j")){ + error = String.format("%s人员照片不符合要求,必须为jpg格式",person.getName()); + break; + } + + // 找到等号,把等号也去掉 + int equalIndex = photoData.indexOf('='); + if(equalIndex>=0) { + photoData=photoData.substring(0, equalIndex); + } + // 原来的字符流大小,单位为字节 + int strLength=photoData.length(); + // 计算后得到的文件流大小,单位为字节 + int fileLength=Integer.valueOf(strLength-(strLength/8)*2); + if(fileLength / 1024 < 20){ + error = String.format("%s人员照片不符合要求,照片必须大于20Kb",person.getName()); + break; + } + } + return error; + } + + @Override + public void receiveRecord(RecordNotification recordNotification){ +// if(recordNotification.getFaceInfoNum() != recordNotification.getLibMatInfoNum()){ +// logger.error("采集和匹配数据不一致,识别失败"); +// } else { + String deviceCode = recordNotification.getDeviceCode(); + List recordsList = new ArrayList<>(); + for (int i = 0; i < recordNotification.getLibMatInfoNum(); i++) { + //FaceInfo faceInfo = recordNotification.getFaceInfoList().get(i); + LibMatInfo libMatInfo = recordNotification.getLibMatInfoList().get(i); + if(libMatInfo.getMatchStatus() == 1){ + FaceInfo faceInfo = getFaceInfoByMatchId(recordNotification.getFaceInfoList(),libMatInfo.getId()); + Long personId = personSyncService.selectPersonId(libMatInfo.getMatchPersonId()); + if(ToolUtil.isNotEmpty(personId) && ToolUtil.isNotEmpty(faceInfo)){ + RecognitionRecords record = new RecognitionRecords(); + record.setPersonId(personId); + record.setDatetime(new Date(faceInfo.getTimestamp()*1000)); + record.setDevCode(deviceCode); + if(ToolUtil.isNotEmpty(faceInfo.getTemperature())){ + record.setTemperature(String.valueOf(faceInfo.getTemperature())); + } + record.setOriginalId(libMatInfo.getId()); + record.setSyncTime(new Date()); + + Device device = deviceSupportService.selectDeviceByCode(deviceCode); + if(ToolUtil.isNotEmpty(device)){ + if(ToolUtil.isNotEmpty(device.getDevIp())){ + record.setDevIp(device.getDevIp()); + } + } + + recordsList.add(record); + } + } + } + if(ToolUtil.isNotEmpty(recordsList)){ + recordSupportService.insertBatch(recordsList); + } + } + + @Override + public void receiveRecord(String recordNotificationStr) { + RecordNotification recordNotification = JSONObject.parseObject(recordNotificationStr,RecordNotification.class); + receiveRecord(recordNotification); + } + + public FaceInfo getFaceInfoByMatchId(List faceInfoList ,Long id){ + for (FaceInfo faceInfo : faceInfoList) { + if(faceInfo.getId().equals(id)){ + return faceInfo; + } + } + return null; + } + + @Override + public String initSubscription(List deviceIds) { + try { + List error = new ArrayList<>(); + for (Long deviceId : deviceIds) { + Device device = deviceSupportService.selectById(deviceId); + List subscribeIds = subscribeService.selectSubscribeIdsByDevCode(device.getDevCode());; + // 删除所有id + boolean flag = true; + for (Long subscribeId : subscribeIds) { + flag = flag && deleteSubscription(device.getDevIp(),subscribeId); + } + flag = flag && subscribeService.deleteByDevCode(device.getDevCode()); + // 创建订阅 + Long subscribeId = createSubscription(device.getDevIp(),serverHost,serverPort); + flag = flag && ToolUtil.isNotEmpty(subscribeId); + if(ToolUtil.isNotEmpty(subscribeId)){ + flag = flag && subscribeService.insertSubscribe(subscribeId,device.getDevCode()); + } + if(!flag){ + logger.error(String.format("device %s init subsrciption error",device.getDevCode())); + error.add(device.getDevCode()); + } + } + if(ToolUtil.isNotEmpty(error)){ + return StringUtils.join(error,",").concat("订阅失败"); + }else { + return null; + } + }catch (Exception e){ + e.printStackTrace(); + logger.error(e.getMessage()); + return "订阅失败"; + } + + } + + @Override + public boolean deleteSubscription(String deviceIp, Long subscribeId) { + String url = "http://" + deviceIp + FaceSyncConst.SUBSCRIBE_URL + subscribeId; + String responseContent = HttpClientUtil.sendHttpDelete(url); + logger.info(responseContent); + Gson gson = new Gson(); + JsonObject obj = gson.fromJson(responseContent, JsonObject.class); + logger.info(obj.get("Response").toString()); + FaceBaseResponse response = gson.fromJson(obj.get("Response"),FaceBaseResponse.class); + if(response.getResponseCode() == 0 && response.getStatusCode() == 0){ + return true; + }else { + logger.error(String.format("delele subscribe error, device '%s', subscribeId '%s', response '%s', status '%s'",deviceIp,subscribeId,response.getResponseString(),response.getStatusString())); + return false; + } + } + + @Override + public Long createSubscription(String deviceIp, String ip, String port) { + JsonObject request = new JsonObject(); + request.addProperty("AddressType",0); + request.addProperty("IPAddress",ip); + request.addProperty("Port",Long.valueOf(port)); + request.addProperty("Duration",4294967295L); + request.addProperty("Type",1024); + JsonObject subscribePersonCondition = new JsonObject(); + subscribePersonCondition.addProperty("LibIDNum",65535); + subscribePersonCondition.add("LibIDList",new JsonArray()); + request.add("SubscribePersonCondition",subscribePersonCondition); + Gson gson = new Gson(); + String requestStr = gson.toJson(request); + System.out.println(requestStr); + String url = "http://" + deviceIp + FaceSyncConst.SUBSCRIBE_URL ; + String responseContent = HttpClientUtil.sendHttpPostJson(url,requestStr); + logger.info(responseContent); + JsonObject obj = gson.fromJson(responseContent, JsonObject.class); + FaceBaseResponse response = gson.fromJson(obj.get("Response"),FaceBaseResponse.class); + if(response.getResponseCode() == 0 && response.getStatusCode()==0){ + JsonObject data = gson.fromJson(gson.toJson(response.getData()),JsonObject.class); + Long subsrcibeId = data.get("ID").getAsLong(); + logger.info(String.format("create subscribe success, device '%s', subsrcibeId '%s'",deviceIp,subsrcibeId)); + return subsrcibeId; + }else { + logger.error(String.format("create subscribe error, device '%s', response '%s', status '%s'",deviceIp,response.getResponseString(),response.getStatusString())); + return null; + } + } + +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/util/HttpClientUtil.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/util/HttpClientUtil.java new file mode 100644 index 0000000..e258174 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/util/HttpClientUtil.java @@ -0,0 +1,468 @@ +package com.casic.missiles.modular.system.util; + +import java.io.File; +import java.io.IOException; +import java.security.KeyManagementException; +import java.security.KeyStoreException; +import java.security.NoSuchAlgorithmException; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.apache.http.HttpEntity; +import org.apache.http.HttpStatus; +import org.apache.http.client.config.RequestConfig; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpDelete; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.config.Registry; +import org.apache.http.config.RegistryBuilder; +import org.apache.http.conn.socket.ConnectionSocketFactory; +import org.apache.http.conn.socket.PlainConnectionSocketFactory; +import org.apache.http.conn.ssl.SSLConnectionSocketFactory; +import org.apache.http.conn.ssl.SSLContextBuilder; +import org.apache.http.conn.ssl.TrustSelfSignedStrategy; +import org.apache.http.entity.ContentType; +import org.apache.http.entity.StringEntity; +import org.apache.http.entity.mime.MultipartEntityBuilder; +import org.apache.http.entity.mime.content.FileBody; +import org.apache.http.entity.mime.content.StringBody; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.DefaultHttpRequestRetryHandler; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; +import org.apache.http.util.EntityUtils; + +/** + * + * @author H__D + * @date 2016年10月19日 上午11:27:25 + * + */ +public class HttpClientUtil { + + // utf-8字符编码 + public static final String CHARSET_UTF_8 = "utf-8"; + + // HTTP内容类型。 + public static final String CONTENT_TYPE_TEXT_HTML = "text/xml"; + + // HTTP内容类型。相当于form表单的形式,提交数据 + public static final String CONTENT_TYPE_FORM_URL = "application/x-www-form-urlencoded"; + + // HTTP内容类型。相当于form表单的形式,提交数据 + public static final String CONTENT_TYPE_JSON_URL = "application/json;charset=utf-8"; + + + // 连接管理器 + private static PoolingHttpClientConnectionManager pool; + + // 请求配置 + private static RequestConfig requestConfig; + + static { + + try { + //System.out.println("初始化HttpClientTest~~~开始"); + SSLContextBuilder builder = new SSLContextBuilder(); + builder.loadTrustMaterial(null, new TrustSelfSignedStrategy()); + SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory( + builder.build()); + // 配置同时支持 HTTP 和 HTPPS + Registry socketFactoryRegistry = RegistryBuilder. create().register( + "http", PlainConnectionSocketFactory.getSocketFactory()).register( + "https", sslsf).build(); + // 初始化连接管理器 + pool = new PoolingHttpClientConnectionManager( + socketFactoryRegistry); + // 将最大连接数增加到200,实际项目最好从配置文件中读取这个值 + pool.setMaxTotal(200); + // 设置最大路由 + pool.setDefaultMaxPerRoute(2); + // 根据默认超时限制初始化requestConfig + int socketTimeout = 10000; + int connectTimeout = 10000; + int connectionRequestTimeout = 10000; + requestConfig = RequestConfig.custom().setConnectionRequestTimeout( + connectionRequestTimeout).setSocketTimeout(socketTimeout).setConnectTimeout( + connectTimeout).build(); + + //System.out.println("初始化HttpClientTest~~~结束"); + } catch (NoSuchAlgorithmException e) { + e.printStackTrace(); + } catch (KeyStoreException e) { + e.printStackTrace(); + } catch (KeyManagementException e) { + e.printStackTrace(); + } + + + // 设置请求超时时间 + requestConfig = RequestConfig.custom().setSocketTimeout(50000).setConnectTimeout(50000) + .setConnectionRequestTimeout(50000).build(); + } + + public static CloseableHttpClient getHttpClient() { + + CloseableHttpClient httpClient = HttpClients.custom() + // 设置连接池管理 + .setConnectionManager(pool) + // 设置请求配置 + .setDefaultRequestConfig(requestConfig) + // 设置重试次数 + .setRetryHandler(new DefaultHttpRequestRetryHandler(0, false)) + .build(); + + return httpClient; + } + + /** + * 发送Post请求 + * + * @param httpPost + * @return + */ + private static String sendHttpPost(HttpPost httpPost) { + + CloseableHttpClient httpClient = null; + CloseableHttpResponse response = null; + // 响应内容 + String responseContent = null; + try { + // 创建默认的httpClient实例. + httpClient = getHttpClient(); + // 配置请求信息 + httpPost.setConfig(requestConfig); + // 执行请求 + response = httpClient.execute(httpPost); + // 得到响应实例 + HttpEntity entity = response.getEntity(); + + // 可以获得响应头 + // Header[] headers = response.getHeaders(HttpHeaders.CONTENT_TYPE); + // for (Header header : headers) { + // System.out.println(header.getName()); + // } + + // 得到响应类型 + // System.out.println(ContentType.getOrDefault(response.getEntity()).getMimeType()); + + // 判断响应状态 + if (response.getStatusLine().getStatusCode() >= 300) { + throw new Exception( + "HTTP Request is not success, Response code is " + response.getStatusLine().getStatusCode()); + } + + if (HttpStatus.SC_OK == response.getStatusLine().getStatusCode()) { + responseContent = EntityUtils.toString(entity, CHARSET_UTF_8); + EntityUtils.consume(entity); + } + + } catch (Exception e) { + e.printStackTrace(); + } finally { + try { + // 释放资源 + if (response != null) { + response.close(); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + return responseContent; + } + + /** + * 发送Get请求 + * + * @param httpGet + * @return + */ + private static String sendHttpGet(HttpGet httpGet) { + + CloseableHttpClient httpClient = null; + CloseableHttpResponse response = null; + // 响应内容 + String responseContent = null; + try { + // 创建默认的httpClient实例. + httpClient = getHttpClient(); + // 配置请求信息 + httpGet.setConfig(requestConfig); + // 执行请求 + response = httpClient.execute(httpGet); + // 得到响应实例 + HttpEntity entity = response.getEntity(); + + // 可以获得响应头 + // Header[] headers = response.getHeaders(HttpHeaders.CONTENT_TYPE); + // for (Header header : headers) { + // System.out.println(header.getName()); + // } + + // 得到响应类型 + // System.out.println(ContentType.getOrDefault(response.getEntity()).getMimeType()); + + // 判断响应状态 + if (response.getStatusLine().getStatusCode() >= 300) { + throw new Exception( + "HTTP Request is not success, Response code is " + response.getStatusLine().getStatusCode()); + } + + if (HttpStatus.SC_OK == response.getStatusLine().getStatusCode()) { + responseContent = EntityUtils.toString(entity, CHARSET_UTF_8); + EntityUtils.consume(entity); + } + + } catch (Exception e) { + e.printStackTrace(); + } finally { + try { + // 释放资源 + if (response != null) { + response.close(); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + return responseContent; + } + + /** + * 发送Delete请求 + * + * @param httpDelete + * @return + */ + private static String sendHttpDelete(HttpDelete httpDelete) { + + CloseableHttpClient httpClient = null; + CloseableHttpResponse response = null; + // 响应内容 + String responseContent = null; + try { + // 创建默认的httpClient实例. + httpClient = getHttpClient(); + // 配置请求信息 + httpDelete.setConfig(requestConfig); + // 执行请求 + response = httpClient.execute(httpDelete); + // 得到响应实例 + HttpEntity entity = response.getEntity(); + + // 可以获得响应头 + // Header[] headers = response.getHeaders(HttpHeaders.CONTENT_TYPE); + // for (Header header : headers) { + // System.out.println(header.getName()); + // } + + // 得到响应类型 + // System.out.println(ContentType.getOrDefault(response.getEntity()).getMimeType()); + + // 判断响应状态 + if (response.getStatusLine().getStatusCode() >= 300) { + throw new Exception( + "HTTP Request is not success, Response code is " + response.getStatusLine().getStatusCode()); + } + + if (HttpStatus.SC_OK == response.getStatusLine().getStatusCode()) { + responseContent = EntityUtils.toString(entity, CHARSET_UTF_8); + EntityUtils.consume(entity); + } + + } catch (Exception e) { + e.printStackTrace(); + } finally { + try { + // 释放资源 + if (response != null) { + response.close(); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + return responseContent; + } + + + + /** + * 发送 post请求 + * + * @param httpUrl 地址 + */ + public static String sendHttpPost(String httpUrl) { + // 创建httpPost + HttpPost httpPost = new HttpPost(httpUrl); + return sendHttpPost(httpPost); + } + + /** + * 发送 get请求 + * + * @param httpUrl + */ + public static String sendHttpGet(String httpUrl) { + // 创建get请求 + HttpGet httpGet = new HttpGet(httpUrl); + return sendHttpGet(httpGet); + } + + /** + * 发送 DELETE 请求 + * + * @param httpUrl + */ + public static String sendHttpDelete(String httpUrl) { + // 创建delete请求 + HttpDelete httpDelete = new HttpDelete(httpUrl); + return sendHttpDelete(httpDelete); + } + + + + /** + * 发送 post请求(带文件) + * + * @param httpUrl + * 地址 + * @param maps + * 参数 + * @param fileLists + * 附件 + */ + public static String sendHttpPost(String httpUrl, Map maps, List fileLists) { + HttpPost httpPost = new HttpPost(httpUrl);// 创建httpPost + MultipartEntityBuilder meBuilder = MultipartEntityBuilder.create(); + if (maps != null) { + for (String key : maps.keySet()) { + meBuilder.addPart(key, new StringBody(maps.get(key), ContentType.TEXT_PLAIN)); + } + } + if (fileLists != null) { + for (File file : fileLists) { + FileBody fileBody = new FileBody(file); + meBuilder.addPart("files", fileBody); + } + } + HttpEntity reqEntity = meBuilder.build(); + httpPost.setEntity(reqEntity); + return sendHttpPost(httpPost); + } + + /** + * 发送 post请求 + * + * @param httpUrl + * 地址 + * @param params + * 参数(格式:key1=value1&key2=value2) + * + */ + public static String sendHttpPost(String httpUrl, String params) { + HttpPost httpPost = new HttpPost(httpUrl);// 创建httpPost + try { + // 设置参数 + if (params != null && params.trim().length() > 0) { + StringEntity stringEntity = new StringEntity(params, "UTF-8"); + stringEntity.setContentType(CONTENT_TYPE_FORM_URL); + httpPost.setEntity(stringEntity); + } + } catch (Exception e) { + throw e; + } + return sendHttpPost(httpPost); + } + + /** + * 发送 post请求 + * + * @param maps + * 参数 + */ + public static String sendHttpPost(String httpUrl, Map maps) { + String parem = convertStringParamter(maps); + return sendHttpPost(httpUrl, parem); + } + + + + + /** + * 发送 post请求 发送json数据 + * + * @param httpUrl 地址 + * @param paramsJson 参数(格式 json) + * + */ + public static String sendHttpPostJson(String httpUrl, String paramsJson) { + HttpPost httpPost = new HttpPost(httpUrl);// 创建httpPost + try { + // 设置参数 + if (paramsJson != null && paramsJson.trim().length() > 0) { + StringEntity stringEntity = new StringEntity(paramsJson, "UTF-8"); + stringEntity.setContentType(CONTENT_TYPE_JSON_URL); + httpPost.setEntity(stringEntity); + } + } catch (Exception e) { + e.printStackTrace(); + } + return sendHttpPost(httpPost); + } + + /** + * 发送 post请求 发送xml数据 + * + * @param httpUrl 地址 + * @param paramsXml 参数(格式 Xml) + * + */ + public static String sendHttpPostXml(String httpUrl, String paramsXml) { + HttpPost httpPost = new HttpPost(httpUrl);// 创建httpPost + try { + // 设置参数 + if (paramsXml != null && paramsXml.trim().length() > 0) { + StringEntity stringEntity = new StringEntity(paramsXml, "UTF-8"); + stringEntity.setContentType(CONTENT_TYPE_TEXT_HTML); + httpPost.setEntity(stringEntity); + } + } catch (Exception e) { + e.printStackTrace(); + } + return sendHttpPost(httpPost); + } + + + /** + * 将map集合的键值对转化成:key1=value1&key2=value2 的形式 + * + * @param parameterMap 需要转化的键值对集合 + * @return 字符串 + */ + public static String convertStringParamter(Map parameterMap) { + StringBuffer parameterBuffer = new StringBuffer(); + if (parameterMap != null) { + Iterator iterator = parameterMap.keySet().iterator(); + String key = null; + String value = null; + while (iterator.hasNext()) { + key = (String) iterator.next(); + if (parameterMap.get(key) != null) { + value = (String) parameterMap.get(key); + } else { + value = ""; + } + parameterBuffer.append(key).append("=").append(value); + if (iterator.hasNext()) { + parameterBuffer.append("&"); + } + } + } + return parameterBuffer.toString(); + } + +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/util/ImageUtil.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/util/ImageUtil.java new file mode 100644 index 0000000..4586ad1 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/util/ImageUtil.java @@ -0,0 +1,30 @@ +package com.casic.missiles.modular.system.util; + +import javax.imageio.ImageIO; +import java.awt.*; +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.IOException; + +public class ImageUtil { + public static void main(String[] args) { + BufferedImage bufferedImage; + try { + // read image file + bufferedImage = ImageIO.read(new File("C:\\Users\\zhang\\Desktop\\test.png")); + // create a blank, RGB, same width and height, and a white + // background + BufferedImage newBufferedImage = new BufferedImage( + bufferedImage.getWidth(), bufferedImage.getHeight(), + BufferedImage.TYPE_INT_RGB); + // TYPE_INT_RGB:创建一个RBG图像,24位深度,成功将32位图转化成24位 + newBufferedImage.createGraphics().drawImage(bufferedImage, 0, 0, + Color.WHITE, null); + // write to jpeg file + ImageIO.write(newBufferedImage, "jpg", new File("C:\\Users\\zhang\\Desktop\\test.jpg")); + System.out.println("Done"); + } catch (IOException e) { + e.printStackTrace(); + } + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/util/LocalHostUtil.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/util/LocalHostUtil.java new file mode 100644 index 0000000..1f6c639 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/util/LocalHostUtil.java @@ -0,0 +1,111 @@ +package com.casic.missiles.modular.system.util; + +import java.net.InetAddress; +import java.net.NetworkInterface; +import java.net.SocketException; +import java.net.UnknownHostException; +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.List; + +/** + * 本地主机工具类 + * + * @author zhi + * @since 2019年11月13日09:04:36 + * + */ +public class LocalHostUtil { + + /** + * 获取主机名称 + * + * @return + * @throws UnknownHostException + */ + public static String getHostName() throws UnknownHostException { + return InetAddress.getLocalHost().getHostName(); + } + + /** + * 获取系统首选IP + * + * @return + * @throws UnknownHostException + */ + public static String getLocalIP() throws UnknownHostException { + return InetAddress.getLocalHost().getHostAddress(); + } + + /** + * 获取所有网卡IP,排除回文地址、虚拟地址 + * + * @return + * @throws SocketException + */ + public static String[] getLocalIPs() throws SocketException { + List list = new ArrayList<>(); + Enumeration enumeration = NetworkInterface.getNetworkInterfaces(); + while (enumeration.hasMoreElements()) { + NetworkInterface intf = enumeration.nextElement(); + if (intf.isLoopback() || intf.isVirtual()) { // + continue; + } + Enumeration inets = intf.getInetAddresses(); + while (inets.hasMoreElements()) { + InetAddress addr = inets.nextElement(); + if (addr.isLoopbackAddress() || !addr.isSiteLocalAddress() || addr.isAnyLocalAddress()) { + continue; + } + list.add(addr.getHostAddress()); + } + } + return list.toArray(new String[0]); + } + + /** + * 判断操作系统是否是Windows + * + * @return + */ + public static boolean isWindowsOS() { + boolean isWindowsOS = false; + String osName = System.getProperty("os.name"); + if (osName.toLowerCase().indexOf("windows") > -1) { + isWindowsOS = true; + } + return isWindowsOS; + } + + public static void main(String[] args) { +// try { +// System.out.println("主机是否为Windows系统:" + LocalHostUtil.isWindowsOS()); +// System.out.println("主机名称:" + LocalHostUtil.getHostName()); +// System.out.println("系统首选IP:" + LocalHostUtil.getLocalIP()); +// System.out.println("系统所有IP:" + String.join(",", LocalHostUtil.getLocalIPs())); +// } catch (UnknownHostException e) { +// } catch (Exception e) { +// e.printStackTrace(); +// } + try { + Enumeration faces = NetworkInterface.getNetworkInterfaces(); + while (faces.hasMoreElements()) { // 遍历网络接口 + NetworkInterface face = faces.nextElement(); + if (face.isLoopback() || face.isVirtual() || !face.isUp()) { + continue; + } + System.out.print("网络接口名:" + face.getDisplayName() + ",地址:"); + Enumeration address = face.getInetAddresses(); + while (address.hasMoreElements()) { // 遍历网络地址 + InetAddress addr = address.nextElement(); + if (!addr.isLoopbackAddress() && addr.isSiteLocalAddress() && !addr.isAnyLocalAddress()) { + System.out.print(addr.getHostAddress() + " "); + } + } + System.out.println(""); + } + } catch (SocketException e) { + e.printStackTrace(); + } + } +} diff --git a/casic-iris-register/src/main/java/com/casic/missiles/modular/register/dao/mapping/IrisPersonMapper.xml b/casic-iris-register/src/main/java/com/casic/missiles/modular/register/dao/mapping/IrisPersonMapper.xml new file mode 100644 index 0000000..c974147 --- /dev/null +++ b/casic-iris-register/src/main/java/com/casic/missiles/modular/register/dao/mapping/IrisPersonMapper.xml @@ -0,0 +1,20 @@ + + + + + + + diff --git a/casic-face-sync/pom.xml b/casic-face-sync/pom.xml new file mode 100644 index 0000000..24dc884 --- /dev/null +++ b/casic-face-sync/pom.xml @@ -0,0 +1,74 @@ + + + 4.0.0 + + com.casic + casic-iris-parent + 1.0.0-SNAPSHOT + ../pom.xml + + + + casic-face-sync + ${pro.version} + jar + casic-face-sync + + + + + + com.casic + casic-core + ${core.version} + + + + com.casic + casic-admin-support + ${admin.version} + + + com.casic + casic-iris-support + ${pro.version} + + + + org.apache.httpcomponents + httpclient + 4.5.3 + + + + org.apache.httpcomponents + httpcore + 4.4.8 + + + + org.apache.httpcomponents + httpmime + 4.5.3 + + + + com.google.code.gson + gson + + + + + + + + src/main/java + + **/*.xml + + + + + \ No newline at end of file diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/constant/FaceSyncConst.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/constant/FaceSyncConst.java new file mode 100644 index 0000000..352d47d --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/constant/FaceSyncConst.java @@ -0,0 +1,29 @@ +package com.casic.missiles.modular.system.constant; + +public class FaceSyncConst { + + /** + * 单次最大批量上传人员数 + */ + public static final int UPLOAD_MAX_PERSON = 6; + + /** + * 上传人员库 + */ + public static final String UPLOAD_STAFF_LIB = "3"; + public static final String UPLOAD_VISITOR_LIB = "4"; + + public static final String UPLOAD_URL_PREFIX = "/LAPI/V1.0/PeopleLibraries/"; + + public static final String UPLOAD_URL_SUFFIX = "/People"; + + public static final int UPLOAD_PERSONCODE_MAXLENGTH = 15; + + public static final int UPLOAD_REMARK_MAXLENGTH = 63; + + public static final String SUBSCRIBE_URL = "/LAPI/V1.0/System/Event/Subscription/"; + + public static final String STAFF_PERSON_TYPE = "1"; + + public static final String VISITOR_PERSON_TYPE = "0"; +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/controller/FaceSyncController.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/controller/FaceSyncController.java new file mode 100644 index 0000000..1b35431 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/controller/FaceSyncController.java @@ -0,0 +1,117 @@ +package com.casic.missiles.modular.system.controller; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson.serializer.SerializerFeature; +import com.casic.missiles.core.base.response.ResponseData; +import com.casic.missiles.core.common.service.ICommonPermissionService; +import com.casic.missiles.core.common.service.ICommonPersonService; +import com.casic.missiles.core.datascope.DataScope; +import com.casic.missiles.core.util.ToolUtil; +import com.casic.missiles.modular.system.request.PersonInfo; +import com.casic.missiles.modular.system.response.RecordNotification; +import com.casic.missiles.modular.system.service.IFaceSyncService; +import com.casic.missiles.modular.system.service.IIrisPersonSupportService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.*; +import com.casic.missiles.modular.system.constant.FaceSyncConst; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + + + +@Controller +public class FaceSyncController { + private final static Logger logger = LoggerFactory.getLogger(FaceSyncController.class); + + @Autowired + private IFaceSyncService syncService; + @Autowired + private ICommonPersonService commonPersonService; + @Autowired + private IIrisPersonSupportService personSupportService; + @Autowired + private ICommonPermissionService permissionService; + + @RequestMapping("/face/upload") + @ResponseBody + public Object upload(@RequestParam("personIds") List personIds, + @RequestParam("deviceIds") List deviceIds, + @RequestParam("personType")String personType ){ + // 检查数量 +// if(personIds.size()>FaceSyncConst.UPLOAD_MAX_PERSON){ +// return ResponseData.error(String.format("每次最多上传%s个人",FaceSyncConst.UPLOAD_MAX_PERSON)); +// } + // 检查照片格式及大小 + String photoCheck = syncService.checkPersonPhoto(personIds); + if(ToolUtil.isNotEmpty(photoCheck)){ + return ResponseData.error(photoCheck); + } + else{ + // 上传数据 + String error = syncService.uploadPerson(personIds,deviceIds,personType); + if(ToolUtil.isNotEmpty(error)){ + return ResponseData.error(error); + } + } + return ResponseData.success(); + } + + @RequestMapping("/face/uploadAll") + @ResponseBody + public Object uploadAll(@RequestParam("deviceIds") List deviceIds){ + DataScope dataScope = permissionService.getCurrUserDataScope(); + + List staffPersonIds = personSupportService.listIdsByType(dataScope,FaceSyncConst.STAFF_PERSON_TYPE); + List visitorPersonIds = personSupportService.listIdsByType(dataScope,FaceSyncConst.VISITOR_PERSON_TYPE); + // 1.检查照片,分别检查员工、访客 + String staffPhotoCheck = syncService.checkPersonPhoto(staffPersonIds); + if(ToolUtil.isNotEmpty(staffPhotoCheck)){ + return ResponseData.error(staffPhotoCheck); + } + String visitorPhotoCheck = syncService.checkPersonPhoto(visitorPersonIds); + if(ToolUtil.isNotEmpty(visitorPhotoCheck)){ + return ResponseData.error(visitorPhotoCheck); + } + + // 2. 下发数据 + String staffError = syncService.uploadPerson(staffPersonIds,deviceIds,FaceSyncConst.STAFF_PERSON_TYPE); + if(ToolUtil.isNotEmpty(staffError)){ + return ResponseData.error(staffError); + } + String visitorError = syncService.uploadPerson(visitorPersonIds,deviceIds,FaceSyncConst.VISITOR_PERSON_TYPE); + if(ToolUtil.isNotEmpty(visitorError)){ + return ResponseData.error(visitorError); + } + + return ResponseData.success(); + } + + // 错误信息返回 + @RequestMapping("/subsrcibe/init") + @ResponseBody + public Object upload(@RequestParam("deviceIds") List deviceIds){ + String errorMsg = syncService.initSubscription(deviceIds); + if(ToolUtil.isNotEmpty(errorMsg)){ + return ResponseData.error(errorMsg); + } + return ResponseData.success(); + } + + + @RequestMapping(value = "/LAPI/V1.0/System/Event/Notification/PersonVerification", method = RequestMethod.POST) + @ResponseBody + public void verification(@RequestBody String recordNotification){ + logger.info(recordNotification); + RecordNotification record = JSONObject.parseObject(recordNotification,RecordNotification.class); + syncService.receiveRecord(record); + //return ResponseData.success(); + } + + +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FacePersonSyncMapper.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FacePersonSyncMapper.java new file mode 100644 index 0000000..af53702 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FacePersonSyncMapper.java @@ -0,0 +1,17 @@ +package com.casic.missiles.modular.system.dao; + +import com.casic.missiles.modular.system.model.FacePersonSync; +import com.baomidou.mybatisplus.mapper.BaseMapper; + +/** + *

+ * Mapper 接口 + *

+ * + * @author zyj123 + * @since 2020-07-24 + */ +public interface FacePersonSyncMapper extends BaseMapper { + + Long getMaxSyncId(); +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FaceSubscribeMapper.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FaceSubscribeMapper.java new file mode 100644 index 0000000..0c6374a --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FaceSubscribeMapper.java @@ -0,0 +1,16 @@ +package com.casic.missiles.modular.system.dao; + +import com.casic.missiles.modular.system.model.FaceSubscribe; +import com.baomidou.mybatisplus.mapper.BaseMapper; + +/** + *

+ * Mapper 接口 + *

+ * + * @author zyj123 + * @since 2020-07-25 + */ +public interface FaceSubscribeMapper extends BaseMapper { + +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FacePersonSyncMapper.xml b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FacePersonSyncMapper.xml new file mode 100644 index 0000000..ac46ad0 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FacePersonSyncMapper.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + PERSON_ID AS personId, SYNC_ID AS syncId + + + + + diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FaceSubscribeMapper.xml b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FaceSubscribeMapper.xml new file mode 100644 index 0000000..16024e2 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FaceSubscribeMapper.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + SUBSCRIBE_ID AS subscribeId, DEVICE_CODE AS deviceCode, UPDATE_TIME AS updateTime + + + diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FacePersonSync.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FacePersonSync.java new file mode 100644 index 0000000..7cdb821 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FacePersonSync.java @@ -0,0 +1,68 @@ +package com.casic.missiles.modular.system.model; + +import java.io.Serializable; + +import com.baomidou.mybatisplus.annotations.TableId; +import com.baomidou.mybatisplus.annotations.TableField; +import com.baomidou.mybatisplus.activerecord.Model; +import com.baomidou.mybatisplus.annotations.TableName; +import java.io.Serializable; + +/** + *

+ * + *

+ * + * @author zyj123 + * @since 2020-07-24 + */ +@TableName("face_person_sync") +public class FacePersonSync extends Model { + + private static final long serialVersionUID = 1L; + + /** + * 人员id + */ + @TableId("PERSON_ID") + private Long personId; + /** + * 人员同步id + */ + @TableField("SYNC_ID") + private Long syncId; + + public FacePersonSync(Long personId, Long syncId) { + this.personId = personId; + this.syncId = syncId; + } + + public Long getPersonId() { + return personId; + } + + public void setPersonId(Long personId) { + this.personId = personId; + } + + public Long getSyncId() { + return syncId; + } + + public void setSyncId(Long syncId) { + this.syncId = syncId; + } + + @Override + protected Serializable pkVal() { + return this.personId; + } + + @Override + public String toString() { + return "FacePersonSync{" + + "personId=" + personId + + ", syncId=" + syncId + + "}"; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FaceSubscribe.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FaceSubscribe.java new file mode 100644 index 0000000..ccc7792 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FaceSubscribe.java @@ -0,0 +1,79 @@ +package com.casic.missiles.modular.system.model; + +import java.io.Serializable; + +import java.util.Date; +import com.baomidou.mybatisplus.annotations.TableId; +import com.baomidou.mybatisplus.annotations.TableField; +import com.baomidou.mybatisplus.activerecord.Model; +import com.baomidou.mybatisplus.annotations.TableName; +import java.io.Serializable; + +/** + *

+ * + *

+ * + * @author zyj123 + * @since 2020-07-25 + */ +@TableName("face_subscribe") +public class FaceSubscribe extends Model { + + private static final long serialVersionUID = 1L; + + /** + * 订阅id + */ + @TableId("SUBSCRIBE_ID") + private Long subscribeId; + /** + * 设备编号 + */ + @TableField("DEVICE_CODE") + private String deviceCode; + /** + * 更新时间 + */ + @TableField("UPDATE_TIME") + private Date updateTime; + + + public Long getSubscribeId() { + return subscribeId; + } + + public void setSubscribeId(Long subscribeId) { + this.subscribeId = subscribeId; + } + + public String getDeviceCode() { + return deviceCode; + } + + public void setDeviceCode(String deviceCode) { + this.deviceCode = deviceCode; + } + + public Date getUpdateTime() { + return updateTime; + } + + public void setUpdateTime(Date updateTime) { + this.updateTime = updateTime; + } + + @Override + protected Serializable pkVal() { + return this.subscribeId; + } + + @Override + public String toString() { + return "FaceSubscribe{" + + "subscribeId=" + subscribeId + + ", deviceCode=" + deviceCode + + ", updateTime=" + updateTime + + "}"; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/request/PersonInfo.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/request/PersonInfo.java new file mode 100644 index 0000000..80d9eff --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/request/PersonInfo.java @@ -0,0 +1,271 @@ +package com.casic.missiles.modular.system.request; + +import com.alibaba.fastjson.annotation.JSONField; +import com.baomidou.mybatisplus.annotations.TableField; +import com.google.gson.annotations.SerializedName; + +import java.util.List; + +public class PersonInfo { + + //@JSONField(name = "PersonID") + @SerializedName("PersonID") + private Long personID; + + //@JSONField(name = "LastChange") + @SerializedName("LastChange") + private Long lastChange; + + //@JSONField(name = "PersonCode") + @SerializedName("PersonCode") + private String personCode; + + //@JSONField(name = "PersonName") + @SerializedName("PersonName") + private String personName; + + //@JSONField(name = "Remarks") + @SerializedName("Remarks") + private String remarks; + + //@JSONField(name = "TimeTemplateNum") + @SerializedName("TimeTemplateNum") + private Integer timeTemplateNum; + + //@JSONField(name = "TimeTemplateList") + @SerializedName("TimeTemplateList") + private List timeTemplateList; + + //@JSONField(name = "IdentificationNum") + @SerializedName("IdentificationNum") + private Integer identificationNum; + + //@JSONField(name = "IdentificationList") + @SerializedName("IdentificationList") + private List identificationList; + + //@JSONField(name = "ImageNum") + @SerializedName("ImageNum") + private Integer imageNum; + + //@JSONField(name = "ImageList") + @SerializedName("ImageList") + private List imageList; + + public Long getPersonID() { + return personID; + } + + public void setPersonID(Long personID) { + this.personID = personID; + } + + public Long getLastChange() { + return lastChange; + } + + public void setLastChange(Long lastChange) { + this.lastChange = lastChange; + } + + public String getPersonCode() { + return personCode; + } + + public void setPersonCode(String personCode) { + this.personCode = personCode; + } + + public String getPersonName() { + return personName; + } + + public void setPersonName(String personName) { + this.personName = personName; + } + + public String getRemarks() { + return remarks; + } + + public void setRemarks(String remarks) { + this.remarks = remarks; + } + + public Integer getTimeTemplateNum() { + return timeTemplateNum; + } + + public void setTimeTemplateNum(Integer timeTemplateNum) { + this.timeTemplateNum = timeTemplateNum; + } + + public List getTimeTemplateList() { + return timeTemplateList; + } + + public void setTimeTemplateList(List timeTemplateList) { + this.timeTemplateList = timeTemplateList; + } + + public Integer getIdentificationNum() { + return identificationNum; + } + + public void setIdentificationNum(Integer identificationNum) { + this.identificationNum = identificationNum; + } + + public List getIdentificationList() { + return identificationList; + } + + public void setIdentificationList(List identificationList) { + this.identificationList = identificationList; + } + + public Integer getImageNum() { + return imageNum; + } + + public void setImageNum(Integer imageNum) { + this.imageNum = imageNum; + } + + public List getImageList() { + return imageList; + } + + public void setImageList(List imageList) { + this.imageList = imageList; + } + + public class TimeTemplate{ + @JSONField(name = "BeginTime") + private Long beginTime; + @JSONField(name = "EndTime") + private Long endTime; + @JSONField(name = "Index") + private Long index; + + public TimeTemplate(Long beginTime, Long endTime, Long index) { + this.beginTime = beginTime; + this.endTime = endTime; + this.index = index; + } + + public Long getBeginTime() { + return beginTime; + } + + public void setBeginTime(Long beginTime) { + this.beginTime = beginTime; + } + + public Long getEndTime() { + return endTime; + } + + public void setEndTime(Long endTime) { + this.endTime = endTime; + } + + public Long getIndex() { + return index; + } + + public void setIndex(Long index) { + this.index = index; + } + } + + public TimeTemplate createTimeTemplate(Long beginTime, Long endTime, Long index){ + return new TimeTemplate(beginTime, endTime, index); + } + + public class IdentificationInfo { + @JSONField(name = "Type") + private Integer type; + @JSONField(name = "Number") + private String number; + + public IdentificationInfo(Integer type, String number) { + this.type = type; + this.number = number; + } + + public Integer getType() { + return type; + } + + public void setType(Integer type) { + this.type = type; + } + + public String getNumber() { + return number; + } + + public void setNumber(String number) { + this.number = number; + } + } + + public IdentificationInfo createIdentificationInfo(Integer type, String number){ + return new IdentificationInfo(type,number); + } + + public class ImageInfo{ + @JSONField(name = "FaceID") + private Long faceID; + @JSONField(name = "Name") + private String name; + @JSONField(name = "Size") + private Long size; + @JSONField(name = "Data") + private String data; + + public ImageInfo(Long faceID, String name, Long size, String data) { + this.faceID = faceID; + this.name = name; + this.size = size; + this.data = data; + } + + public Long getFaceID() { + return faceID; + } + + public void setFaceID(Long faceID) { + this.faceID = faceID; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Long getSize() { + return size; + } + + public void setSize(Long size) { + this.size = size; + } + + public String getData() { + return data; + } + + public void setData(String data) { + this.data = data; + } + } + + public ImageInfo createImageInfo(Long faceID, String name, Long size, String data){ + return new ImageInfo(faceID, name, size, data); + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceBaseResponse.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceBaseResponse.java new file mode 100644 index 0000000..fe93b8a --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceBaseResponse.java @@ -0,0 +1,90 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; +import com.google.gson.annotations.SerializedName; + +public class FaceBaseResponse { + @JSONField(name = "ResponseURL") + @SerializedName("ResponseURL") + private String responseUrl; + + @JSONField(name = "CreatedID") + @SerializedName("CreatedID") + private int createdId; + + @JSONField(name = "ResponseCode") + @SerializedName("ResponseCode") + private int responseCode; + + @JSONField(name = "ResponseString") + @SerializedName("ResponseString") + private String responseString; + + @JSONField(name = "StatusCode") + @SerializedName("StatusCode") + private int statusCode; + + @JSONField(name = "StatusString") + @SerializedName("StatusString") + private String statusString; + + //@JSONField(name = "Data") + @SerializedName("Data") + private T data; + + public String getResponseUrl() { + return responseUrl; + } + + public void setResponseUrl(String responseUrl) { + this.responseUrl = responseUrl; + } + + public int getCreatedId() { + return createdId; + } + + public void setCreatedId(int createdId) { + this.createdId = createdId; + } + + public int getResponseCode() { + return responseCode; + } + + public void setResponseCode(int responseCode) { + this.responseCode = responseCode; + } + + public String getResponseString() { + return responseString; + } + + public void setResponseString(String responseString) { + this.responseString = responseString; + } + + public int getStatusCode() { + return statusCode; + } + + public void setStatusCode(int statusCode) { + this.statusCode = statusCode; + } + + public String getStatusString() { + return statusString; + } + + public void setStatusString(String statusString) { + this.statusString = statusString; + } + + public T getData() { + return data; + } + + public void setData(T data) { + this.data = data; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceInfo.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceInfo.java new file mode 100644 index 0000000..f128c92 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceInfo.java @@ -0,0 +1,128 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; + +import java.util.List; + +public class FaceInfo { + @JSONField(name = "ID") + private Long id; + @JSONField(name = "Timestamp") + private Long timestamp; + @JSONField(name = "CapSrc") + private Long capSrc; + @JSONField(name = "FeatureNum") + private Long featureNum; + @JSONField(name = "FeatureList") + private List featureList; + @JSONField(name = "FeatureVersion") + private String featureVersion; + @JSONField(name = "Feature") + private String feature; + @JSONField(name = "Temperature") + private Float temperature; + @JSONField(name = "MaskFlag") + private Long maskFlag; + @JSONField(name = "PanoImage") + private Object panoImage; + @JSONField(name = "FaceImage") + private Object faceImage; + @JSONField(name = "FaceArea") + private Object faceArea; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Long getTimestamp() { + return timestamp; + } + + public void setTimestamp(Long timestamp) { + this.timestamp = timestamp; + } + + public Long getCapSrc() { + return capSrc; + } + + public void setCapSrc(Long capSrc) { + this.capSrc = capSrc; + } + + public Long getFeatureNum() { + return featureNum; + } + + public void setFeatureNum(Long featureNum) { + this.featureNum = featureNum; + } + + public List getFeatureList() { + return featureList; + } + + public void setFeatureList(List featureList) { + this.featureList = featureList; + } + + public String getFeatureVersion() { + return featureVersion; + } + + public void setFeatureVersion(String featureVersion) { + this.featureVersion = featureVersion; + } + + public String getFeature() { + return feature; + } + + public void setFeature(String feature) { + this.feature = feature; + } + + public Float getTemperature() { + return temperature; + } + + public void setTemperature(Float temperature) { + this.temperature = temperature; + } + + public Long getMaskFlag() { + return maskFlag; + } + + public void setMaskFlag(Long maskFlag) { + this.maskFlag = maskFlag; + } + + public Object getPanoImage() { + return panoImage; + } + + public void setPanoImage(Object panoImage) { + this.panoImage = panoImage; + } + + public Object getFaceImage() { + return faceImage; + } + + public void setFaceImage(Object faceImage) { + this.faceImage = faceImage; + } + + public Object getFaceArea() { + return faceArea; + } + + public void setFaceArea(Object faceArea) { + this.faceArea = faceArea; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/LibMatInfo.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/LibMatInfo.java new file mode 100644 index 0000000..ce6dd33 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/LibMatInfo.java @@ -0,0 +1,69 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; + +public class LibMatInfo { + @JSONField(name = "ID") + private Long id; + @JSONField(name = "LibID") + private Long libId; + @JSONField(name = "LibType") + private Long libType; + @JSONField(name = "MatchStatus") + private Long matchStatus; + @JSONField(name = "MatchPersonID") + private Long matchPersonId; + @JSONField(name = "MatchFaceID") + private Long matchFaceId; + + // MatchPersonInfo 暂时忽略不用 + + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Long getLibId() { + return libId; + } + + public void setLibId(Long libId) { + this.libId = libId; + } + + public Long getLibType() { + return libType; + } + + public void setLibType(Long libType) { + this.libType = libType; + } + + public Long getMatchStatus() { + return matchStatus; + } + + public void setMatchStatus(Long matchStatus) { + this.matchStatus = matchStatus; + } + + public Long getMatchPersonId() { + return matchPersonId; + } + + public void setMatchPersonId(Long matchPersonId) { + this.matchPersonId = matchPersonId; + } + + public Long getMatchFaceId() { + return matchFaceId; + } + + public void setMatchFaceId(Long matchFaceId) { + this.matchFaceId = matchFaceId; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/PersonResponseData.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/PersonResponseData.java new file mode 100644 index 0000000..186faed --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/PersonResponseData.java @@ -0,0 +1,31 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; +import com.google.gson.annotations.SerializedName; + +import java.util.List; + +public class PersonResponseData { + @JSONField(name = "Num") + @SerializedName("Num") + private int num; + @JSONField(name = "PersonList") + @SerializedName("PersonList") + private List personList; + + public int getNum() { + return num; + } + + public void setNum(int num) { + this.num = num; + } + + public List getPersonList() { + return personList; + } + + public void setPersonList(List personList) { + this.personList = personList; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/PersonResponseInfo.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/PersonResponseInfo.java new file mode 100644 index 0000000..7ba3edc --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/PersonResponseInfo.java @@ -0,0 +1,67 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; +import com.google.gson.annotations.SerializedName; + +import java.util.List; + +public class PersonResponseInfo { + @JSONField(name = "PersonID") + @SerializedName("PersonID") + private Long personId; + @JSONField(name = "FaceNum") + @SerializedName("FaceNum") + private Long faceNum; + @JSONField(name = "FaceList") + @SerializedName("FaceList") + private List faceList; + + public Long getPersonId() { + return personId; + } + + public void setPersonId(Long personId) { + this.personId = personId; + } + + public Long getFaceNum() { + return faceNum; + } + + public void setFaceNum(Long faceNum) { + this.faceNum = faceNum; + } + + public List getFaceList() { + return faceList; + } + + public void setFaceList(List faceList) { + this.faceList = faceList; + } + + public class PersonResponseFace{ + @JSONField(name = "FaceID") + @SerializedName("FaceID") + private Long faceId; + @JSONField(name = "ResultCode") + @SerializedName("ResultCode") + private Long resultCode; + + public Long getFaceId() { + return faceId; + } + + public void setFaceId(Long faceId) { + this.faceId = faceId; + } + + public Long getResultCode() { + return resultCode; + } + + public void setResultCode(Long resultCode) { + this.resultCode = resultCode; + } + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/RecordNotification.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/RecordNotification.java new file mode 100644 index 0000000..ca52d29 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/RecordNotification.java @@ -0,0 +1,138 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; + +import java.util.List; + +public class RecordNotification { + @JSONField(name = "Reference") + private String reference; + @JSONField(name = "Seq") + private int seq; + @JSONField(name = "DeviceCode") + private String deviceCode; + @JSONField(name = "Timestamp") + private Long timestamp; + @JSONField(name = "NotificationType") + private int notificationType; + @JSONField(name = "FaceInfoNum") + private int faceInfoNum; + @JSONField(name = "FaceInfoList") + private List faceInfoList; + @JSONField(name = "CardInfoNum") + private int cardInfoNum; + @JSONField(name = "CardInfoList") + private List cardInfoList; + @JSONField(name = "GateInfoNum") + private int gateInfoNum; + @JSONField(name = "GateInfoList") + private List gateInfoList; + @JSONField(name = "LibMatInfoNum") + private int libMatInfoNum; + @JSONField(name = "LibMatInfoList") + private List libMatInfoList; + + public String getReference() { + return reference; + } + + public void setReference(String reference) { + this.reference = reference; + } + + public int getSeq() { + return seq; + } + + public void setSeq(int seq) { + this.seq = seq; + } + + public String getDeviceCode() { + return deviceCode; + } + + public void setDeviceCode(String deviceCode) { + this.deviceCode = deviceCode; + } + + public Long getTimestamp() { + return timestamp; + } + + public void setTimestamp(Long timestamp) { + this.timestamp = timestamp; + } + + public int getNotificationType() { + return notificationType; + } + + public void setNotificationType(int notificationType) { + this.notificationType = notificationType; + } + + public int getFaceInfoNum() { + return faceInfoNum; + } + + public void setFaceInfoNum(int faceInfoNum) { + this.faceInfoNum = faceInfoNum; + } + + public List getFaceInfoList() { + return faceInfoList; + } + + public void setFaceInfoList(List faceInfoList) { + this.faceInfoList = faceInfoList; + } + + public int getCardInfoNum() { + return cardInfoNum; + } + + public void setCardInfoNum(int cardInfoNum) { + this.cardInfoNum = cardInfoNum; + } + + public List getCardInfoList() { + return cardInfoList; + } + + public void setCardInfoList(List cardInfoList) { + this.cardInfoList = cardInfoList; + } + + public int getGateInfoNum() { + return gateInfoNum; + } + + public void setGateInfoNum(int gateInfoNum) { + this.gateInfoNum = gateInfoNum; + } + + public List getGateInfoList() { + return gateInfoList; + } + + public void setGateInfoList(List gateInfoList) { + this.gateInfoList = gateInfoList; + } + + public int getLibMatInfoNum() { + return libMatInfoNum; + } + + public void setLibMatInfoNum(int libMatInfoNum) { + this.libMatInfoNum = libMatInfoNum; + } + + public List getLibMatInfoList() { + return libMatInfoList; + } + + public void setLibMatInfoList(List libMatInfoList) { + this.libMatInfoList = libMatInfoList; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/runner/InitSubscribeRunner.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/runner/InitSubscribeRunner.java new file mode 100644 index 0000000..c7d0565 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/runner/InitSubscribeRunner.java @@ -0,0 +1,43 @@ +package com.casic.missiles.modular.system.runner; + +import com.casic.missiles.modular.system.model.Device; +import com.casic.missiles.modular.system.service.IDeviceSupportService; +import com.casic.missiles.modular.system.service.IFaceSyncService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.ApplicationArguments; +import org.springframework.boot.ApplicationRunner; +import org.springframework.stereotype.Component; + +import java.util.ArrayList; +import java.util.List; + +@Component +public class InitSubscribeRunner implements ApplicationRunner { + private static Logger logger = LoggerFactory.getLogger(InitSubscribeRunner.class); + + @Value("${iris.face.initSubscribe}") + private String initSubscribe; + @Autowired + private IDeviceSupportService deviceSupportService; + @Autowired + private IFaceSyncService faceSyncService; + + /** + * 启动项目时,根据需要初始化设备订阅信息 + * @param applicationArguments + * @throws Exception + */ + @Override + public void run(ApplicationArguments applicationArguments) throws Exception { + logger.info("==================initSubscribe: "); + if(Boolean.valueOf(initSubscribe)){ + List deviceList = deviceSupportService.selectDeviceByType("5"); + List deviceIds = new ArrayList<>(); + deviceList.forEach(device -> deviceIds.add(Long.valueOf(device.getId()))); + faceSyncService.initSubscription(deviceIds); + } + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFacePersonSyncService.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFacePersonSyncService.java new file mode 100644 index 0000000..6b2461b --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFacePersonSyncService.java @@ -0,0 +1,18 @@ +package com.casic.missiles.modular.system.service; + +import com.casic.missiles.modular.system.model.FacePersonSync; +import com.baomidou.mybatisplus.service.IService; + +/** + *

+ * 服务类 + *

+ * + * @author zyj123 + * @since 2020-07-24 + */ +public interface IFacePersonSyncService extends IService { + Long selectSyncId(Long personId); + Long selectPersonId(Long syncId); + Long getMaxSyncId(Long personId); +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFaceSubscribeService.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFaceSubscribeService.java new file mode 100644 index 0000000..e0461ed --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFaceSubscribeService.java @@ -0,0 +1,24 @@ +package com.casic.missiles.modular.system.service; + +import com.casic.missiles.modular.system.model.FaceSubscribe; +import com.baomidou.mybatisplus.service.IService; + +import java.util.List; + +/** + *

+ * 服务类 + *

+ * + * @author zyj123 + * @since 2020-07-25 + */ +public interface IFaceSubscribeService extends IService { + + List selectSubscribeIdsByDevCode(String devCode); + + boolean deleteByDevCode(String devCode); + + boolean insertSubscribe(Long subscribeId, String devCode); + +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFaceSyncService.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFaceSyncService.java new file mode 100644 index 0000000..effd921 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFaceSyncService.java @@ -0,0 +1,21 @@ +package com.casic.missiles.modular.system.service; + +import com.casic.missiles.modular.system.response.RecordNotification; + +import java.util.List; + +public interface IFaceSyncService { + String uploadPerson(List personIds, List deviceIds,String personType); + + String checkPersonPhoto(List personIds); + + void receiveRecord(RecordNotification recordNotification); + + void receiveRecord(String recordNotificationStr); + + String initSubscription(List deviceIds); + + boolean deleteSubscription(String deviceIp, Long subscribeId); + + Long createSubscription(String deviceIp,String ip,String port); +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/Impl/FacePersonSyncServiceImpl.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/Impl/FacePersonSyncServiceImpl.java new file mode 100644 index 0000000..d1d1694 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/Impl/FacePersonSyncServiceImpl.java @@ -0,0 +1,55 @@ +package com.casic.missiles.modular.system.service.Impl; + +import com.baomidou.mybatisplus.mapper.EntityWrapper; +import com.casic.missiles.core.util.ToolUtil; +import com.casic.missiles.modular.system.model.FacePersonSync; +import com.casic.missiles.modular.system.dao.FacePersonSyncMapper; +import com.casic.missiles.modular.system.service.IFacePersonSyncService; +import com.baomidou.mybatisplus.service.impl.ServiceImpl; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +/** + *

+ * 服务实现类 + *

+ * + * @author zyj123 + * @since 2020-07-24 + */ +@Service +public class FacePersonSyncServiceImpl extends ServiceImpl implements IFacePersonSyncService { + + @Override + public Long selectSyncId(Long personId) { + FacePersonSync facePersonSync = this.selectById(personId); + if(ToolUtil.isNotEmpty(facePersonSync)){ + return facePersonSync.getSyncId(); + } + return null; + } + + @Override + public Long selectPersonId(Long syncId) { + EntityWrapper query = new EntityWrapper(); + query.eq("SYNC_ID",syncId); + FacePersonSync facePersonSync = this.selectOne(query); + if(ToolUtil.isNotEmpty(facePersonSync)){ + return facePersonSync.getPersonId(); + } + return null; + } + + @Override + @Transactional + public Long getMaxSyncId(Long personId) { + Long maxId = this.baseMapper.getMaxSyncId(); + if(ToolUtil.isEmpty(maxId)){ + maxId = 1000L; + }else { + maxId = maxId + 1; + } + this.insert(new FacePersonSync(personId,maxId)); + return maxId; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/Impl/FaceSubscribeServiceImpl.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/Impl/FaceSubscribeServiceImpl.java new file mode 100644 index 0000000..c04302d --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/Impl/FaceSubscribeServiceImpl.java @@ -0,0 +1,52 @@ +package com.casic.missiles.modular.system.service.Impl; + +import com.baomidou.mybatisplus.mapper.EntityWrapper; +import com.casic.missiles.modular.system.model.FaceSubscribe; +import com.casic.missiles.modular.system.dao.FaceSubscribeMapper; +import com.casic.missiles.modular.system.service.IFaceSubscribeService; +import com.baomidou.mybatisplus.service.impl.ServiceImpl; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +/** + *

+ * 服务实现类 + *

+ * + * @author zyj123 + * @since 2020-07-25 + */ +@Service +public class FaceSubscribeServiceImpl extends ServiceImpl implements IFaceSubscribeService { + + @Override + public List selectSubscribeIdsByDevCode(String devCode) { + EntityWrapper query = new EntityWrapper(); + query.eq("DEVICE_CODE",devCode); + List faceSubscribes = this.selectList(query); + List subscribeIds = new ArrayList<>(); + for (FaceSubscribe faceSubscribe : faceSubscribes) { + subscribeIds.add(faceSubscribe.getSubscribeId()); + } + return subscribeIds; + } + + @Override + public boolean deleteByDevCode(String devCode) { + EntityWrapper query = new EntityWrapper(); + query.eq("DEVICE_CODE",devCode); + return this.delete(query); + } + + @Override + public boolean insertSubscribe(Long subscribeId, String devCode) { + FaceSubscribe faceSubscribe = new FaceSubscribe(); + faceSubscribe.setDeviceCode(devCode); + faceSubscribe.setSubscribeId(subscribeId); + faceSubscribe.setUpdateTime(new Date()); + return this.insert(faceSubscribe); + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/Impl/FaceSyncServiceImpl.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/Impl/FaceSyncServiceImpl.java new file mode 100644 index 0000000..8826be5 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/Impl/FaceSyncServiceImpl.java @@ -0,0 +1,465 @@ +package com.casic.missiles.modular.system.service.Impl; + +import com.alibaba.fastjson.JSONObject; +import com.casic.missiles.core.common.service.ICommonPersonService; +import com.casic.missiles.core.util.ToolUtil; +import com.casic.missiles.modular.system.model.Device; +import com.casic.missiles.modular.system.model.FacePersonSync; +import com.casic.missiles.modular.system.model.Person; +import com.casic.missiles.modular.system.model.RecognitionRecords; +import com.casic.missiles.modular.system.request.PersonInfo; +import com.casic.missiles.modular.system.response.*; +import com.casic.missiles.modular.system.service.*; +import com.casic.missiles.modular.system.util.HttpClientUtil; +import com.google.gson.*; +import org.apache.commons.lang3.StringUtils; +import org.omg.CORBA.Object; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import com.casic.missiles.modular.system.constant.FaceSyncConst; +import java.net.InetAddress; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +@Service +public class FaceSyncServiceImpl implements IFaceSyncService { + private static final Logger logger = LoggerFactory.getLogger(FaceSyncServiceImpl.class); + + @Autowired + private IFacePersonSyncService personSyncService; + @Autowired + private ICommonPersonService commonPersonService; + @Autowired + private IPersonPhotoSupportService photoSupportService; + @Autowired + private IDeviceSupportService deviceSupportService; + @Autowired + private IRecordSupportService recordSupportService; + @Autowired + private IFaceSubscribeService subscribeService; + @Value("${server.port}") + private String serverPort; + @Value("${iris.face.serverHost}") + private String serverHost; + + @Override + @Transactional + public String uploadPerson(List personIds,List deviceIds,String personType) { + String error = null; + + try{ + List personInfoList = new ArrayList<>(personIds.size()); + for (Long personId : personIds) { + Person person = commonPersonService.getPersonById(personId); + Long syncId = getPersonSyncId(personId); + String photoData = photoSupportService.selectPhotoDataById(personId); + PersonInfo personInfo = convPersonInfo(person,syncId,photoData); + personInfoList.add(personInfo); + } + + + outterLoop : for (Long deviceId : deviceIds) { + Device device = deviceSupportService.selectById(deviceId); + // 批量下发(单次最多6个,分多次下发) + int batchSize = FaceSyncConst.UPLOAD_MAX_PERSON; + int batchNum = (int)Math.ceil((double)personInfoList.size()/batchSize); + for (int i = 0; i < batchNum; i++) { + int fromIndex = i * batchSize; + int toIndex = (i+1) * batchSize <= personInfoList.size() ? (i+1) * batchSize : personInfoList.size(); + List subPersonInfoList = personInfoList.subList(fromIndex,toIndex); + + // 设置上传body对象 + Gson gson = new GsonBuilder().serializeNulls().create(); + JsonObject body = new JsonObject(); + JsonElement person = gson.toJsonTree(subPersonInfoList); + body.addProperty("Num",subPersonInfoList.size()); + body.add("PersonInfoList",person); + String bodyStr = gson.toJson(body); +// logger.info(String.valueOf(subPersonInfoList.size())); + logger.info(bodyStr); + +// 调用接口上传 + String devIp = device.getDevIp(); + String personLib = null; + if("1".equals(personType)){ + personLib = FaceSyncConst.UPLOAD_STAFF_LIB; + }else { + personLib = FaceSyncConst.UPLOAD_VISITOR_LIB; + } + + String url = "http://".concat(devIp).concat(FaceSyncConst.UPLOAD_URL_PREFIX).concat(personLib).concat(FaceSyncConst.UPLOAD_URL_SUFFIX); + String responseContent = HttpClientUtil.sendHttpPost(url,bodyStr); + logger.info(responseContent); + JsonObject obj = gson.fromJson(responseContent, JsonObject.class); + // 解析返回结果 + FaceBaseResponse> response = gson.fromJson(obj.get("Response"),FaceBaseResponse.class); + if(response.getResponseCode() == 0 && response.getStatusCode() == 0){ + PersonResponseData personResponseData = gson.fromJson(gson.toJson(response.getData()),PersonResponseData.class); + List responseInfos = personResponseData.getPersonList(); + for(int j = 0;j < responseInfos.size();j++){ + PersonResponseInfo personResponseInfo = gson.fromJson(gson.toJson(responseInfos.get(j)),PersonResponseInfo.class);; + if(personResponseInfo.getFaceList().get(0).getResultCode() == 0){ + // 成功 + logger.info(String.format("人脸数据下发成功,人员:%s,设备: %s",personResponseInfo.getPersonId(),device.getDevCode())); + }else{ + error = convErrorCode(personResponseInfo.getFaceList().get(0).getResultCode()); + String personName = commonPersonService.getPersonById(personIds.get(i)).getName(); + error = String.format("下发失败,%s %s",personName,error); + logger.error(error); + break outterLoop; + } + } + }else { + if(response.getResponseCode() != 0 ){ + error = String.format("设备%s下发失败: %s",device.getDevCode(),response.getResponseString()); + logger.error(error); + break; + } + if(response.getStatusCode() != 0){ + error = String.format("设备%s下发失败: %s",device.getDevCode(),response.getStatusString()); + logger.error(error); + break; + } + } + } + } + }catch (Exception e){ + e.printStackTrace(); + logger.error(e.getMessage()); + error = "下发失败"; + } + + return error; + } + + private void updatePersonInfoList(List personInfoList,List personIds){ + for (int i = 0; i < personIds.size(); i++) { + Long syncId = personSyncService.selectSyncId(personIds.get(i)); + if(ToolUtil.isNotEmpty(syncId)){ + PersonInfo personInfo = personInfoList.get(i); + personInfo.setPersonID(syncId); + if(ToolUtil.isNotEmpty(personInfo.getImageList())){ + personInfo.getImageList().get(i).setFaceID(syncId); + } + } + } + } + + private Long getPersonSyncId(Long personId){ + Long syncId = personSyncService.selectSyncId(personId); + if(ToolUtil.isEmpty(syncId)){ + syncId = personSyncService.getMaxSyncId(personId); + } + return syncId; + } + + private PersonInfo convPersonInfo(Person person,Long syncId,String photoData){ + PersonInfo personInfo = new PersonInfo(); + if(ToolUtil.isNotEmpty(syncId)){ + personInfo.setPersonID(syncId); + } + if(ToolUtil.isNotEmpty(person.getUpdatetime())){ + personInfo.setLastChange(person.getUpdatetime().getTime()); + } + if(ToolUtil.isNotEmpty(person.getPersonCode()) && person.getPersonCode().length() <= FaceSyncConst.UPLOAD_PERSONCODE_MAXLENGTH){ + personInfo.setPersonCode(person.getPersonCode()); + }else { + personInfo.setPersonCode(String.valueOf(syncId)); + } + if(ToolUtil.isNotEmpty(person.getName())){ + personInfo.setPersonName(person.getName()); + } + if(ToolUtil.isNotEmpty(person.getRemarks()) && person.getRemarks().length() <= FaceSyncConst.UPLOAD_REMARK_MAXLENGTH){ + personInfo.setRemarks(person.getRemarks()); + }else { + personInfo.setRemarks(""); + } + + // 时间模板 + personInfo.setTimeTemplateNum(0); + List timeTemplateList = new ArrayList<>(); + timeTemplateList.add(personInfo.createTimeTemplate(0L,4294967295L,0L)); + personInfo.setTimeTemplateList(timeTemplateList); + + // 证件列表 + if(ToolUtil.isNotEmpty(person.getIdCardNo())){ + personInfo.setIdentificationNum(1); + List identificationInfoList = new ArrayList<>(); + identificationInfoList.add(personInfo.createIdentificationInfo(1,person.getIdCardNo())); + personInfo.setIdentificationList(identificationInfoList); + }else{ + personInfo.setIdentificationNum(0); + } + + // 图片列表 + if(ToolUtil.isNotEmpty(photoData)){ + personInfo.setImageNum(1); + List imageInfoList = new ArrayList<>(); + // 图片base64码 + if(photoData.startsWith("data") || photoData.startsWith("base64")){ + int splitIndex = photoData.indexOf(","); + photoData = photoData.substring(splitIndex+1); + } + imageInfoList.add(personInfo.createImageInfo(syncId,person.getPhoto(),Long.valueOf(photoData.length()),photoData)); + personInfo.setImageList(imageInfoList); + }else { + personInfo.setImageNum(0); + } + return personInfo; + } + + private String convErrorCode(Long errorCode){ + String errorMsg = ""; + switch (errorCode.intValue()){ + case 1000: + errorMsg = "算法初始化失败"; + break; + case 1001: + errorMsg = "人脸检测失败"; + break; + case 1002: + errorMsg = "图片未检测到人脸"; + break; + case 1003: + errorMsg = "jpeg照片解码失败"; + break; + case 1004: + errorMsg = "图片质量分数不满足"; + break; + case 1005: + errorMsg = "图片缩放失败"; + break; + case 1006: + errorMsg = "未启用智能"; + break; + case 1007: + errorMsg = "导入图片过小"; + break; + case 1008: + errorMsg = "导入图片过大"; + break; + case 1009: + errorMsg = "导入图片分辨率超过1920*1080"; + break; + case 1010: + errorMsg = "导入图片不存在"; + break; + case 1011: + errorMsg = "人脸元素个数已达到上限"; + break; + case 1012: + errorMsg = "智能棒算法模型不匹配"; + break; + case 1013: + errorMsg = "人脸导入库成员证件号非法"; + break; + case 1014: + errorMsg = "人脸导入库成员图片格式错误"; + break; + case 1015: + errorMsg = "通道布控已达设备能力上限"; + break; + case 1016: + errorMsg = "其它客户端正在进行操作人脸库"; + break; + case 1017: + errorMsg = "人脸库文件正在更新中"; + break; + case 1018: + errorMsg = "Json反序列化失败"; + break; + case 1019: + errorMsg = "Base64解码失败"; + break; + case 1020: + errorMsg = "人脸照片,编码后的大小和实际接收到的长度不一致,关注Data和Size大小是否正确"; + break; + default: + break; + } + return errorMsg; + + } + + @Override + public String checkPersonPhoto(List personIds) { + String error = null; + for (Long personId : personIds) { + Person person = commonPersonService.getPersonById(personId); + String photoData = photoSupportService.selectPhotoDataById(personId); + if(ToolUtil.isEmpty(photoData)){ + error = String.format("%s 未上传照片",person.getName()); + break; + } + if(photoData.startsWith("data") || photoData.startsWith("base64")){ + int splitIndex = photoData.indexOf(","); + photoData = photoData.substring(splitIndex+1); + } + if(!photoData.startsWith("/9j")){ + error = String.format("%s人员照片不符合要求,必须为jpg格式",person.getName()); + break; + } + + // 找到等号,把等号也去掉 + int equalIndex = photoData.indexOf('='); + if(equalIndex>=0) { + photoData=photoData.substring(0, equalIndex); + } + // 原来的字符流大小,单位为字节 + int strLength=photoData.length(); + // 计算后得到的文件流大小,单位为字节 + int fileLength=Integer.valueOf(strLength-(strLength/8)*2); + if(fileLength / 1024 < 20){ + error = String.format("%s人员照片不符合要求,照片必须大于20Kb",person.getName()); + break; + } + } + return error; + } + + @Override + public void receiveRecord(RecordNotification recordNotification){ +// if(recordNotification.getFaceInfoNum() != recordNotification.getLibMatInfoNum()){ +// logger.error("采集和匹配数据不一致,识别失败"); +// } else { + String deviceCode = recordNotification.getDeviceCode(); + List recordsList = new ArrayList<>(); + for (int i = 0; i < recordNotification.getLibMatInfoNum(); i++) { + //FaceInfo faceInfo = recordNotification.getFaceInfoList().get(i); + LibMatInfo libMatInfo = recordNotification.getLibMatInfoList().get(i); + if(libMatInfo.getMatchStatus() == 1){ + FaceInfo faceInfo = getFaceInfoByMatchId(recordNotification.getFaceInfoList(),libMatInfo.getId()); + Long personId = personSyncService.selectPersonId(libMatInfo.getMatchPersonId()); + if(ToolUtil.isNotEmpty(personId) && ToolUtil.isNotEmpty(faceInfo)){ + RecognitionRecords record = new RecognitionRecords(); + record.setPersonId(personId); + record.setDatetime(new Date(faceInfo.getTimestamp()*1000)); + record.setDevCode(deviceCode); + if(ToolUtil.isNotEmpty(faceInfo.getTemperature())){ + record.setTemperature(String.valueOf(faceInfo.getTemperature())); + } + record.setOriginalId(libMatInfo.getId()); + record.setSyncTime(new Date()); + + Device device = deviceSupportService.selectDeviceByCode(deviceCode); + if(ToolUtil.isNotEmpty(device)){ + if(ToolUtil.isNotEmpty(device.getDevIp())){ + record.setDevIp(device.getDevIp()); + } + } + + recordsList.add(record); + } + } + } + if(ToolUtil.isNotEmpty(recordsList)){ + recordSupportService.insertBatch(recordsList); + } + } + + @Override + public void receiveRecord(String recordNotificationStr) { + RecordNotification recordNotification = JSONObject.parseObject(recordNotificationStr,RecordNotification.class); + receiveRecord(recordNotification); + } + + public FaceInfo getFaceInfoByMatchId(List faceInfoList ,Long id){ + for (FaceInfo faceInfo : faceInfoList) { + if(faceInfo.getId().equals(id)){ + return faceInfo; + } + } + return null; + } + + @Override + public String initSubscription(List deviceIds) { + try { + List error = new ArrayList<>(); + for (Long deviceId : deviceIds) { + Device device = deviceSupportService.selectById(deviceId); + List subscribeIds = subscribeService.selectSubscribeIdsByDevCode(device.getDevCode());; + // 删除所有id + boolean flag = true; + for (Long subscribeId : subscribeIds) { + flag = flag && deleteSubscription(device.getDevIp(),subscribeId); + } + flag = flag && subscribeService.deleteByDevCode(device.getDevCode()); + // 创建订阅 + Long subscribeId = createSubscription(device.getDevIp(),serverHost,serverPort); + flag = flag && ToolUtil.isNotEmpty(subscribeId); + if(ToolUtil.isNotEmpty(subscribeId)){ + flag = flag && subscribeService.insertSubscribe(subscribeId,device.getDevCode()); + } + if(!flag){ + logger.error(String.format("device %s init subsrciption error",device.getDevCode())); + error.add(device.getDevCode()); + } + } + if(ToolUtil.isNotEmpty(error)){ + return StringUtils.join(error,",").concat("订阅失败"); + }else { + return null; + } + }catch (Exception e){ + e.printStackTrace(); + logger.error(e.getMessage()); + return "订阅失败"; + } + + } + + @Override + public boolean deleteSubscription(String deviceIp, Long subscribeId) { + String url = "http://" + deviceIp + FaceSyncConst.SUBSCRIBE_URL + subscribeId; + String responseContent = HttpClientUtil.sendHttpDelete(url); + logger.info(responseContent); + Gson gson = new Gson(); + JsonObject obj = gson.fromJson(responseContent, JsonObject.class); + logger.info(obj.get("Response").toString()); + FaceBaseResponse response = gson.fromJson(obj.get("Response"),FaceBaseResponse.class); + if(response.getResponseCode() == 0 && response.getStatusCode() == 0){ + return true; + }else { + logger.error(String.format("delele subscribe error, device '%s', subscribeId '%s', response '%s', status '%s'",deviceIp,subscribeId,response.getResponseString(),response.getStatusString())); + return false; + } + } + + @Override + public Long createSubscription(String deviceIp, String ip, String port) { + JsonObject request = new JsonObject(); + request.addProperty("AddressType",0); + request.addProperty("IPAddress",ip); + request.addProperty("Port",Long.valueOf(port)); + request.addProperty("Duration",4294967295L); + request.addProperty("Type",1024); + JsonObject subscribePersonCondition = new JsonObject(); + subscribePersonCondition.addProperty("LibIDNum",65535); + subscribePersonCondition.add("LibIDList",new JsonArray()); + request.add("SubscribePersonCondition",subscribePersonCondition); + Gson gson = new Gson(); + String requestStr = gson.toJson(request); + System.out.println(requestStr); + String url = "http://" + deviceIp + FaceSyncConst.SUBSCRIBE_URL ; + String responseContent = HttpClientUtil.sendHttpPostJson(url,requestStr); + logger.info(responseContent); + JsonObject obj = gson.fromJson(responseContent, JsonObject.class); + FaceBaseResponse response = gson.fromJson(obj.get("Response"),FaceBaseResponse.class); + if(response.getResponseCode() == 0 && response.getStatusCode()==0){ + JsonObject data = gson.fromJson(gson.toJson(response.getData()),JsonObject.class); + Long subsrcibeId = data.get("ID").getAsLong(); + logger.info(String.format("create subscribe success, device '%s', subsrcibeId '%s'",deviceIp,subsrcibeId)); + return subsrcibeId; + }else { + logger.error(String.format("create subscribe error, device '%s', response '%s', status '%s'",deviceIp,response.getResponseString(),response.getStatusString())); + return null; + } + } + +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/util/HttpClientUtil.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/util/HttpClientUtil.java new file mode 100644 index 0000000..e258174 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/util/HttpClientUtil.java @@ -0,0 +1,468 @@ +package com.casic.missiles.modular.system.util; + +import java.io.File; +import java.io.IOException; +import java.security.KeyManagementException; +import java.security.KeyStoreException; +import java.security.NoSuchAlgorithmException; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.apache.http.HttpEntity; +import org.apache.http.HttpStatus; +import org.apache.http.client.config.RequestConfig; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpDelete; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.config.Registry; +import org.apache.http.config.RegistryBuilder; +import org.apache.http.conn.socket.ConnectionSocketFactory; +import org.apache.http.conn.socket.PlainConnectionSocketFactory; +import org.apache.http.conn.ssl.SSLConnectionSocketFactory; +import org.apache.http.conn.ssl.SSLContextBuilder; +import org.apache.http.conn.ssl.TrustSelfSignedStrategy; +import org.apache.http.entity.ContentType; +import org.apache.http.entity.StringEntity; +import org.apache.http.entity.mime.MultipartEntityBuilder; +import org.apache.http.entity.mime.content.FileBody; +import org.apache.http.entity.mime.content.StringBody; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.DefaultHttpRequestRetryHandler; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; +import org.apache.http.util.EntityUtils; + +/** + * + * @author H__D + * @date 2016年10月19日 上午11:27:25 + * + */ +public class HttpClientUtil { + + // utf-8字符编码 + public static final String CHARSET_UTF_8 = "utf-8"; + + // HTTP内容类型。 + public static final String CONTENT_TYPE_TEXT_HTML = "text/xml"; + + // HTTP内容类型。相当于form表单的形式,提交数据 + public static final String CONTENT_TYPE_FORM_URL = "application/x-www-form-urlencoded"; + + // HTTP内容类型。相当于form表单的形式,提交数据 + public static final String CONTENT_TYPE_JSON_URL = "application/json;charset=utf-8"; + + + // 连接管理器 + private static PoolingHttpClientConnectionManager pool; + + // 请求配置 + private static RequestConfig requestConfig; + + static { + + try { + //System.out.println("初始化HttpClientTest~~~开始"); + SSLContextBuilder builder = new SSLContextBuilder(); + builder.loadTrustMaterial(null, new TrustSelfSignedStrategy()); + SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory( + builder.build()); + // 配置同时支持 HTTP 和 HTPPS + Registry socketFactoryRegistry = RegistryBuilder. create().register( + "http", PlainConnectionSocketFactory.getSocketFactory()).register( + "https", sslsf).build(); + // 初始化连接管理器 + pool = new PoolingHttpClientConnectionManager( + socketFactoryRegistry); + // 将最大连接数增加到200,实际项目最好从配置文件中读取这个值 + pool.setMaxTotal(200); + // 设置最大路由 + pool.setDefaultMaxPerRoute(2); + // 根据默认超时限制初始化requestConfig + int socketTimeout = 10000; + int connectTimeout = 10000; + int connectionRequestTimeout = 10000; + requestConfig = RequestConfig.custom().setConnectionRequestTimeout( + connectionRequestTimeout).setSocketTimeout(socketTimeout).setConnectTimeout( + connectTimeout).build(); + + //System.out.println("初始化HttpClientTest~~~结束"); + } catch (NoSuchAlgorithmException e) { + e.printStackTrace(); + } catch (KeyStoreException e) { + e.printStackTrace(); + } catch (KeyManagementException e) { + e.printStackTrace(); + } + + + // 设置请求超时时间 + requestConfig = RequestConfig.custom().setSocketTimeout(50000).setConnectTimeout(50000) + .setConnectionRequestTimeout(50000).build(); + } + + public static CloseableHttpClient getHttpClient() { + + CloseableHttpClient httpClient = HttpClients.custom() + // 设置连接池管理 + .setConnectionManager(pool) + // 设置请求配置 + .setDefaultRequestConfig(requestConfig) + // 设置重试次数 + .setRetryHandler(new DefaultHttpRequestRetryHandler(0, false)) + .build(); + + return httpClient; + } + + /** + * 发送Post请求 + * + * @param httpPost + * @return + */ + private static String sendHttpPost(HttpPost httpPost) { + + CloseableHttpClient httpClient = null; + CloseableHttpResponse response = null; + // 响应内容 + String responseContent = null; + try { + // 创建默认的httpClient实例. + httpClient = getHttpClient(); + // 配置请求信息 + httpPost.setConfig(requestConfig); + // 执行请求 + response = httpClient.execute(httpPost); + // 得到响应实例 + HttpEntity entity = response.getEntity(); + + // 可以获得响应头 + // Header[] headers = response.getHeaders(HttpHeaders.CONTENT_TYPE); + // for (Header header : headers) { + // System.out.println(header.getName()); + // } + + // 得到响应类型 + // System.out.println(ContentType.getOrDefault(response.getEntity()).getMimeType()); + + // 判断响应状态 + if (response.getStatusLine().getStatusCode() >= 300) { + throw new Exception( + "HTTP Request is not success, Response code is " + response.getStatusLine().getStatusCode()); + } + + if (HttpStatus.SC_OK == response.getStatusLine().getStatusCode()) { + responseContent = EntityUtils.toString(entity, CHARSET_UTF_8); + EntityUtils.consume(entity); + } + + } catch (Exception e) { + e.printStackTrace(); + } finally { + try { + // 释放资源 + if (response != null) { + response.close(); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + return responseContent; + } + + /** + * 发送Get请求 + * + * @param httpGet + * @return + */ + private static String sendHttpGet(HttpGet httpGet) { + + CloseableHttpClient httpClient = null; + CloseableHttpResponse response = null; + // 响应内容 + String responseContent = null; + try { + // 创建默认的httpClient实例. + httpClient = getHttpClient(); + // 配置请求信息 + httpGet.setConfig(requestConfig); + // 执行请求 + response = httpClient.execute(httpGet); + // 得到响应实例 + HttpEntity entity = response.getEntity(); + + // 可以获得响应头 + // Header[] headers = response.getHeaders(HttpHeaders.CONTENT_TYPE); + // for (Header header : headers) { + // System.out.println(header.getName()); + // } + + // 得到响应类型 + // System.out.println(ContentType.getOrDefault(response.getEntity()).getMimeType()); + + // 判断响应状态 + if (response.getStatusLine().getStatusCode() >= 300) { + throw new Exception( + "HTTP Request is not success, Response code is " + response.getStatusLine().getStatusCode()); + } + + if (HttpStatus.SC_OK == response.getStatusLine().getStatusCode()) { + responseContent = EntityUtils.toString(entity, CHARSET_UTF_8); + EntityUtils.consume(entity); + } + + } catch (Exception e) { + e.printStackTrace(); + } finally { + try { + // 释放资源 + if (response != null) { + response.close(); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + return responseContent; + } + + /** + * 发送Delete请求 + * + * @param httpDelete + * @return + */ + private static String sendHttpDelete(HttpDelete httpDelete) { + + CloseableHttpClient httpClient = null; + CloseableHttpResponse response = null; + // 响应内容 + String responseContent = null; + try { + // 创建默认的httpClient实例. + httpClient = getHttpClient(); + // 配置请求信息 + httpDelete.setConfig(requestConfig); + // 执行请求 + response = httpClient.execute(httpDelete); + // 得到响应实例 + HttpEntity entity = response.getEntity(); + + // 可以获得响应头 + // Header[] headers = response.getHeaders(HttpHeaders.CONTENT_TYPE); + // for (Header header : headers) { + // System.out.println(header.getName()); + // } + + // 得到响应类型 + // System.out.println(ContentType.getOrDefault(response.getEntity()).getMimeType()); + + // 判断响应状态 + if (response.getStatusLine().getStatusCode() >= 300) { + throw new Exception( + "HTTP Request is not success, Response code is " + response.getStatusLine().getStatusCode()); + } + + if (HttpStatus.SC_OK == response.getStatusLine().getStatusCode()) { + responseContent = EntityUtils.toString(entity, CHARSET_UTF_8); + EntityUtils.consume(entity); + } + + } catch (Exception e) { + e.printStackTrace(); + } finally { + try { + // 释放资源 + if (response != null) { + response.close(); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + return responseContent; + } + + + + /** + * 发送 post请求 + * + * @param httpUrl 地址 + */ + public static String sendHttpPost(String httpUrl) { + // 创建httpPost + HttpPost httpPost = new HttpPost(httpUrl); + return sendHttpPost(httpPost); + } + + /** + * 发送 get请求 + * + * @param httpUrl + */ + public static String sendHttpGet(String httpUrl) { + // 创建get请求 + HttpGet httpGet = new HttpGet(httpUrl); + return sendHttpGet(httpGet); + } + + /** + * 发送 DELETE 请求 + * + * @param httpUrl + */ + public static String sendHttpDelete(String httpUrl) { + // 创建delete请求 + HttpDelete httpDelete = new HttpDelete(httpUrl); + return sendHttpDelete(httpDelete); + } + + + + /** + * 发送 post请求(带文件) + * + * @param httpUrl + * 地址 + * @param maps + * 参数 + * @param fileLists + * 附件 + */ + public static String sendHttpPost(String httpUrl, Map maps, List fileLists) { + HttpPost httpPost = new HttpPost(httpUrl);// 创建httpPost + MultipartEntityBuilder meBuilder = MultipartEntityBuilder.create(); + if (maps != null) { + for (String key : maps.keySet()) { + meBuilder.addPart(key, new StringBody(maps.get(key), ContentType.TEXT_PLAIN)); + } + } + if (fileLists != null) { + for (File file : fileLists) { + FileBody fileBody = new FileBody(file); + meBuilder.addPart("files", fileBody); + } + } + HttpEntity reqEntity = meBuilder.build(); + httpPost.setEntity(reqEntity); + return sendHttpPost(httpPost); + } + + /** + * 发送 post请求 + * + * @param httpUrl + * 地址 + * @param params + * 参数(格式:key1=value1&key2=value2) + * + */ + public static String sendHttpPost(String httpUrl, String params) { + HttpPost httpPost = new HttpPost(httpUrl);// 创建httpPost + try { + // 设置参数 + if (params != null && params.trim().length() > 0) { + StringEntity stringEntity = new StringEntity(params, "UTF-8"); + stringEntity.setContentType(CONTENT_TYPE_FORM_URL); + httpPost.setEntity(stringEntity); + } + } catch (Exception e) { + throw e; + } + return sendHttpPost(httpPost); + } + + /** + * 发送 post请求 + * + * @param maps + * 参数 + */ + public static String sendHttpPost(String httpUrl, Map maps) { + String parem = convertStringParamter(maps); + return sendHttpPost(httpUrl, parem); + } + + + + + /** + * 发送 post请求 发送json数据 + * + * @param httpUrl 地址 + * @param paramsJson 参数(格式 json) + * + */ + public static String sendHttpPostJson(String httpUrl, String paramsJson) { + HttpPost httpPost = new HttpPost(httpUrl);// 创建httpPost + try { + // 设置参数 + if (paramsJson != null && paramsJson.trim().length() > 0) { + StringEntity stringEntity = new StringEntity(paramsJson, "UTF-8"); + stringEntity.setContentType(CONTENT_TYPE_JSON_URL); + httpPost.setEntity(stringEntity); + } + } catch (Exception e) { + e.printStackTrace(); + } + return sendHttpPost(httpPost); + } + + /** + * 发送 post请求 发送xml数据 + * + * @param httpUrl 地址 + * @param paramsXml 参数(格式 Xml) + * + */ + public static String sendHttpPostXml(String httpUrl, String paramsXml) { + HttpPost httpPost = new HttpPost(httpUrl);// 创建httpPost + try { + // 设置参数 + if (paramsXml != null && paramsXml.trim().length() > 0) { + StringEntity stringEntity = new StringEntity(paramsXml, "UTF-8"); + stringEntity.setContentType(CONTENT_TYPE_TEXT_HTML); + httpPost.setEntity(stringEntity); + } + } catch (Exception e) { + e.printStackTrace(); + } + return sendHttpPost(httpPost); + } + + + /** + * 将map集合的键值对转化成:key1=value1&key2=value2 的形式 + * + * @param parameterMap 需要转化的键值对集合 + * @return 字符串 + */ + public static String convertStringParamter(Map parameterMap) { + StringBuffer parameterBuffer = new StringBuffer(); + if (parameterMap != null) { + Iterator iterator = parameterMap.keySet().iterator(); + String key = null; + String value = null; + while (iterator.hasNext()) { + key = (String) iterator.next(); + if (parameterMap.get(key) != null) { + value = (String) parameterMap.get(key); + } else { + value = ""; + } + parameterBuffer.append(key).append("=").append(value); + if (iterator.hasNext()) { + parameterBuffer.append("&"); + } + } + } + return parameterBuffer.toString(); + } + +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/util/ImageUtil.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/util/ImageUtil.java new file mode 100644 index 0000000..4586ad1 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/util/ImageUtil.java @@ -0,0 +1,30 @@ +package com.casic.missiles.modular.system.util; + +import javax.imageio.ImageIO; +import java.awt.*; +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.IOException; + +public class ImageUtil { + public static void main(String[] args) { + BufferedImage bufferedImage; + try { + // read image file + bufferedImage = ImageIO.read(new File("C:\\Users\\zhang\\Desktop\\test.png")); + // create a blank, RGB, same width and height, and a white + // background + BufferedImage newBufferedImage = new BufferedImage( + bufferedImage.getWidth(), bufferedImage.getHeight(), + BufferedImage.TYPE_INT_RGB); + // TYPE_INT_RGB:创建一个RBG图像,24位深度,成功将32位图转化成24位 + newBufferedImage.createGraphics().drawImage(bufferedImage, 0, 0, + Color.WHITE, null); + // write to jpeg file + ImageIO.write(newBufferedImage, "jpg", new File("C:\\Users\\zhang\\Desktop\\test.jpg")); + System.out.println("Done"); + } catch (IOException e) { + e.printStackTrace(); + } + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/util/LocalHostUtil.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/util/LocalHostUtil.java new file mode 100644 index 0000000..1f6c639 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/util/LocalHostUtil.java @@ -0,0 +1,111 @@ +package com.casic.missiles.modular.system.util; + +import java.net.InetAddress; +import java.net.NetworkInterface; +import java.net.SocketException; +import java.net.UnknownHostException; +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.List; + +/** + * 本地主机工具类 + * + * @author zhi + * @since 2019年11月13日09:04:36 + * + */ +public class LocalHostUtil { + + /** + * 获取主机名称 + * + * @return + * @throws UnknownHostException + */ + public static String getHostName() throws UnknownHostException { + return InetAddress.getLocalHost().getHostName(); + } + + /** + * 获取系统首选IP + * + * @return + * @throws UnknownHostException + */ + public static String getLocalIP() throws UnknownHostException { + return InetAddress.getLocalHost().getHostAddress(); + } + + /** + * 获取所有网卡IP,排除回文地址、虚拟地址 + * + * @return + * @throws SocketException + */ + public static String[] getLocalIPs() throws SocketException { + List list = new ArrayList<>(); + Enumeration enumeration = NetworkInterface.getNetworkInterfaces(); + while (enumeration.hasMoreElements()) { + NetworkInterface intf = enumeration.nextElement(); + if (intf.isLoopback() || intf.isVirtual()) { // + continue; + } + Enumeration inets = intf.getInetAddresses(); + while (inets.hasMoreElements()) { + InetAddress addr = inets.nextElement(); + if (addr.isLoopbackAddress() || !addr.isSiteLocalAddress() || addr.isAnyLocalAddress()) { + continue; + } + list.add(addr.getHostAddress()); + } + } + return list.toArray(new String[0]); + } + + /** + * 判断操作系统是否是Windows + * + * @return + */ + public static boolean isWindowsOS() { + boolean isWindowsOS = false; + String osName = System.getProperty("os.name"); + if (osName.toLowerCase().indexOf("windows") > -1) { + isWindowsOS = true; + } + return isWindowsOS; + } + + public static void main(String[] args) { +// try { +// System.out.println("主机是否为Windows系统:" + LocalHostUtil.isWindowsOS()); +// System.out.println("主机名称:" + LocalHostUtil.getHostName()); +// System.out.println("系统首选IP:" + LocalHostUtil.getLocalIP()); +// System.out.println("系统所有IP:" + String.join(",", LocalHostUtil.getLocalIPs())); +// } catch (UnknownHostException e) { +// } catch (Exception e) { +// e.printStackTrace(); +// } + try { + Enumeration faces = NetworkInterface.getNetworkInterfaces(); + while (faces.hasMoreElements()) { // 遍历网络接口 + NetworkInterface face = faces.nextElement(); + if (face.isLoopback() || face.isVirtual() || !face.isUp()) { + continue; + } + System.out.print("网络接口名:" + face.getDisplayName() + ",地址:"); + Enumeration address = face.getInetAddresses(); + while (address.hasMoreElements()) { // 遍历网络地址 + InetAddress addr = address.nextElement(); + if (!addr.isLoopbackAddress() && addr.isSiteLocalAddress() && !addr.isAnyLocalAddress()) { + System.out.print(addr.getHostAddress() + " "); + } + } + System.out.println(""); + } + } catch (SocketException e) { + e.printStackTrace(); + } + } +} diff --git a/casic-iris-register/src/main/java/com/casic/missiles/modular/register/dao/mapping/IrisPersonMapper.xml b/casic-iris-register/src/main/java/com/casic/missiles/modular/register/dao/mapping/IrisPersonMapper.xml new file mode 100644 index 0000000..c974147 --- /dev/null +++ b/casic-iris-register/src/main/java/com/casic/missiles/modular/register/dao/mapping/IrisPersonMapper.xml @@ -0,0 +1,20 @@ + + + + + + + diff --git a/casic-iris-support/src/main/java/com/casic/missiles/modular/system/model/RecognitionRecords.java b/casic-iris-support/src/main/java/com/casic/missiles/modular/system/model/RecognitionRecords.java new file mode 100644 index 0000000..3729383 --- /dev/null +++ b/casic-iris-support/src/main/java/com/casic/missiles/modular/system/model/RecognitionRecords.java @@ -0,0 +1,93 @@ +package com.casic.missiles.modular.system.model; + +import com.baomidou.mybatisplus.activerecord.Model; +import com.baomidou.mybatisplus.annotations.TableField; +import com.baomidou.mybatisplus.annotations.TableId; +import com.baomidou.mybatisplus.annotations.TableName; +import com.baomidou.mybatisplus.enums.IdType; +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +/** + *

+ * + *

+ * + * @author 123 + * @since 2019-12-02 + */ +@Data +@TableName("recognition_records") +public class RecognitionRecords extends Model { + + private static final long serialVersionUID = 1L; + + /** + * 主键 + */ + @TableId(value = "ID", type = IdType.AUTO) + private Long id; + /** + * 原始记录id + */ + @TableField("ORIGINAL_ID") + private Long originalId; + /** + * 对应person表主键 + */ + @TableField("PERSON_ID") + private Long personId; + /** + * 识别时间 + */ + @TableField("DATETIME") + private Date datetime; + /** + * 设备业务编码 + */ + @TableField("DEV_CODE") + private String devCode; + + /** + * 门编码 + */ + @TableField("DOOR_CODE") + private String doorCode; + + /** + * 进出标记 + */ + @TableField("INOUT_TYPE") + private String inoutType; + + @TableField("TEMPERATURE") + private String temperature; + + @TableField("DEV_IP") + private String devIp; + + @TableField("SYNC_TIME") + private Date syncTime; + + @Override + protected Serializable pkVal() { + return this.id; + } + + @Override + public String toString() { + return "RecognitionRecords{" + + "id=" + id + + ", originalId=" + originalId + + ", personId=" + personId + + ", datetime=" + datetime + + ", devCode=" + devCode + + ", doorCode=" + doorCode + + ", inoutType=" + inoutType + + ", devIp=" + devIp + + ", syncTime=" + syncTime + + "}"; + } +} diff --git a/casic-face-sync/pom.xml b/casic-face-sync/pom.xml new file mode 100644 index 0000000..24dc884 --- /dev/null +++ b/casic-face-sync/pom.xml @@ -0,0 +1,74 @@ + + + 4.0.0 + + com.casic + casic-iris-parent + 1.0.0-SNAPSHOT + ../pom.xml + + + + casic-face-sync + ${pro.version} + jar + casic-face-sync + + + + + + com.casic + casic-core + ${core.version} + + + + com.casic + casic-admin-support + ${admin.version} + + + com.casic + casic-iris-support + ${pro.version} + + + + org.apache.httpcomponents + httpclient + 4.5.3 + + + + org.apache.httpcomponents + httpcore + 4.4.8 + + + + org.apache.httpcomponents + httpmime + 4.5.3 + + + + com.google.code.gson + gson + + + + + + + + src/main/java + + **/*.xml + + + + + \ No newline at end of file diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/constant/FaceSyncConst.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/constant/FaceSyncConst.java new file mode 100644 index 0000000..352d47d --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/constant/FaceSyncConst.java @@ -0,0 +1,29 @@ +package com.casic.missiles.modular.system.constant; + +public class FaceSyncConst { + + /** + * 单次最大批量上传人员数 + */ + public static final int UPLOAD_MAX_PERSON = 6; + + /** + * 上传人员库 + */ + public static final String UPLOAD_STAFF_LIB = "3"; + public static final String UPLOAD_VISITOR_LIB = "4"; + + public static final String UPLOAD_URL_PREFIX = "/LAPI/V1.0/PeopleLibraries/"; + + public static final String UPLOAD_URL_SUFFIX = "/People"; + + public static final int UPLOAD_PERSONCODE_MAXLENGTH = 15; + + public static final int UPLOAD_REMARK_MAXLENGTH = 63; + + public static final String SUBSCRIBE_URL = "/LAPI/V1.0/System/Event/Subscription/"; + + public static final String STAFF_PERSON_TYPE = "1"; + + public static final String VISITOR_PERSON_TYPE = "0"; +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/controller/FaceSyncController.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/controller/FaceSyncController.java new file mode 100644 index 0000000..1b35431 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/controller/FaceSyncController.java @@ -0,0 +1,117 @@ +package com.casic.missiles.modular.system.controller; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson.serializer.SerializerFeature; +import com.casic.missiles.core.base.response.ResponseData; +import com.casic.missiles.core.common.service.ICommonPermissionService; +import com.casic.missiles.core.common.service.ICommonPersonService; +import com.casic.missiles.core.datascope.DataScope; +import com.casic.missiles.core.util.ToolUtil; +import com.casic.missiles.modular.system.request.PersonInfo; +import com.casic.missiles.modular.system.response.RecordNotification; +import com.casic.missiles.modular.system.service.IFaceSyncService; +import com.casic.missiles.modular.system.service.IIrisPersonSupportService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.*; +import com.casic.missiles.modular.system.constant.FaceSyncConst; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + + + +@Controller +public class FaceSyncController { + private final static Logger logger = LoggerFactory.getLogger(FaceSyncController.class); + + @Autowired + private IFaceSyncService syncService; + @Autowired + private ICommonPersonService commonPersonService; + @Autowired + private IIrisPersonSupportService personSupportService; + @Autowired + private ICommonPermissionService permissionService; + + @RequestMapping("/face/upload") + @ResponseBody + public Object upload(@RequestParam("personIds") List personIds, + @RequestParam("deviceIds") List deviceIds, + @RequestParam("personType")String personType ){ + // 检查数量 +// if(personIds.size()>FaceSyncConst.UPLOAD_MAX_PERSON){ +// return ResponseData.error(String.format("每次最多上传%s个人",FaceSyncConst.UPLOAD_MAX_PERSON)); +// } + // 检查照片格式及大小 + String photoCheck = syncService.checkPersonPhoto(personIds); + if(ToolUtil.isNotEmpty(photoCheck)){ + return ResponseData.error(photoCheck); + } + else{ + // 上传数据 + String error = syncService.uploadPerson(personIds,deviceIds,personType); + if(ToolUtil.isNotEmpty(error)){ + return ResponseData.error(error); + } + } + return ResponseData.success(); + } + + @RequestMapping("/face/uploadAll") + @ResponseBody + public Object uploadAll(@RequestParam("deviceIds") List deviceIds){ + DataScope dataScope = permissionService.getCurrUserDataScope(); + + List staffPersonIds = personSupportService.listIdsByType(dataScope,FaceSyncConst.STAFF_PERSON_TYPE); + List visitorPersonIds = personSupportService.listIdsByType(dataScope,FaceSyncConst.VISITOR_PERSON_TYPE); + // 1.检查照片,分别检查员工、访客 + String staffPhotoCheck = syncService.checkPersonPhoto(staffPersonIds); + if(ToolUtil.isNotEmpty(staffPhotoCheck)){ + return ResponseData.error(staffPhotoCheck); + } + String visitorPhotoCheck = syncService.checkPersonPhoto(visitorPersonIds); + if(ToolUtil.isNotEmpty(visitorPhotoCheck)){ + return ResponseData.error(visitorPhotoCheck); + } + + // 2. 下发数据 + String staffError = syncService.uploadPerson(staffPersonIds,deviceIds,FaceSyncConst.STAFF_PERSON_TYPE); + if(ToolUtil.isNotEmpty(staffError)){ + return ResponseData.error(staffError); + } + String visitorError = syncService.uploadPerson(visitorPersonIds,deviceIds,FaceSyncConst.VISITOR_PERSON_TYPE); + if(ToolUtil.isNotEmpty(visitorError)){ + return ResponseData.error(visitorError); + } + + return ResponseData.success(); + } + + // 错误信息返回 + @RequestMapping("/subsrcibe/init") + @ResponseBody + public Object upload(@RequestParam("deviceIds") List deviceIds){ + String errorMsg = syncService.initSubscription(deviceIds); + if(ToolUtil.isNotEmpty(errorMsg)){ + return ResponseData.error(errorMsg); + } + return ResponseData.success(); + } + + + @RequestMapping(value = "/LAPI/V1.0/System/Event/Notification/PersonVerification", method = RequestMethod.POST) + @ResponseBody + public void verification(@RequestBody String recordNotification){ + logger.info(recordNotification); + RecordNotification record = JSONObject.parseObject(recordNotification,RecordNotification.class); + syncService.receiveRecord(record); + //return ResponseData.success(); + } + + +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FacePersonSyncMapper.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FacePersonSyncMapper.java new file mode 100644 index 0000000..af53702 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FacePersonSyncMapper.java @@ -0,0 +1,17 @@ +package com.casic.missiles.modular.system.dao; + +import com.casic.missiles.modular.system.model.FacePersonSync; +import com.baomidou.mybatisplus.mapper.BaseMapper; + +/** + *

+ * Mapper 接口 + *

+ * + * @author zyj123 + * @since 2020-07-24 + */ +public interface FacePersonSyncMapper extends BaseMapper { + + Long getMaxSyncId(); +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FaceSubscribeMapper.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FaceSubscribeMapper.java new file mode 100644 index 0000000..0c6374a --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FaceSubscribeMapper.java @@ -0,0 +1,16 @@ +package com.casic.missiles.modular.system.dao; + +import com.casic.missiles.modular.system.model.FaceSubscribe; +import com.baomidou.mybatisplus.mapper.BaseMapper; + +/** + *

+ * Mapper 接口 + *

+ * + * @author zyj123 + * @since 2020-07-25 + */ +public interface FaceSubscribeMapper extends BaseMapper { + +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FacePersonSyncMapper.xml b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FacePersonSyncMapper.xml new file mode 100644 index 0000000..ac46ad0 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FacePersonSyncMapper.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + PERSON_ID AS personId, SYNC_ID AS syncId + + + + + diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FaceSubscribeMapper.xml b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FaceSubscribeMapper.xml new file mode 100644 index 0000000..16024e2 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FaceSubscribeMapper.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + SUBSCRIBE_ID AS subscribeId, DEVICE_CODE AS deviceCode, UPDATE_TIME AS updateTime + + + diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FacePersonSync.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FacePersonSync.java new file mode 100644 index 0000000..7cdb821 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FacePersonSync.java @@ -0,0 +1,68 @@ +package com.casic.missiles.modular.system.model; + +import java.io.Serializable; + +import com.baomidou.mybatisplus.annotations.TableId; +import com.baomidou.mybatisplus.annotations.TableField; +import com.baomidou.mybatisplus.activerecord.Model; +import com.baomidou.mybatisplus.annotations.TableName; +import java.io.Serializable; + +/** + *

+ * + *

+ * + * @author zyj123 + * @since 2020-07-24 + */ +@TableName("face_person_sync") +public class FacePersonSync extends Model { + + private static final long serialVersionUID = 1L; + + /** + * 人员id + */ + @TableId("PERSON_ID") + private Long personId; + /** + * 人员同步id + */ + @TableField("SYNC_ID") + private Long syncId; + + public FacePersonSync(Long personId, Long syncId) { + this.personId = personId; + this.syncId = syncId; + } + + public Long getPersonId() { + return personId; + } + + public void setPersonId(Long personId) { + this.personId = personId; + } + + public Long getSyncId() { + return syncId; + } + + public void setSyncId(Long syncId) { + this.syncId = syncId; + } + + @Override + protected Serializable pkVal() { + return this.personId; + } + + @Override + public String toString() { + return "FacePersonSync{" + + "personId=" + personId + + ", syncId=" + syncId + + "}"; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FaceSubscribe.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FaceSubscribe.java new file mode 100644 index 0000000..ccc7792 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FaceSubscribe.java @@ -0,0 +1,79 @@ +package com.casic.missiles.modular.system.model; + +import java.io.Serializable; + +import java.util.Date; +import com.baomidou.mybatisplus.annotations.TableId; +import com.baomidou.mybatisplus.annotations.TableField; +import com.baomidou.mybatisplus.activerecord.Model; +import com.baomidou.mybatisplus.annotations.TableName; +import java.io.Serializable; + +/** + *

+ * + *

+ * + * @author zyj123 + * @since 2020-07-25 + */ +@TableName("face_subscribe") +public class FaceSubscribe extends Model { + + private static final long serialVersionUID = 1L; + + /** + * 订阅id + */ + @TableId("SUBSCRIBE_ID") + private Long subscribeId; + /** + * 设备编号 + */ + @TableField("DEVICE_CODE") + private String deviceCode; + /** + * 更新时间 + */ + @TableField("UPDATE_TIME") + private Date updateTime; + + + public Long getSubscribeId() { + return subscribeId; + } + + public void setSubscribeId(Long subscribeId) { + this.subscribeId = subscribeId; + } + + public String getDeviceCode() { + return deviceCode; + } + + public void setDeviceCode(String deviceCode) { + this.deviceCode = deviceCode; + } + + public Date getUpdateTime() { + return updateTime; + } + + public void setUpdateTime(Date updateTime) { + this.updateTime = updateTime; + } + + @Override + protected Serializable pkVal() { + return this.subscribeId; + } + + @Override + public String toString() { + return "FaceSubscribe{" + + "subscribeId=" + subscribeId + + ", deviceCode=" + deviceCode + + ", updateTime=" + updateTime + + "}"; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/request/PersonInfo.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/request/PersonInfo.java new file mode 100644 index 0000000..80d9eff --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/request/PersonInfo.java @@ -0,0 +1,271 @@ +package com.casic.missiles.modular.system.request; + +import com.alibaba.fastjson.annotation.JSONField; +import com.baomidou.mybatisplus.annotations.TableField; +import com.google.gson.annotations.SerializedName; + +import java.util.List; + +public class PersonInfo { + + //@JSONField(name = "PersonID") + @SerializedName("PersonID") + private Long personID; + + //@JSONField(name = "LastChange") + @SerializedName("LastChange") + private Long lastChange; + + //@JSONField(name = "PersonCode") + @SerializedName("PersonCode") + private String personCode; + + //@JSONField(name = "PersonName") + @SerializedName("PersonName") + private String personName; + + //@JSONField(name = "Remarks") + @SerializedName("Remarks") + private String remarks; + + //@JSONField(name = "TimeTemplateNum") + @SerializedName("TimeTemplateNum") + private Integer timeTemplateNum; + + //@JSONField(name = "TimeTemplateList") + @SerializedName("TimeTemplateList") + private List timeTemplateList; + + //@JSONField(name = "IdentificationNum") + @SerializedName("IdentificationNum") + private Integer identificationNum; + + //@JSONField(name = "IdentificationList") + @SerializedName("IdentificationList") + private List identificationList; + + //@JSONField(name = "ImageNum") + @SerializedName("ImageNum") + private Integer imageNum; + + //@JSONField(name = "ImageList") + @SerializedName("ImageList") + private List imageList; + + public Long getPersonID() { + return personID; + } + + public void setPersonID(Long personID) { + this.personID = personID; + } + + public Long getLastChange() { + return lastChange; + } + + public void setLastChange(Long lastChange) { + this.lastChange = lastChange; + } + + public String getPersonCode() { + return personCode; + } + + public void setPersonCode(String personCode) { + this.personCode = personCode; + } + + public String getPersonName() { + return personName; + } + + public void setPersonName(String personName) { + this.personName = personName; + } + + public String getRemarks() { + return remarks; + } + + public void setRemarks(String remarks) { + this.remarks = remarks; + } + + public Integer getTimeTemplateNum() { + return timeTemplateNum; + } + + public void setTimeTemplateNum(Integer timeTemplateNum) { + this.timeTemplateNum = timeTemplateNum; + } + + public List getTimeTemplateList() { + return timeTemplateList; + } + + public void setTimeTemplateList(List timeTemplateList) { + this.timeTemplateList = timeTemplateList; + } + + public Integer getIdentificationNum() { + return identificationNum; + } + + public void setIdentificationNum(Integer identificationNum) { + this.identificationNum = identificationNum; + } + + public List getIdentificationList() { + return identificationList; + } + + public void setIdentificationList(List identificationList) { + this.identificationList = identificationList; + } + + public Integer getImageNum() { + return imageNum; + } + + public void setImageNum(Integer imageNum) { + this.imageNum = imageNum; + } + + public List getImageList() { + return imageList; + } + + public void setImageList(List imageList) { + this.imageList = imageList; + } + + public class TimeTemplate{ + @JSONField(name = "BeginTime") + private Long beginTime; + @JSONField(name = "EndTime") + private Long endTime; + @JSONField(name = "Index") + private Long index; + + public TimeTemplate(Long beginTime, Long endTime, Long index) { + this.beginTime = beginTime; + this.endTime = endTime; + this.index = index; + } + + public Long getBeginTime() { + return beginTime; + } + + public void setBeginTime(Long beginTime) { + this.beginTime = beginTime; + } + + public Long getEndTime() { + return endTime; + } + + public void setEndTime(Long endTime) { + this.endTime = endTime; + } + + public Long getIndex() { + return index; + } + + public void setIndex(Long index) { + this.index = index; + } + } + + public TimeTemplate createTimeTemplate(Long beginTime, Long endTime, Long index){ + return new TimeTemplate(beginTime, endTime, index); + } + + public class IdentificationInfo { + @JSONField(name = "Type") + private Integer type; + @JSONField(name = "Number") + private String number; + + public IdentificationInfo(Integer type, String number) { + this.type = type; + this.number = number; + } + + public Integer getType() { + return type; + } + + public void setType(Integer type) { + this.type = type; + } + + public String getNumber() { + return number; + } + + public void setNumber(String number) { + this.number = number; + } + } + + public IdentificationInfo createIdentificationInfo(Integer type, String number){ + return new IdentificationInfo(type,number); + } + + public class ImageInfo{ + @JSONField(name = "FaceID") + private Long faceID; + @JSONField(name = "Name") + private String name; + @JSONField(name = "Size") + private Long size; + @JSONField(name = "Data") + private String data; + + public ImageInfo(Long faceID, String name, Long size, String data) { + this.faceID = faceID; + this.name = name; + this.size = size; + this.data = data; + } + + public Long getFaceID() { + return faceID; + } + + public void setFaceID(Long faceID) { + this.faceID = faceID; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Long getSize() { + return size; + } + + public void setSize(Long size) { + this.size = size; + } + + public String getData() { + return data; + } + + public void setData(String data) { + this.data = data; + } + } + + public ImageInfo createImageInfo(Long faceID, String name, Long size, String data){ + return new ImageInfo(faceID, name, size, data); + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceBaseResponse.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceBaseResponse.java new file mode 100644 index 0000000..fe93b8a --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceBaseResponse.java @@ -0,0 +1,90 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; +import com.google.gson.annotations.SerializedName; + +public class FaceBaseResponse { + @JSONField(name = "ResponseURL") + @SerializedName("ResponseURL") + private String responseUrl; + + @JSONField(name = "CreatedID") + @SerializedName("CreatedID") + private int createdId; + + @JSONField(name = "ResponseCode") + @SerializedName("ResponseCode") + private int responseCode; + + @JSONField(name = "ResponseString") + @SerializedName("ResponseString") + private String responseString; + + @JSONField(name = "StatusCode") + @SerializedName("StatusCode") + private int statusCode; + + @JSONField(name = "StatusString") + @SerializedName("StatusString") + private String statusString; + + //@JSONField(name = "Data") + @SerializedName("Data") + private T data; + + public String getResponseUrl() { + return responseUrl; + } + + public void setResponseUrl(String responseUrl) { + this.responseUrl = responseUrl; + } + + public int getCreatedId() { + return createdId; + } + + public void setCreatedId(int createdId) { + this.createdId = createdId; + } + + public int getResponseCode() { + return responseCode; + } + + public void setResponseCode(int responseCode) { + this.responseCode = responseCode; + } + + public String getResponseString() { + return responseString; + } + + public void setResponseString(String responseString) { + this.responseString = responseString; + } + + public int getStatusCode() { + return statusCode; + } + + public void setStatusCode(int statusCode) { + this.statusCode = statusCode; + } + + public String getStatusString() { + return statusString; + } + + public void setStatusString(String statusString) { + this.statusString = statusString; + } + + public T getData() { + return data; + } + + public void setData(T data) { + this.data = data; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceInfo.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceInfo.java new file mode 100644 index 0000000..f128c92 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceInfo.java @@ -0,0 +1,128 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; + +import java.util.List; + +public class FaceInfo { + @JSONField(name = "ID") + private Long id; + @JSONField(name = "Timestamp") + private Long timestamp; + @JSONField(name = "CapSrc") + private Long capSrc; + @JSONField(name = "FeatureNum") + private Long featureNum; + @JSONField(name = "FeatureList") + private List featureList; + @JSONField(name = "FeatureVersion") + private String featureVersion; + @JSONField(name = "Feature") + private String feature; + @JSONField(name = "Temperature") + private Float temperature; + @JSONField(name = "MaskFlag") + private Long maskFlag; + @JSONField(name = "PanoImage") + private Object panoImage; + @JSONField(name = "FaceImage") + private Object faceImage; + @JSONField(name = "FaceArea") + private Object faceArea; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Long getTimestamp() { + return timestamp; + } + + public void setTimestamp(Long timestamp) { + this.timestamp = timestamp; + } + + public Long getCapSrc() { + return capSrc; + } + + public void setCapSrc(Long capSrc) { + this.capSrc = capSrc; + } + + public Long getFeatureNum() { + return featureNum; + } + + public void setFeatureNum(Long featureNum) { + this.featureNum = featureNum; + } + + public List getFeatureList() { + return featureList; + } + + public void setFeatureList(List featureList) { + this.featureList = featureList; + } + + public String getFeatureVersion() { + return featureVersion; + } + + public void setFeatureVersion(String featureVersion) { + this.featureVersion = featureVersion; + } + + public String getFeature() { + return feature; + } + + public void setFeature(String feature) { + this.feature = feature; + } + + public Float getTemperature() { + return temperature; + } + + public void setTemperature(Float temperature) { + this.temperature = temperature; + } + + public Long getMaskFlag() { + return maskFlag; + } + + public void setMaskFlag(Long maskFlag) { + this.maskFlag = maskFlag; + } + + public Object getPanoImage() { + return panoImage; + } + + public void setPanoImage(Object panoImage) { + this.panoImage = panoImage; + } + + public Object getFaceImage() { + return faceImage; + } + + public void setFaceImage(Object faceImage) { + this.faceImage = faceImage; + } + + public Object getFaceArea() { + return faceArea; + } + + public void setFaceArea(Object faceArea) { + this.faceArea = faceArea; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/LibMatInfo.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/LibMatInfo.java new file mode 100644 index 0000000..ce6dd33 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/LibMatInfo.java @@ -0,0 +1,69 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; + +public class LibMatInfo { + @JSONField(name = "ID") + private Long id; + @JSONField(name = "LibID") + private Long libId; + @JSONField(name = "LibType") + private Long libType; + @JSONField(name = "MatchStatus") + private Long matchStatus; + @JSONField(name = "MatchPersonID") + private Long matchPersonId; + @JSONField(name = "MatchFaceID") + private Long matchFaceId; + + // MatchPersonInfo 暂时忽略不用 + + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Long getLibId() { + return libId; + } + + public void setLibId(Long libId) { + this.libId = libId; + } + + public Long getLibType() { + return libType; + } + + public void setLibType(Long libType) { + this.libType = libType; + } + + public Long getMatchStatus() { + return matchStatus; + } + + public void setMatchStatus(Long matchStatus) { + this.matchStatus = matchStatus; + } + + public Long getMatchPersonId() { + return matchPersonId; + } + + public void setMatchPersonId(Long matchPersonId) { + this.matchPersonId = matchPersonId; + } + + public Long getMatchFaceId() { + return matchFaceId; + } + + public void setMatchFaceId(Long matchFaceId) { + this.matchFaceId = matchFaceId; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/PersonResponseData.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/PersonResponseData.java new file mode 100644 index 0000000..186faed --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/PersonResponseData.java @@ -0,0 +1,31 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; +import com.google.gson.annotations.SerializedName; + +import java.util.List; + +public class PersonResponseData { + @JSONField(name = "Num") + @SerializedName("Num") + private int num; + @JSONField(name = "PersonList") + @SerializedName("PersonList") + private List personList; + + public int getNum() { + return num; + } + + public void setNum(int num) { + this.num = num; + } + + public List getPersonList() { + return personList; + } + + public void setPersonList(List personList) { + this.personList = personList; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/PersonResponseInfo.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/PersonResponseInfo.java new file mode 100644 index 0000000..7ba3edc --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/PersonResponseInfo.java @@ -0,0 +1,67 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; +import com.google.gson.annotations.SerializedName; + +import java.util.List; + +public class PersonResponseInfo { + @JSONField(name = "PersonID") + @SerializedName("PersonID") + private Long personId; + @JSONField(name = "FaceNum") + @SerializedName("FaceNum") + private Long faceNum; + @JSONField(name = "FaceList") + @SerializedName("FaceList") + private List faceList; + + public Long getPersonId() { + return personId; + } + + public void setPersonId(Long personId) { + this.personId = personId; + } + + public Long getFaceNum() { + return faceNum; + } + + public void setFaceNum(Long faceNum) { + this.faceNum = faceNum; + } + + public List getFaceList() { + return faceList; + } + + public void setFaceList(List faceList) { + this.faceList = faceList; + } + + public class PersonResponseFace{ + @JSONField(name = "FaceID") + @SerializedName("FaceID") + private Long faceId; + @JSONField(name = "ResultCode") + @SerializedName("ResultCode") + private Long resultCode; + + public Long getFaceId() { + return faceId; + } + + public void setFaceId(Long faceId) { + this.faceId = faceId; + } + + public Long getResultCode() { + return resultCode; + } + + public void setResultCode(Long resultCode) { + this.resultCode = resultCode; + } + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/RecordNotification.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/RecordNotification.java new file mode 100644 index 0000000..ca52d29 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/RecordNotification.java @@ -0,0 +1,138 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; + +import java.util.List; + +public class RecordNotification { + @JSONField(name = "Reference") + private String reference; + @JSONField(name = "Seq") + private int seq; + @JSONField(name = "DeviceCode") + private String deviceCode; + @JSONField(name = "Timestamp") + private Long timestamp; + @JSONField(name = "NotificationType") + private int notificationType; + @JSONField(name = "FaceInfoNum") + private int faceInfoNum; + @JSONField(name = "FaceInfoList") + private List faceInfoList; + @JSONField(name = "CardInfoNum") + private int cardInfoNum; + @JSONField(name = "CardInfoList") + private List cardInfoList; + @JSONField(name = "GateInfoNum") + private int gateInfoNum; + @JSONField(name = "GateInfoList") + private List gateInfoList; + @JSONField(name = "LibMatInfoNum") + private int libMatInfoNum; + @JSONField(name = "LibMatInfoList") + private List libMatInfoList; + + public String getReference() { + return reference; + } + + public void setReference(String reference) { + this.reference = reference; + } + + public int getSeq() { + return seq; + } + + public void setSeq(int seq) { + this.seq = seq; + } + + public String getDeviceCode() { + return deviceCode; + } + + public void setDeviceCode(String deviceCode) { + this.deviceCode = deviceCode; + } + + public Long getTimestamp() { + return timestamp; + } + + public void setTimestamp(Long timestamp) { + this.timestamp = timestamp; + } + + public int getNotificationType() { + return notificationType; + } + + public void setNotificationType(int notificationType) { + this.notificationType = notificationType; + } + + public int getFaceInfoNum() { + return faceInfoNum; + } + + public void setFaceInfoNum(int faceInfoNum) { + this.faceInfoNum = faceInfoNum; + } + + public List getFaceInfoList() { + return faceInfoList; + } + + public void setFaceInfoList(List faceInfoList) { + this.faceInfoList = faceInfoList; + } + + public int getCardInfoNum() { + return cardInfoNum; + } + + public void setCardInfoNum(int cardInfoNum) { + this.cardInfoNum = cardInfoNum; + } + + public List getCardInfoList() { + return cardInfoList; + } + + public void setCardInfoList(List cardInfoList) { + this.cardInfoList = cardInfoList; + } + + public int getGateInfoNum() { + return gateInfoNum; + } + + public void setGateInfoNum(int gateInfoNum) { + this.gateInfoNum = gateInfoNum; + } + + public List getGateInfoList() { + return gateInfoList; + } + + public void setGateInfoList(List gateInfoList) { + this.gateInfoList = gateInfoList; + } + + public int getLibMatInfoNum() { + return libMatInfoNum; + } + + public void setLibMatInfoNum(int libMatInfoNum) { + this.libMatInfoNum = libMatInfoNum; + } + + public List getLibMatInfoList() { + return libMatInfoList; + } + + public void setLibMatInfoList(List libMatInfoList) { + this.libMatInfoList = libMatInfoList; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/runner/InitSubscribeRunner.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/runner/InitSubscribeRunner.java new file mode 100644 index 0000000..c7d0565 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/runner/InitSubscribeRunner.java @@ -0,0 +1,43 @@ +package com.casic.missiles.modular.system.runner; + +import com.casic.missiles.modular.system.model.Device; +import com.casic.missiles.modular.system.service.IDeviceSupportService; +import com.casic.missiles.modular.system.service.IFaceSyncService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.ApplicationArguments; +import org.springframework.boot.ApplicationRunner; +import org.springframework.stereotype.Component; + +import java.util.ArrayList; +import java.util.List; + +@Component +public class InitSubscribeRunner implements ApplicationRunner { + private static Logger logger = LoggerFactory.getLogger(InitSubscribeRunner.class); + + @Value("${iris.face.initSubscribe}") + private String initSubscribe; + @Autowired + private IDeviceSupportService deviceSupportService; + @Autowired + private IFaceSyncService faceSyncService; + + /** + * 启动项目时,根据需要初始化设备订阅信息 + * @param applicationArguments + * @throws Exception + */ + @Override + public void run(ApplicationArguments applicationArguments) throws Exception { + logger.info("==================initSubscribe: "); + if(Boolean.valueOf(initSubscribe)){ + List deviceList = deviceSupportService.selectDeviceByType("5"); + List deviceIds = new ArrayList<>(); + deviceList.forEach(device -> deviceIds.add(Long.valueOf(device.getId()))); + faceSyncService.initSubscription(deviceIds); + } + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFacePersonSyncService.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFacePersonSyncService.java new file mode 100644 index 0000000..6b2461b --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFacePersonSyncService.java @@ -0,0 +1,18 @@ +package com.casic.missiles.modular.system.service; + +import com.casic.missiles.modular.system.model.FacePersonSync; +import com.baomidou.mybatisplus.service.IService; + +/** + *

+ * 服务类 + *

+ * + * @author zyj123 + * @since 2020-07-24 + */ +public interface IFacePersonSyncService extends IService { + Long selectSyncId(Long personId); + Long selectPersonId(Long syncId); + Long getMaxSyncId(Long personId); +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFaceSubscribeService.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFaceSubscribeService.java new file mode 100644 index 0000000..e0461ed --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFaceSubscribeService.java @@ -0,0 +1,24 @@ +package com.casic.missiles.modular.system.service; + +import com.casic.missiles.modular.system.model.FaceSubscribe; +import com.baomidou.mybatisplus.service.IService; + +import java.util.List; + +/** + *

+ * 服务类 + *

+ * + * @author zyj123 + * @since 2020-07-25 + */ +public interface IFaceSubscribeService extends IService { + + List selectSubscribeIdsByDevCode(String devCode); + + boolean deleteByDevCode(String devCode); + + boolean insertSubscribe(Long subscribeId, String devCode); + +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFaceSyncService.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFaceSyncService.java new file mode 100644 index 0000000..effd921 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFaceSyncService.java @@ -0,0 +1,21 @@ +package com.casic.missiles.modular.system.service; + +import com.casic.missiles.modular.system.response.RecordNotification; + +import java.util.List; + +public interface IFaceSyncService { + String uploadPerson(List personIds, List deviceIds,String personType); + + String checkPersonPhoto(List personIds); + + void receiveRecord(RecordNotification recordNotification); + + void receiveRecord(String recordNotificationStr); + + String initSubscription(List deviceIds); + + boolean deleteSubscription(String deviceIp, Long subscribeId); + + Long createSubscription(String deviceIp,String ip,String port); +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/Impl/FacePersonSyncServiceImpl.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/Impl/FacePersonSyncServiceImpl.java new file mode 100644 index 0000000..d1d1694 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/Impl/FacePersonSyncServiceImpl.java @@ -0,0 +1,55 @@ +package com.casic.missiles.modular.system.service.Impl; + +import com.baomidou.mybatisplus.mapper.EntityWrapper; +import com.casic.missiles.core.util.ToolUtil; +import com.casic.missiles.modular.system.model.FacePersonSync; +import com.casic.missiles.modular.system.dao.FacePersonSyncMapper; +import com.casic.missiles.modular.system.service.IFacePersonSyncService; +import com.baomidou.mybatisplus.service.impl.ServiceImpl; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +/** + *

+ * 服务实现类 + *

+ * + * @author zyj123 + * @since 2020-07-24 + */ +@Service +public class FacePersonSyncServiceImpl extends ServiceImpl implements IFacePersonSyncService { + + @Override + public Long selectSyncId(Long personId) { + FacePersonSync facePersonSync = this.selectById(personId); + if(ToolUtil.isNotEmpty(facePersonSync)){ + return facePersonSync.getSyncId(); + } + return null; + } + + @Override + public Long selectPersonId(Long syncId) { + EntityWrapper query = new EntityWrapper(); + query.eq("SYNC_ID",syncId); + FacePersonSync facePersonSync = this.selectOne(query); + if(ToolUtil.isNotEmpty(facePersonSync)){ + return facePersonSync.getPersonId(); + } + return null; + } + + @Override + @Transactional + public Long getMaxSyncId(Long personId) { + Long maxId = this.baseMapper.getMaxSyncId(); + if(ToolUtil.isEmpty(maxId)){ + maxId = 1000L; + }else { + maxId = maxId + 1; + } + this.insert(new FacePersonSync(personId,maxId)); + return maxId; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/Impl/FaceSubscribeServiceImpl.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/Impl/FaceSubscribeServiceImpl.java new file mode 100644 index 0000000..c04302d --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/Impl/FaceSubscribeServiceImpl.java @@ -0,0 +1,52 @@ +package com.casic.missiles.modular.system.service.Impl; + +import com.baomidou.mybatisplus.mapper.EntityWrapper; +import com.casic.missiles.modular.system.model.FaceSubscribe; +import com.casic.missiles.modular.system.dao.FaceSubscribeMapper; +import com.casic.missiles.modular.system.service.IFaceSubscribeService; +import com.baomidou.mybatisplus.service.impl.ServiceImpl; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +/** + *

+ * 服务实现类 + *

+ * + * @author zyj123 + * @since 2020-07-25 + */ +@Service +public class FaceSubscribeServiceImpl extends ServiceImpl implements IFaceSubscribeService { + + @Override + public List selectSubscribeIdsByDevCode(String devCode) { + EntityWrapper query = new EntityWrapper(); + query.eq("DEVICE_CODE",devCode); + List faceSubscribes = this.selectList(query); + List subscribeIds = new ArrayList<>(); + for (FaceSubscribe faceSubscribe : faceSubscribes) { + subscribeIds.add(faceSubscribe.getSubscribeId()); + } + return subscribeIds; + } + + @Override + public boolean deleteByDevCode(String devCode) { + EntityWrapper query = new EntityWrapper(); + query.eq("DEVICE_CODE",devCode); + return this.delete(query); + } + + @Override + public boolean insertSubscribe(Long subscribeId, String devCode) { + FaceSubscribe faceSubscribe = new FaceSubscribe(); + faceSubscribe.setDeviceCode(devCode); + faceSubscribe.setSubscribeId(subscribeId); + faceSubscribe.setUpdateTime(new Date()); + return this.insert(faceSubscribe); + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/Impl/FaceSyncServiceImpl.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/Impl/FaceSyncServiceImpl.java new file mode 100644 index 0000000..8826be5 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/Impl/FaceSyncServiceImpl.java @@ -0,0 +1,465 @@ +package com.casic.missiles.modular.system.service.Impl; + +import com.alibaba.fastjson.JSONObject; +import com.casic.missiles.core.common.service.ICommonPersonService; +import com.casic.missiles.core.util.ToolUtil; +import com.casic.missiles.modular.system.model.Device; +import com.casic.missiles.modular.system.model.FacePersonSync; +import com.casic.missiles.modular.system.model.Person; +import com.casic.missiles.modular.system.model.RecognitionRecords; +import com.casic.missiles.modular.system.request.PersonInfo; +import com.casic.missiles.modular.system.response.*; +import com.casic.missiles.modular.system.service.*; +import com.casic.missiles.modular.system.util.HttpClientUtil; +import com.google.gson.*; +import org.apache.commons.lang3.StringUtils; +import org.omg.CORBA.Object; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import com.casic.missiles.modular.system.constant.FaceSyncConst; +import java.net.InetAddress; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +@Service +public class FaceSyncServiceImpl implements IFaceSyncService { + private static final Logger logger = LoggerFactory.getLogger(FaceSyncServiceImpl.class); + + @Autowired + private IFacePersonSyncService personSyncService; + @Autowired + private ICommonPersonService commonPersonService; + @Autowired + private IPersonPhotoSupportService photoSupportService; + @Autowired + private IDeviceSupportService deviceSupportService; + @Autowired + private IRecordSupportService recordSupportService; + @Autowired + private IFaceSubscribeService subscribeService; + @Value("${server.port}") + private String serverPort; + @Value("${iris.face.serverHost}") + private String serverHost; + + @Override + @Transactional + public String uploadPerson(List personIds,List deviceIds,String personType) { + String error = null; + + try{ + List personInfoList = new ArrayList<>(personIds.size()); + for (Long personId : personIds) { + Person person = commonPersonService.getPersonById(personId); + Long syncId = getPersonSyncId(personId); + String photoData = photoSupportService.selectPhotoDataById(personId); + PersonInfo personInfo = convPersonInfo(person,syncId,photoData); + personInfoList.add(personInfo); + } + + + outterLoop : for (Long deviceId : deviceIds) { + Device device = deviceSupportService.selectById(deviceId); + // 批量下发(单次最多6个,分多次下发) + int batchSize = FaceSyncConst.UPLOAD_MAX_PERSON; + int batchNum = (int)Math.ceil((double)personInfoList.size()/batchSize); + for (int i = 0; i < batchNum; i++) { + int fromIndex = i * batchSize; + int toIndex = (i+1) * batchSize <= personInfoList.size() ? (i+1) * batchSize : personInfoList.size(); + List subPersonInfoList = personInfoList.subList(fromIndex,toIndex); + + // 设置上传body对象 + Gson gson = new GsonBuilder().serializeNulls().create(); + JsonObject body = new JsonObject(); + JsonElement person = gson.toJsonTree(subPersonInfoList); + body.addProperty("Num",subPersonInfoList.size()); + body.add("PersonInfoList",person); + String bodyStr = gson.toJson(body); +// logger.info(String.valueOf(subPersonInfoList.size())); + logger.info(bodyStr); + +// 调用接口上传 + String devIp = device.getDevIp(); + String personLib = null; + if("1".equals(personType)){ + personLib = FaceSyncConst.UPLOAD_STAFF_LIB; + }else { + personLib = FaceSyncConst.UPLOAD_VISITOR_LIB; + } + + String url = "http://".concat(devIp).concat(FaceSyncConst.UPLOAD_URL_PREFIX).concat(personLib).concat(FaceSyncConst.UPLOAD_URL_SUFFIX); + String responseContent = HttpClientUtil.sendHttpPost(url,bodyStr); + logger.info(responseContent); + JsonObject obj = gson.fromJson(responseContent, JsonObject.class); + // 解析返回结果 + FaceBaseResponse> response = gson.fromJson(obj.get("Response"),FaceBaseResponse.class); + if(response.getResponseCode() == 0 && response.getStatusCode() == 0){ + PersonResponseData personResponseData = gson.fromJson(gson.toJson(response.getData()),PersonResponseData.class); + List responseInfos = personResponseData.getPersonList(); + for(int j = 0;j < responseInfos.size();j++){ + PersonResponseInfo personResponseInfo = gson.fromJson(gson.toJson(responseInfos.get(j)),PersonResponseInfo.class);; + if(personResponseInfo.getFaceList().get(0).getResultCode() == 0){ + // 成功 + logger.info(String.format("人脸数据下发成功,人员:%s,设备: %s",personResponseInfo.getPersonId(),device.getDevCode())); + }else{ + error = convErrorCode(personResponseInfo.getFaceList().get(0).getResultCode()); + String personName = commonPersonService.getPersonById(personIds.get(i)).getName(); + error = String.format("下发失败,%s %s",personName,error); + logger.error(error); + break outterLoop; + } + } + }else { + if(response.getResponseCode() != 0 ){ + error = String.format("设备%s下发失败: %s",device.getDevCode(),response.getResponseString()); + logger.error(error); + break; + } + if(response.getStatusCode() != 0){ + error = String.format("设备%s下发失败: %s",device.getDevCode(),response.getStatusString()); + logger.error(error); + break; + } + } + } + } + }catch (Exception e){ + e.printStackTrace(); + logger.error(e.getMessage()); + error = "下发失败"; + } + + return error; + } + + private void updatePersonInfoList(List personInfoList,List personIds){ + for (int i = 0; i < personIds.size(); i++) { + Long syncId = personSyncService.selectSyncId(personIds.get(i)); + if(ToolUtil.isNotEmpty(syncId)){ + PersonInfo personInfo = personInfoList.get(i); + personInfo.setPersonID(syncId); + if(ToolUtil.isNotEmpty(personInfo.getImageList())){ + personInfo.getImageList().get(i).setFaceID(syncId); + } + } + } + } + + private Long getPersonSyncId(Long personId){ + Long syncId = personSyncService.selectSyncId(personId); + if(ToolUtil.isEmpty(syncId)){ + syncId = personSyncService.getMaxSyncId(personId); + } + return syncId; + } + + private PersonInfo convPersonInfo(Person person,Long syncId,String photoData){ + PersonInfo personInfo = new PersonInfo(); + if(ToolUtil.isNotEmpty(syncId)){ + personInfo.setPersonID(syncId); + } + if(ToolUtil.isNotEmpty(person.getUpdatetime())){ + personInfo.setLastChange(person.getUpdatetime().getTime()); + } + if(ToolUtil.isNotEmpty(person.getPersonCode()) && person.getPersonCode().length() <= FaceSyncConst.UPLOAD_PERSONCODE_MAXLENGTH){ + personInfo.setPersonCode(person.getPersonCode()); + }else { + personInfo.setPersonCode(String.valueOf(syncId)); + } + if(ToolUtil.isNotEmpty(person.getName())){ + personInfo.setPersonName(person.getName()); + } + if(ToolUtil.isNotEmpty(person.getRemarks()) && person.getRemarks().length() <= FaceSyncConst.UPLOAD_REMARK_MAXLENGTH){ + personInfo.setRemarks(person.getRemarks()); + }else { + personInfo.setRemarks(""); + } + + // 时间模板 + personInfo.setTimeTemplateNum(0); + List timeTemplateList = new ArrayList<>(); + timeTemplateList.add(personInfo.createTimeTemplate(0L,4294967295L,0L)); + personInfo.setTimeTemplateList(timeTemplateList); + + // 证件列表 + if(ToolUtil.isNotEmpty(person.getIdCardNo())){ + personInfo.setIdentificationNum(1); + List identificationInfoList = new ArrayList<>(); + identificationInfoList.add(personInfo.createIdentificationInfo(1,person.getIdCardNo())); + personInfo.setIdentificationList(identificationInfoList); + }else{ + personInfo.setIdentificationNum(0); + } + + // 图片列表 + if(ToolUtil.isNotEmpty(photoData)){ + personInfo.setImageNum(1); + List imageInfoList = new ArrayList<>(); + // 图片base64码 + if(photoData.startsWith("data") || photoData.startsWith("base64")){ + int splitIndex = photoData.indexOf(","); + photoData = photoData.substring(splitIndex+1); + } + imageInfoList.add(personInfo.createImageInfo(syncId,person.getPhoto(),Long.valueOf(photoData.length()),photoData)); + personInfo.setImageList(imageInfoList); + }else { + personInfo.setImageNum(0); + } + return personInfo; + } + + private String convErrorCode(Long errorCode){ + String errorMsg = ""; + switch (errorCode.intValue()){ + case 1000: + errorMsg = "算法初始化失败"; + break; + case 1001: + errorMsg = "人脸检测失败"; + break; + case 1002: + errorMsg = "图片未检测到人脸"; + break; + case 1003: + errorMsg = "jpeg照片解码失败"; + break; + case 1004: + errorMsg = "图片质量分数不满足"; + break; + case 1005: + errorMsg = "图片缩放失败"; + break; + case 1006: + errorMsg = "未启用智能"; + break; + case 1007: + errorMsg = "导入图片过小"; + break; + case 1008: + errorMsg = "导入图片过大"; + break; + case 1009: + errorMsg = "导入图片分辨率超过1920*1080"; + break; + case 1010: + errorMsg = "导入图片不存在"; + break; + case 1011: + errorMsg = "人脸元素个数已达到上限"; + break; + case 1012: + errorMsg = "智能棒算法模型不匹配"; + break; + case 1013: + errorMsg = "人脸导入库成员证件号非法"; + break; + case 1014: + errorMsg = "人脸导入库成员图片格式错误"; + break; + case 1015: + errorMsg = "通道布控已达设备能力上限"; + break; + case 1016: + errorMsg = "其它客户端正在进行操作人脸库"; + break; + case 1017: + errorMsg = "人脸库文件正在更新中"; + break; + case 1018: + errorMsg = "Json反序列化失败"; + break; + case 1019: + errorMsg = "Base64解码失败"; + break; + case 1020: + errorMsg = "人脸照片,编码后的大小和实际接收到的长度不一致,关注Data和Size大小是否正确"; + break; + default: + break; + } + return errorMsg; + + } + + @Override + public String checkPersonPhoto(List personIds) { + String error = null; + for (Long personId : personIds) { + Person person = commonPersonService.getPersonById(personId); + String photoData = photoSupportService.selectPhotoDataById(personId); + if(ToolUtil.isEmpty(photoData)){ + error = String.format("%s 未上传照片",person.getName()); + break; + } + if(photoData.startsWith("data") || photoData.startsWith("base64")){ + int splitIndex = photoData.indexOf(","); + photoData = photoData.substring(splitIndex+1); + } + if(!photoData.startsWith("/9j")){ + error = String.format("%s人员照片不符合要求,必须为jpg格式",person.getName()); + break; + } + + // 找到等号,把等号也去掉 + int equalIndex = photoData.indexOf('='); + if(equalIndex>=0) { + photoData=photoData.substring(0, equalIndex); + } + // 原来的字符流大小,单位为字节 + int strLength=photoData.length(); + // 计算后得到的文件流大小,单位为字节 + int fileLength=Integer.valueOf(strLength-(strLength/8)*2); + if(fileLength / 1024 < 20){ + error = String.format("%s人员照片不符合要求,照片必须大于20Kb",person.getName()); + break; + } + } + return error; + } + + @Override + public void receiveRecord(RecordNotification recordNotification){ +// if(recordNotification.getFaceInfoNum() != recordNotification.getLibMatInfoNum()){ +// logger.error("采集和匹配数据不一致,识别失败"); +// } else { + String deviceCode = recordNotification.getDeviceCode(); + List recordsList = new ArrayList<>(); + for (int i = 0; i < recordNotification.getLibMatInfoNum(); i++) { + //FaceInfo faceInfo = recordNotification.getFaceInfoList().get(i); + LibMatInfo libMatInfo = recordNotification.getLibMatInfoList().get(i); + if(libMatInfo.getMatchStatus() == 1){ + FaceInfo faceInfo = getFaceInfoByMatchId(recordNotification.getFaceInfoList(),libMatInfo.getId()); + Long personId = personSyncService.selectPersonId(libMatInfo.getMatchPersonId()); + if(ToolUtil.isNotEmpty(personId) && ToolUtil.isNotEmpty(faceInfo)){ + RecognitionRecords record = new RecognitionRecords(); + record.setPersonId(personId); + record.setDatetime(new Date(faceInfo.getTimestamp()*1000)); + record.setDevCode(deviceCode); + if(ToolUtil.isNotEmpty(faceInfo.getTemperature())){ + record.setTemperature(String.valueOf(faceInfo.getTemperature())); + } + record.setOriginalId(libMatInfo.getId()); + record.setSyncTime(new Date()); + + Device device = deviceSupportService.selectDeviceByCode(deviceCode); + if(ToolUtil.isNotEmpty(device)){ + if(ToolUtil.isNotEmpty(device.getDevIp())){ + record.setDevIp(device.getDevIp()); + } + } + + recordsList.add(record); + } + } + } + if(ToolUtil.isNotEmpty(recordsList)){ + recordSupportService.insertBatch(recordsList); + } + } + + @Override + public void receiveRecord(String recordNotificationStr) { + RecordNotification recordNotification = JSONObject.parseObject(recordNotificationStr,RecordNotification.class); + receiveRecord(recordNotification); + } + + public FaceInfo getFaceInfoByMatchId(List faceInfoList ,Long id){ + for (FaceInfo faceInfo : faceInfoList) { + if(faceInfo.getId().equals(id)){ + return faceInfo; + } + } + return null; + } + + @Override + public String initSubscription(List deviceIds) { + try { + List error = new ArrayList<>(); + for (Long deviceId : deviceIds) { + Device device = deviceSupportService.selectById(deviceId); + List subscribeIds = subscribeService.selectSubscribeIdsByDevCode(device.getDevCode());; + // 删除所有id + boolean flag = true; + for (Long subscribeId : subscribeIds) { + flag = flag && deleteSubscription(device.getDevIp(),subscribeId); + } + flag = flag && subscribeService.deleteByDevCode(device.getDevCode()); + // 创建订阅 + Long subscribeId = createSubscription(device.getDevIp(),serverHost,serverPort); + flag = flag && ToolUtil.isNotEmpty(subscribeId); + if(ToolUtil.isNotEmpty(subscribeId)){ + flag = flag && subscribeService.insertSubscribe(subscribeId,device.getDevCode()); + } + if(!flag){ + logger.error(String.format("device %s init subsrciption error",device.getDevCode())); + error.add(device.getDevCode()); + } + } + if(ToolUtil.isNotEmpty(error)){ + return StringUtils.join(error,",").concat("订阅失败"); + }else { + return null; + } + }catch (Exception e){ + e.printStackTrace(); + logger.error(e.getMessage()); + return "订阅失败"; + } + + } + + @Override + public boolean deleteSubscription(String deviceIp, Long subscribeId) { + String url = "http://" + deviceIp + FaceSyncConst.SUBSCRIBE_URL + subscribeId; + String responseContent = HttpClientUtil.sendHttpDelete(url); + logger.info(responseContent); + Gson gson = new Gson(); + JsonObject obj = gson.fromJson(responseContent, JsonObject.class); + logger.info(obj.get("Response").toString()); + FaceBaseResponse response = gson.fromJson(obj.get("Response"),FaceBaseResponse.class); + if(response.getResponseCode() == 0 && response.getStatusCode() == 0){ + return true; + }else { + logger.error(String.format("delele subscribe error, device '%s', subscribeId '%s', response '%s', status '%s'",deviceIp,subscribeId,response.getResponseString(),response.getStatusString())); + return false; + } + } + + @Override + public Long createSubscription(String deviceIp, String ip, String port) { + JsonObject request = new JsonObject(); + request.addProperty("AddressType",0); + request.addProperty("IPAddress",ip); + request.addProperty("Port",Long.valueOf(port)); + request.addProperty("Duration",4294967295L); + request.addProperty("Type",1024); + JsonObject subscribePersonCondition = new JsonObject(); + subscribePersonCondition.addProperty("LibIDNum",65535); + subscribePersonCondition.add("LibIDList",new JsonArray()); + request.add("SubscribePersonCondition",subscribePersonCondition); + Gson gson = new Gson(); + String requestStr = gson.toJson(request); + System.out.println(requestStr); + String url = "http://" + deviceIp + FaceSyncConst.SUBSCRIBE_URL ; + String responseContent = HttpClientUtil.sendHttpPostJson(url,requestStr); + logger.info(responseContent); + JsonObject obj = gson.fromJson(responseContent, JsonObject.class); + FaceBaseResponse response = gson.fromJson(obj.get("Response"),FaceBaseResponse.class); + if(response.getResponseCode() == 0 && response.getStatusCode()==0){ + JsonObject data = gson.fromJson(gson.toJson(response.getData()),JsonObject.class); + Long subsrcibeId = data.get("ID").getAsLong(); + logger.info(String.format("create subscribe success, device '%s', subsrcibeId '%s'",deviceIp,subsrcibeId)); + return subsrcibeId; + }else { + logger.error(String.format("create subscribe error, device '%s', response '%s', status '%s'",deviceIp,response.getResponseString(),response.getStatusString())); + return null; + } + } + +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/util/HttpClientUtil.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/util/HttpClientUtil.java new file mode 100644 index 0000000..e258174 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/util/HttpClientUtil.java @@ -0,0 +1,468 @@ +package com.casic.missiles.modular.system.util; + +import java.io.File; +import java.io.IOException; +import java.security.KeyManagementException; +import java.security.KeyStoreException; +import java.security.NoSuchAlgorithmException; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.apache.http.HttpEntity; +import org.apache.http.HttpStatus; +import org.apache.http.client.config.RequestConfig; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpDelete; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.config.Registry; +import org.apache.http.config.RegistryBuilder; +import org.apache.http.conn.socket.ConnectionSocketFactory; +import org.apache.http.conn.socket.PlainConnectionSocketFactory; +import org.apache.http.conn.ssl.SSLConnectionSocketFactory; +import org.apache.http.conn.ssl.SSLContextBuilder; +import org.apache.http.conn.ssl.TrustSelfSignedStrategy; +import org.apache.http.entity.ContentType; +import org.apache.http.entity.StringEntity; +import org.apache.http.entity.mime.MultipartEntityBuilder; +import org.apache.http.entity.mime.content.FileBody; +import org.apache.http.entity.mime.content.StringBody; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.DefaultHttpRequestRetryHandler; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; +import org.apache.http.util.EntityUtils; + +/** + * + * @author H__D + * @date 2016年10月19日 上午11:27:25 + * + */ +public class HttpClientUtil { + + // utf-8字符编码 + public static final String CHARSET_UTF_8 = "utf-8"; + + // HTTP内容类型。 + public static final String CONTENT_TYPE_TEXT_HTML = "text/xml"; + + // HTTP内容类型。相当于form表单的形式,提交数据 + public static final String CONTENT_TYPE_FORM_URL = "application/x-www-form-urlencoded"; + + // HTTP内容类型。相当于form表单的形式,提交数据 + public static final String CONTENT_TYPE_JSON_URL = "application/json;charset=utf-8"; + + + // 连接管理器 + private static PoolingHttpClientConnectionManager pool; + + // 请求配置 + private static RequestConfig requestConfig; + + static { + + try { + //System.out.println("初始化HttpClientTest~~~开始"); + SSLContextBuilder builder = new SSLContextBuilder(); + builder.loadTrustMaterial(null, new TrustSelfSignedStrategy()); + SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory( + builder.build()); + // 配置同时支持 HTTP 和 HTPPS + Registry socketFactoryRegistry = RegistryBuilder. create().register( + "http", PlainConnectionSocketFactory.getSocketFactory()).register( + "https", sslsf).build(); + // 初始化连接管理器 + pool = new PoolingHttpClientConnectionManager( + socketFactoryRegistry); + // 将最大连接数增加到200,实际项目最好从配置文件中读取这个值 + pool.setMaxTotal(200); + // 设置最大路由 + pool.setDefaultMaxPerRoute(2); + // 根据默认超时限制初始化requestConfig + int socketTimeout = 10000; + int connectTimeout = 10000; + int connectionRequestTimeout = 10000; + requestConfig = RequestConfig.custom().setConnectionRequestTimeout( + connectionRequestTimeout).setSocketTimeout(socketTimeout).setConnectTimeout( + connectTimeout).build(); + + //System.out.println("初始化HttpClientTest~~~结束"); + } catch (NoSuchAlgorithmException e) { + e.printStackTrace(); + } catch (KeyStoreException e) { + e.printStackTrace(); + } catch (KeyManagementException e) { + e.printStackTrace(); + } + + + // 设置请求超时时间 + requestConfig = RequestConfig.custom().setSocketTimeout(50000).setConnectTimeout(50000) + .setConnectionRequestTimeout(50000).build(); + } + + public static CloseableHttpClient getHttpClient() { + + CloseableHttpClient httpClient = HttpClients.custom() + // 设置连接池管理 + .setConnectionManager(pool) + // 设置请求配置 + .setDefaultRequestConfig(requestConfig) + // 设置重试次数 + .setRetryHandler(new DefaultHttpRequestRetryHandler(0, false)) + .build(); + + return httpClient; + } + + /** + * 发送Post请求 + * + * @param httpPost + * @return + */ + private static String sendHttpPost(HttpPost httpPost) { + + CloseableHttpClient httpClient = null; + CloseableHttpResponse response = null; + // 响应内容 + String responseContent = null; + try { + // 创建默认的httpClient实例. + httpClient = getHttpClient(); + // 配置请求信息 + httpPost.setConfig(requestConfig); + // 执行请求 + response = httpClient.execute(httpPost); + // 得到响应实例 + HttpEntity entity = response.getEntity(); + + // 可以获得响应头 + // Header[] headers = response.getHeaders(HttpHeaders.CONTENT_TYPE); + // for (Header header : headers) { + // System.out.println(header.getName()); + // } + + // 得到响应类型 + // System.out.println(ContentType.getOrDefault(response.getEntity()).getMimeType()); + + // 判断响应状态 + if (response.getStatusLine().getStatusCode() >= 300) { + throw new Exception( + "HTTP Request is not success, Response code is " + response.getStatusLine().getStatusCode()); + } + + if (HttpStatus.SC_OK == response.getStatusLine().getStatusCode()) { + responseContent = EntityUtils.toString(entity, CHARSET_UTF_8); + EntityUtils.consume(entity); + } + + } catch (Exception e) { + e.printStackTrace(); + } finally { + try { + // 释放资源 + if (response != null) { + response.close(); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + return responseContent; + } + + /** + * 发送Get请求 + * + * @param httpGet + * @return + */ + private static String sendHttpGet(HttpGet httpGet) { + + CloseableHttpClient httpClient = null; + CloseableHttpResponse response = null; + // 响应内容 + String responseContent = null; + try { + // 创建默认的httpClient实例. + httpClient = getHttpClient(); + // 配置请求信息 + httpGet.setConfig(requestConfig); + // 执行请求 + response = httpClient.execute(httpGet); + // 得到响应实例 + HttpEntity entity = response.getEntity(); + + // 可以获得响应头 + // Header[] headers = response.getHeaders(HttpHeaders.CONTENT_TYPE); + // for (Header header : headers) { + // System.out.println(header.getName()); + // } + + // 得到响应类型 + // System.out.println(ContentType.getOrDefault(response.getEntity()).getMimeType()); + + // 判断响应状态 + if (response.getStatusLine().getStatusCode() >= 300) { + throw new Exception( + "HTTP Request is not success, Response code is " + response.getStatusLine().getStatusCode()); + } + + if (HttpStatus.SC_OK == response.getStatusLine().getStatusCode()) { + responseContent = EntityUtils.toString(entity, CHARSET_UTF_8); + EntityUtils.consume(entity); + } + + } catch (Exception e) { + e.printStackTrace(); + } finally { + try { + // 释放资源 + if (response != null) { + response.close(); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + return responseContent; + } + + /** + * 发送Delete请求 + * + * @param httpDelete + * @return + */ + private static String sendHttpDelete(HttpDelete httpDelete) { + + CloseableHttpClient httpClient = null; + CloseableHttpResponse response = null; + // 响应内容 + String responseContent = null; + try { + // 创建默认的httpClient实例. + httpClient = getHttpClient(); + // 配置请求信息 + httpDelete.setConfig(requestConfig); + // 执行请求 + response = httpClient.execute(httpDelete); + // 得到响应实例 + HttpEntity entity = response.getEntity(); + + // 可以获得响应头 + // Header[] headers = response.getHeaders(HttpHeaders.CONTENT_TYPE); + // for (Header header : headers) { + // System.out.println(header.getName()); + // } + + // 得到响应类型 + // System.out.println(ContentType.getOrDefault(response.getEntity()).getMimeType()); + + // 判断响应状态 + if (response.getStatusLine().getStatusCode() >= 300) { + throw new Exception( + "HTTP Request is not success, Response code is " + response.getStatusLine().getStatusCode()); + } + + if (HttpStatus.SC_OK == response.getStatusLine().getStatusCode()) { + responseContent = EntityUtils.toString(entity, CHARSET_UTF_8); + EntityUtils.consume(entity); + } + + } catch (Exception e) { + e.printStackTrace(); + } finally { + try { + // 释放资源 + if (response != null) { + response.close(); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + return responseContent; + } + + + + /** + * 发送 post请求 + * + * @param httpUrl 地址 + */ + public static String sendHttpPost(String httpUrl) { + // 创建httpPost + HttpPost httpPost = new HttpPost(httpUrl); + return sendHttpPost(httpPost); + } + + /** + * 发送 get请求 + * + * @param httpUrl + */ + public static String sendHttpGet(String httpUrl) { + // 创建get请求 + HttpGet httpGet = new HttpGet(httpUrl); + return sendHttpGet(httpGet); + } + + /** + * 发送 DELETE 请求 + * + * @param httpUrl + */ + public static String sendHttpDelete(String httpUrl) { + // 创建delete请求 + HttpDelete httpDelete = new HttpDelete(httpUrl); + return sendHttpDelete(httpDelete); + } + + + + /** + * 发送 post请求(带文件) + * + * @param httpUrl + * 地址 + * @param maps + * 参数 + * @param fileLists + * 附件 + */ + public static String sendHttpPost(String httpUrl, Map maps, List fileLists) { + HttpPost httpPost = new HttpPost(httpUrl);// 创建httpPost + MultipartEntityBuilder meBuilder = MultipartEntityBuilder.create(); + if (maps != null) { + for (String key : maps.keySet()) { + meBuilder.addPart(key, new StringBody(maps.get(key), ContentType.TEXT_PLAIN)); + } + } + if (fileLists != null) { + for (File file : fileLists) { + FileBody fileBody = new FileBody(file); + meBuilder.addPart("files", fileBody); + } + } + HttpEntity reqEntity = meBuilder.build(); + httpPost.setEntity(reqEntity); + return sendHttpPost(httpPost); + } + + /** + * 发送 post请求 + * + * @param httpUrl + * 地址 + * @param params + * 参数(格式:key1=value1&key2=value2) + * + */ + public static String sendHttpPost(String httpUrl, String params) { + HttpPost httpPost = new HttpPost(httpUrl);// 创建httpPost + try { + // 设置参数 + if (params != null && params.trim().length() > 0) { + StringEntity stringEntity = new StringEntity(params, "UTF-8"); + stringEntity.setContentType(CONTENT_TYPE_FORM_URL); + httpPost.setEntity(stringEntity); + } + } catch (Exception e) { + throw e; + } + return sendHttpPost(httpPost); + } + + /** + * 发送 post请求 + * + * @param maps + * 参数 + */ + public static String sendHttpPost(String httpUrl, Map maps) { + String parem = convertStringParamter(maps); + return sendHttpPost(httpUrl, parem); + } + + + + + /** + * 发送 post请求 发送json数据 + * + * @param httpUrl 地址 + * @param paramsJson 参数(格式 json) + * + */ + public static String sendHttpPostJson(String httpUrl, String paramsJson) { + HttpPost httpPost = new HttpPost(httpUrl);// 创建httpPost + try { + // 设置参数 + if (paramsJson != null && paramsJson.trim().length() > 0) { + StringEntity stringEntity = new StringEntity(paramsJson, "UTF-8"); + stringEntity.setContentType(CONTENT_TYPE_JSON_URL); + httpPost.setEntity(stringEntity); + } + } catch (Exception e) { + e.printStackTrace(); + } + return sendHttpPost(httpPost); + } + + /** + * 发送 post请求 发送xml数据 + * + * @param httpUrl 地址 + * @param paramsXml 参数(格式 Xml) + * + */ + public static String sendHttpPostXml(String httpUrl, String paramsXml) { + HttpPost httpPost = new HttpPost(httpUrl);// 创建httpPost + try { + // 设置参数 + if (paramsXml != null && paramsXml.trim().length() > 0) { + StringEntity stringEntity = new StringEntity(paramsXml, "UTF-8"); + stringEntity.setContentType(CONTENT_TYPE_TEXT_HTML); + httpPost.setEntity(stringEntity); + } + } catch (Exception e) { + e.printStackTrace(); + } + return sendHttpPost(httpPost); + } + + + /** + * 将map集合的键值对转化成:key1=value1&key2=value2 的形式 + * + * @param parameterMap 需要转化的键值对集合 + * @return 字符串 + */ + public static String convertStringParamter(Map parameterMap) { + StringBuffer parameterBuffer = new StringBuffer(); + if (parameterMap != null) { + Iterator iterator = parameterMap.keySet().iterator(); + String key = null; + String value = null; + while (iterator.hasNext()) { + key = (String) iterator.next(); + if (parameterMap.get(key) != null) { + value = (String) parameterMap.get(key); + } else { + value = ""; + } + parameterBuffer.append(key).append("=").append(value); + if (iterator.hasNext()) { + parameterBuffer.append("&"); + } + } + } + return parameterBuffer.toString(); + } + +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/util/ImageUtil.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/util/ImageUtil.java new file mode 100644 index 0000000..4586ad1 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/util/ImageUtil.java @@ -0,0 +1,30 @@ +package com.casic.missiles.modular.system.util; + +import javax.imageio.ImageIO; +import java.awt.*; +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.IOException; + +public class ImageUtil { + public static void main(String[] args) { + BufferedImage bufferedImage; + try { + // read image file + bufferedImage = ImageIO.read(new File("C:\\Users\\zhang\\Desktop\\test.png")); + // create a blank, RGB, same width and height, and a white + // background + BufferedImage newBufferedImage = new BufferedImage( + bufferedImage.getWidth(), bufferedImage.getHeight(), + BufferedImage.TYPE_INT_RGB); + // TYPE_INT_RGB:创建一个RBG图像,24位深度,成功将32位图转化成24位 + newBufferedImage.createGraphics().drawImage(bufferedImage, 0, 0, + Color.WHITE, null); + // write to jpeg file + ImageIO.write(newBufferedImage, "jpg", new File("C:\\Users\\zhang\\Desktop\\test.jpg")); + System.out.println("Done"); + } catch (IOException e) { + e.printStackTrace(); + } + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/util/LocalHostUtil.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/util/LocalHostUtil.java new file mode 100644 index 0000000..1f6c639 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/util/LocalHostUtil.java @@ -0,0 +1,111 @@ +package com.casic.missiles.modular.system.util; + +import java.net.InetAddress; +import java.net.NetworkInterface; +import java.net.SocketException; +import java.net.UnknownHostException; +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.List; + +/** + * 本地主机工具类 + * + * @author zhi + * @since 2019年11月13日09:04:36 + * + */ +public class LocalHostUtil { + + /** + * 获取主机名称 + * + * @return + * @throws UnknownHostException + */ + public static String getHostName() throws UnknownHostException { + return InetAddress.getLocalHost().getHostName(); + } + + /** + * 获取系统首选IP + * + * @return + * @throws UnknownHostException + */ + public static String getLocalIP() throws UnknownHostException { + return InetAddress.getLocalHost().getHostAddress(); + } + + /** + * 获取所有网卡IP,排除回文地址、虚拟地址 + * + * @return + * @throws SocketException + */ + public static String[] getLocalIPs() throws SocketException { + List list = new ArrayList<>(); + Enumeration enumeration = NetworkInterface.getNetworkInterfaces(); + while (enumeration.hasMoreElements()) { + NetworkInterface intf = enumeration.nextElement(); + if (intf.isLoopback() || intf.isVirtual()) { // + continue; + } + Enumeration inets = intf.getInetAddresses(); + while (inets.hasMoreElements()) { + InetAddress addr = inets.nextElement(); + if (addr.isLoopbackAddress() || !addr.isSiteLocalAddress() || addr.isAnyLocalAddress()) { + continue; + } + list.add(addr.getHostAddress()); + } + } + return list.toArray(new String[0]); + } + + /** + * 判断操作系统是否是Windows + * + * @return + */ + public static boolean isWindowsOS() { + boolean isWindowsOS = false; + String osName = System.getProperty("os.name"); + if (osName.toLowerCase().indexOf("windows") > -1) { + isWindowsOS = true; + } + return isWindowsOS; + } + + public static void main(String[] args) { +// try { +// System.out.println("主机是否为Windows系统:" + LocalHostUtil.isWindowsOS()); +// System.out.println("主机名称:" + LocalHostUtil.getHostName()); +// System.out.println("系统首选IP:" + LocalHostUtil.getLocalIP()); +// System.out.println("系统所有IP:" + String.join(",", LocalHostUtil.getLocalIPs())); +// } catch (UnknownHostException e) { +// } catch (Exception e) { +// e.printStackTrace(); +// } + try { + Enumeration faces = NetworkInterface.getNetworkInterfaces(); + while (faces.hasMoreElements()) { // 遍历网络接口 + NetworkInterface face = faces.nextElement(); + if (face.isLoopback() || face.isVirtual() || !face.isUp()) { + continue; + } + System.out.print("网络接口名:" + face.getDisplayName() + ",地址:"); + Enumeration address = face.getInetAddresses(); + while (address.hasMoreElements()) { // 遍历网络地址 + InetAddress addr = address.nextElement(); + if (!addr.isLoopbackAddress() && addr.isSiteLocalAddress() && !addr.isAnyLocalAddress()) { + System.out.print(addr.getHostAddress() + " "); + } + } + System.out.println(""); + } + } catch (SocketException e) { + e.printStackTrace(); + } + } +} diff --git a/casic-iris-register/src/main/java/com/casic/missiles/modular/register/dao/mapping/IrisPersonMapper.xml b/casic-iris-register/src/main/java/com/casic/missiles/modular/register/dao/mapping/IrisPersonMapper.xml new file mode 100644 index 0000000..c974147 --- /dev/null +++ b/casic-iris-register/src/main/java/com/casic/missiles/modular/register/dao/mapping/IrisPersonMapper.xml @@ -0,0 +1,20 @@ + + + + + + + diff --git a/casic-iris-support/src/main/java/com/casic/missiles/modular/system/model/RecognitionRecords.java b/casic-iris-support/src/main/java/com/casic/missiles/modular/system/model/RecognitionRecords.java new file mode 100644 index 0000000..3729383 --- /dev/null +++ b/casic-iris-support/src/main/java/com/casic/missiles/modular/system/model/RecognitionRecords.java @@ -0,0 +1,93 @@ +package com.casic.missiles.modular.system.model; + +import com.baomidou.mybatisplus.activerecord.Model; +import com.baomidou.mybatisplus.annotations.TableField; +import com.baomidou.mybatisplus.annotations.TableId; +import com.baomidou.mybatisplus.annotations.TableName; +import com.baomidou.mybatisplus.enums.IdType; +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +/** + *

+ * + *

+ * + * @author 123 + * @since 2019-12-02 + */ +@Data +@TableName("recognition_records") +public class RecognitionRecords extends Model { + + private static final long serialVersionUID = 1L; + + /** + * 主键 + */ + @TableId(value = "ID", type = IdType.AUTO) + private Long id; + /** + * 原始记录id + */ + @TableField("ORIGINAL_ID") + private Long originalId; + /** + * 对应person表主键 + */ + @TableField("PERSON_ID") + private Long personId; + /** + * 识别时间 + */ + @TableField("DATETIME") + private Date datetime; + /** + * 设备业务编码 + */ + @TableField("DEV_CODE") + private String devCode; + + /** + * 门编码 + */ + @TableField("DOOR_CODE") + private String doorCode; + + /** + * 进出标记 + */ + @TableField("INOUT_TYPE") + private String inoutType; + + @TableField("TEMPERATURE") + private String temperature; + + @TableField("DEV_IP") + private String devIp; + + @TableField("SYNC_TIME") + private Date syncTime; + + @Override + protected Serializable pkVal() { + return this.id; + } + + @Override + public String toString() { + return "RecognitionRecords{" + + "id=" + id + + ", originalId=" + originalId + + ", personId=" + personId + + ", datetime=" + datetime + + ", devCode=" + devCode + + ", doorCode=" + doorCode + + ", inoutType=" + inoutType + + ", devIp=" + devIp + + ", syncTime=" + syncTime + + "}"; + } +} diff --git a/casic-iris-support/src/main/java/com/casic/missiles/modular/system/service/IIrisPersonSupportService.java b/casic-iris-support/src/main/java/com/casic/missiles/modular/system/service/IIrisPersonSupportService.java new file mode 100644 index 0000000..a433b09 --- /dev/null +++ b/casic-iris-support/src/main/java/com/casic/missiles/modular/system/service/IIrisPersonSupportService.java @@ -0,0 +1,9 @@ +package com.casic.missiles.modular.system.service; + +import com.casic.missiles.core.datascope.DataScope; + +import java.util.List; + +public interface IIrisPersonSupportService { + List listIdsByType(DataScope dataScope, String personType); +} diff --git a/casic-face-sync/pom.xml b/casic-face-sync/pom.xml new file mode 100644 index 0000000..24dc884 --- /dev/null +++ b/casic-face-sync/pom.xml @@ -0,0 +1,74 @@ + + + 4.0.0 + + com.casic + casic-iris-parent + 1.0.0-SNAPSHOT + ../pom.xml + + + + casic-face-sync + ${pro.version} + jar + casic-face-sync + + + + + + com.casic + casic-core + ${core.version} + + + + com.casic + casic-admin-support + ${admin.version} + + + com.casic + casic-iris-support + ${pro.version} + + + + org.apache.httpcomponents + httpclient + 4.5.3 + + + + org.apache.httpcomponents + httpcore + 4.4.8 + + + + org.apache.httpcomponents + httpmime + 4.5.3 + + + + com.google.code.gson + gson + + + + + + + + src/main/java + + **/*.xml + + + + + \ No newline at end of file diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/constant/FaceSyncConst.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/constant/FaceSyncConst.java new file mode 100644 index 0000000..352d47d --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/constant/FaceSyncConst.java @@ -0,0 +1,29 @@ +package com.casic.missiles.modular.system.constant; + +public class FaceSyncConst { + + /** + * 单次最大批量上传人员数 + */ + public static final int UPLOAD_MAX_PERSON = 6; + + /** + * 上传人员库 + */ + public static final String UPLOAD_STAFF_LIB = "3"; + public static final String UPLOAD_VISITOR_LIB = "4"; + + public static final String UPLOAD_URL_PREFIX = "/LAPI/V1.0/PeopleLibraries/"; + + public static final String UPLOAD_URL_SUFFIX = "/People"; + + public static final int UPLOAD_PERSONCODE_MAXLENGTH = 15; + + public static final int UPLOAD_REMARK_MAXLENGTH = 63; + + public static final String SUBSCRIBE_URL = "/LAPI/V1.0/System/Event/Subscription/"; + + public static final String STAFF_PERSON_TYPE = "1"; + + public static final String VISITOR_PERSON_TYPE = "0"; +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/controller/FaceSyncController.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/controller/FaceSyncController.java new file mode 100644 index 0000000..1b35431 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/controller/FaceSyncController.java @@ -0,0 +1,117 @@ +package com.casic.missiles.modular.system.controller; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson.serializer.SerializerFeature; +import com.casic.missiles.core.base.response.ResponseData; +import com.casic.missiles.core.common.service.ICommonPermissionService; +import com.casic.missiles.core.common.service.ICommonPersonService; +import com.casic.missiles.core.datascope.DataScope; +import com.casic.missiles.core.util.ToolUtil; +import com.casic.missiles.modular.system.request.PersonInfo; +import com.casic.missiles.modular.system.response.RecordNotification; +import com.casic.missiles.modular.system.service.IFaceSyncService; +import com.casic.missiles.modular.system.service.IIrisPersonSupportService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.*; +import com.casic.missiles.modular.system.constant.FaceSyncConst; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + + + +@Controller +public class FaceSyncController { + private final static Logger logger = LoggerFactory.getLogger(FaceSyncController.class); + + @Autowired + private IFaceSyncService syncService; + @Autowired + private ICommonPersonService commonPersonService; + @Autowired + private IIrisPersonSupportService personSupportService; + @Autowired + private ICommonPermissionService permissionService; + + @RequestMapping("/face/upload") + @ResponseBody + public Object upload(@RequestParam("personIds") List personIds, + @RequestParam("deviceIds") List deviceIds, + @RequestParam("personType")String personType ){ + // 检查数量 +// if(personIds.size()>FaceSyncConst.UPLOAD_MAX_PERSON){ +// return ResponseData.error(String.format("每次最多上传%s个人",FaceSyncConst.UPLOAD_MAX_PERSON)); +// } + // 检查照片格式及大小 + String photoCheck = syncService.checkPersonPhoto(personIds); + if(ToolUtil.isNotEmpty(photoCheck)){ + return ResponseData.error(photoCheck); + } + else{ + // 上传数据 + String error = syncService.uploadPerson(personIds,deviceIds,personType); + if(ToolUtil.isNotEmpty(error)){ + return ResponseData.error(error); + } + } + return ResponseData.success(); + } + + @RequestMapping("/face/uploadAll") + @ResponseBody + public Object uploadAll(@RequestParam("deviceIds") List deviceIds){ + DataScope dataScope = permissionService.getCurrUserDataScope(); + + List staffPersonIds = personSupportService.listIdsByType(dataScope,FaceSyncConst.STAFF_PERSON_TYPE); + List visitorPersonIds = personSupportService.listIdsByType(dataScope,FaceSyncConst.VISITOR_PERSON_TYPE); + // 1.检查照片,分别检查员工、访客 + String staffPhotoCheck = syncService.checkPersonPhoto(staffPersonIds); + if(ToolUtil.isNotEmpty(staffPhotoCheck)){ + return ResponseData.error(staffPhotoCheck); + } + String visitorPhotoCheck = syncService.checkPersonPhoto(visitorPersonIds); + if(ToolUtil.isNotEmpty(visitorPhotoCheck)){ + return ResponseData.error(visitorPhotoCheck); + } + + // 2. 下发数据 + String staffError = syncService.uploadPerson(staffPersonIds,deviceIds,FaceSyncConst.STAFF_PERSON_TYPE); + if(ToolUtil.isNotEmpty(staffError)){ + return ResponseData.error(staffError); + } + String visitorError = syncService.uploadPerson(visitorPersonIds,deviceIds,FaceSyncConst.VISITOR_PERSON_TYPE); + if(ToolUtil.isNotEmpty(visitorError)){ + return ResponseData.error(visitorError); + } + + return ResponseData.success(); + } + + // 错误信息返回 + @RequestMapping("/subsrcibe/init") + @ResponseBody + public Object upload(@RequestParam("deviceIds") List deviceIds){ + String errorMsg = syncService.initSubscription(deviceIds); + if(ToolUtil.isNotEmpty(errorMsg)){ + return ResponseData.error(errorMsg); + } + return ResponseData.success(); + } + + + @RequestMapping(value = "/LAPI/V1.0/System/Event/Notification/PersonVerification", method = RequestMethod.POST) + @ResponseBody + public void verification(@RequestBody String recordNotification){ + logger.info(recordNotification); + RecordNotification record = JSONObject.parseObject(recordNotification,RecordNotification.class); + syncService.receiveRecord(record); + //return ResponseData.success(); + } + + +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FacePersonSyncMapper.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FacePersonSyncMapper.java new file mode 100644 index 0000000..af53702 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FacePersonSyncMapper.java @@ -0,0 +1,17 @@ +package com.casic.missiles.modular.system.dao; + +import com.casic.missiles.modular.system.model.FacePersonSync; +import com.baomidou.mybatisplus.mapper.BaseMapper; + +/** + *

+ * Mapper 接口 + *

+ * + * @author zyj123 + * @since 2020-07-24 + */ +public interface FacePersonSyncMapper extends BaseMapper { + + Long getMaxSyncId(); +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FaceSubscribeMapper.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FaceSubscribeMapper.java new file mode 100644 index 0000000..0c6374a --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/FaceSubscribeMapper.java @@ -0,0 +1,16 @@ +package com.casic.missiles.modular.system.dao; + +import com.casic.missiles.modular.system.model.FaceSubscribe; +import com.baomidou.mybatisplus.mapper.BaseMapper; + +/** + *

+ * Mapper 接口 + *

+ * + * @author zyj123 + * @since 2020-07-25 + */ +public interface FaceSubscribeMapper extends BaseMapper { + +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FacePersonSyncMapper.xml b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FacePersonSyncMapper.xml new file mode 100644 index 0000000..ac46ad0 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FacePersonSyncMapper.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + PERSON_ID AS personId, SYNC_ID AS syncId + + + + + diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FaceSubscribeMapper.xml b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FaceSubscribeMapper.xml new file mode 100644 index 0000000..16024e2 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/dao/mapping/FaceSubscribeMapper.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + SUBSCRIBE_ID AS subscribeId, DEVICE_CODE AS deviceCode, UPDATE_TIME AS updateTime + + + diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FacePersonSync.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FacePersonSync.java new file mode 100644 index 0000000..7cdb821 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FacePersonSync.java @@ -0,0 +1,68 @@ +package com.casic.missiles.modular.system.model; + +import java.io.Serializable; + +import com.baomidou.mybatisplus.annotations.TableId; +import com.baomidou.mybatisplus.annotations.TableField; +import com.baomidou.mybatisplus.activerecord.Model; +import com.baomidou.mybatisplus.annotations.TableName; +import java.io.Serializable; + +/** + *

+ * + *

+ * + * @author zyj123 + * @since 2020-07-24 + */ +@TableName("face_person_sync") +public class FacePersonSync extends Model { + + private static final long serialVersionUID = 1L; + + /** + * 人员id + */ + @TableId("PERSON_ID") + private Long personId; + /** + * 人员同步id + */ + @TableField("SYNC_ID") + private Long syncId; + + public FacePersonSync(Long personId, Long syncId) { + this.personId = personId; + this.syncId = syncId; + } + + public Long getPersonId() { + return personId; + } + + public void setPersonId(Long personId) { + this.personId = personId; + } + + public Long getSyncId() { + return syncId; + } + + public void setSyncId(Long syncId) { + this.syncId = syncId; + } + + @Override + protected Serializable pkVal() { + return this.personId; + } + + @Override + public String toString() { + return "FacePersonSync{" + + "personId=" + personId + + ", syncId=" + syncId + + "}"; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FaceSubscribe.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FaceSubscribe.java new file mode 100644 index 0000000..ccc7792 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/model/FaceSubscribe.java @@ -0,0 +1,79 @@ +package com.casic.missiles.modular.system.model; + +import java.io.Serializable; + +import java.util.Date; +import com.baomidou.mybatisplus.annotations.TableId; +import com.baomidou.mybatisplus.annotations.TableField; +import com.baomidou.mybatisplus.activerecord.Model; +import com.baomidou.mybatisplus.annotations.TableName; +import java.io.Serializable; + +/** + *

+ * + *

+ * + * @author zyj123 + * @since 2020-07-25 + */ +@TableName("face_subscribe") +public class FaceSubscribe extends Model { + + private static final long serialVersionUID = 1L; + + /** + * 订阅id + */ + @TableId("SUBSCRIBE_ID") + private Long subscribeId; + /** + * 设备编号 + */ + @TableField("DEVICE_CODE") + private String deviceCode; + /** + * 更新时间 + */ + @TableField("UPDATE_TIME") + private Date updateTime; + + + public Long getSubscribeId() { + return subscribeId; + } + + public void setSubscribeId(Long subscribeId) { + this.subscribeId = subscribeId; + } + + public String getDeviceCode() { + return deviceCode; + } + + public void setDeviceCode(String deviceCode) { + this.deviceCode = deviceCode; + } + + public Date getUpdateTime() { + return updateTime; + } + + public void setUpdateTime(Date updateTime) { + this.updateTime = updateTime; + } + + @Override + protected Serializable pkVal() { + return this.subscribeId; + } + + @Override + public String toString() { + return "FaceSubscribe{" + + "subscribeId=" + subscribeId + + ", deviceCode=" + deviceCode + + ", updateTime=" + updateTime + + "}"; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/request/PersonInfo.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/request/PersonInfo.java new file mode 100644 index 0000000..80d9eff --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/request/PersonInfo.java @@ -0,0 +1,271 @@ +package com.casic.missiles.modular.system.request; + +import com.alibaba.fastjson.annotation.JSONField; +import com.baomidou.mybatisplus.annotations.TableField; +import com.google.gson.annotations.SerializedName; + +import java.util.List; + +public class PersonInfo { + + //@JSONField(name = "PersonID") + @SerializedName("PersonID") + private Long personID; + + //@JSONField(name = "LastChange") + @SerializedName("LastChange") + private Long lastChange; + + //@JSONField(name = "PersonCode") + @SerializedName("PersonCode") + private String personCode; + + //@JSONField(name = "PersonName") + @SerializedName("PersonName") + private String personName; + + //@JSONField(name = "Remarks") + @SerializedName("Remarks") + private String remarks; + + //@JSONField(name = "TimeTemplateNum") + @SerializedName("TimeTemplateNum") + private Integer timeTemplateNum; + + //@JSONField(name = "TimeTemplateList") + @SerializedName("TimeTemplateList") + private List timeTemplateList; + + //@JSONField(name = "IdentificationNum") + @SerializedName("IdentificationNum") + private Integer identificationNum; + + //@JSONField(name = "IdentificationList") + @SerializedName("IdentificationList") + private List identificationList; + + //@JSONField(name = "ImageNum") + @SerializedName("ImageNum") + private Integer imageNum; + + //@JSONField(name = "ImageList") + @SerializedName("ImageList") + private List imageList; + + public Long getPersonID() { + return personID; + } + + public void setPersonID(Long personID) { + this.personID = personID; + } + + public Long getLastChange() { + return lastChange; + } + + public void setLastChange(Long lastChange) { + this.lastChange = lastChange; + } + + public String getPersonCode() { + return personCode; + } + + public void setPersonCode(String personCode) { + this.personCode = personCode; + } + + public String getPersonName() { + return personName; + } + + public void setPersonName(String personName) { + this.personName = personName; + } + + public String getRemarks() { + return remarks; + } + + public void setRemarks(String remarks) { + this.remarks = remarks; + } + + public Integer getTimeTemplateNum() { + return timeTemplateNum; + } + + public void setTimeTemplateNum(Integer timeTemplateNum) { + this.timeTemplateNum = timeTemplateNum; + } + + public List getTimeTemplateList() { + return timeTemplateList; + } + + public void setTimeTemplateList(List timeTemplateList) { + this.timeTemplateList = timeTemplateList; + } + + public Integer getIdentificationNum() { + return identificationNum; + } + + public void setIdentificationNum(Integer identificationNum) { + this.identificationNum = identificationNum; + } + + public List getIdentificationList() { + return identificationList; + } + + public void setIdentificationList(List identificationList) { + this.identificationList = identificationList; + } + + public Integer getImageNum() { + return imageNum; + } + + public void setImageNum(Integer imageNum) { + this.imageNum = imageNum; + } + + public List getImageList() { + return imageList; + } + + public void setImageList(List imageList) { + this.imageList = imageList; + } + + public class TimeTemplate{ + @JSONField(name = "BeginTime") + private Long beginTime; + @JSONField(name = "EndTime") + private Long endTime; + @JSONField(name = "Index") + private Long index; + + public TimeTemplate(Long beginTime, Long endTime, Long index) { + this.beginTime = beginTime; + this.endTime = endTime; + this.index = index; + } + + public Long getBeginTime() { + return beginTime; + } + + public void setBeginTime(Long beginTime) { + this.beginTime = beginTime; + } + + public Long getEndTime() { + return endTime; + } + + public void setEndTime(Long endTime) { + this.endTime = endTime; + } + + public Long getIndex() { + return index; + } + + public void setIndex(Long index) { + this.index = index; + } + } + + public TimeTemplate createTimeTemplate(Long beginTime, Long endTime, Long index){ + return new TimeTemplate(beginTime, endTime, index); + } + + public class IdentificationInfo { + @JSONField(name = "Type") + private Integer type; + @JSONField(name = "Number") + private String number; + + public IdentificationInfo(Integer type, String number) { + this.type = type; + this.number = number; + } + + public Integer getType() { + return type; + } + + public void setType(Integer type) { + this.type = type; + } + + public String getNumber() { + return number; + } + + public void setNumber(String number) { + this.number = number; + } + } + + public IdentificationInfo createIdentificationInfo(Integer type, String number){ + return new IdentificationInfo(type,number); + } + + public class ImageInfo{ + @JSONField(name = "FaceID") + private Long faceID; + @JSONField(name = "Name") + private String name; + @JSONField(name = "Size") + private Long size; + @JSONField(name = "Data") + private String data; + + public ImageInfo(Long faceID, String name, Long size, String data) { + this.faceID = faceID; + this.name = name; + this.size = size; + this.data = data; + } + + public Long getFaceID() { + return faceID; + } + + public void setFaceID(Long faceID) { + this.faceID = faceID; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Long getSize() { + return size; + } + + public void setSize(Long size) { + this.size = size; + } + + public String getData() { + return data; + } + + public void setData(String data) { + this.data = data; + } + } + + public ImageInfo createImageInfo(Long faceID, String name, Long size, String data){ + return new ImageInfo(faceID, name, size, data); + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceBaseResponse.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceBaseResponse.java new file mode 100644 index 0000000..fe93b8a --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceBaseResponse.java @@ -0,0 +1,90 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; +import com.google.gson.annotations.SerializedName; + +public class FaceBaseResponse { + @JSONField(name = "ResponseURL") + @SerializedName("ResponseURL") + private String responseUrl; + + @JSONField(name = "CreatedID") + @SerializedName("CreatedID") + private int createdId; + + @JSONField(name = "ResponseCode") + @SerializedName("ResponseCode") + private int responseCode; + + @JSONField(name = "ResponseString") + @SerializedName("ResponseString") + private String responseString; + + @JSONField(name = "StatusCode") + @SerializedName("StatusCode") + private int statusCode; + + @JSONField(name = "StatusString") + @SerializedName("StatusString") + private String statusString; + + //@JSONField(name = "Data") + @SerializedName("Data") + private T data; + + public String getResponseUrl() { + return responseUrl; + } + + public void setResponseUrl(String responseUrl) { + this.responseUrl = responseUrl; + } + + public int getCreatedId() { + return createdId; + } + + public void setCreatedId(int createdId) { + this.createdId = createdId; + } + + public int getResponseCode() { + return responseCode; + } + + public void setResponseCode(int responseCode) { + this.responseCode = responseCode; + } + + public String getResponseString() { + return responseString; + } + + public void setResponseString(String responseString) { + this.responseString = responseString; + } + + public int getStatusCode() { + return statusCode; + } + + public void setStatusCode(int statusCode) { + this.statusCode = statusCode; + } + + public String getStatusString() { + return statusString; + } + + public void setStatusString(String statusString) { + this.statusString = statusString; + } + + public T getData() { + return data; + } + + public void setData(T data) { + this.data = data; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceInfo.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceInfo.java new file mode 100644 index 0000000..f128c92 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/FaceInfo.java @@ -0,0 +1,128 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; + +import java.util.List; + +public class FaceInfo { + @JSONField(name = "ID") + private Long id; + @JSONField(name = "Timestamp") + private Long timestamp; + @JSONField(name = "CapSrc") + private Long capSrc; + @JSONField(name = "FeatureNum") + private Long featureNum; + @JSONField(name = "FeatureList") + private List featureList; + @JSONField(name = "FeatureVersion") + private String featureVersion; + @JSONField(name = "Feature") + private String feature; + @JSONField(name = "Temperature") + private Float temperature; + @JSONField(name = "MaskFlag") + private Long maskFlag; + @JSONField(name = "PanoImage") + private Object panoImage; + @JSONField(name = "FaceImage") + private Object faceImage; + @JSONField(name = "FaceArea") + private Object faceArea; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Long getTimestamp() { + return timestamp; + } + + public void setTimestamp(Long timestamp) { + this.timestamp = timestamp; + } + + public Long getCapSrc() { + return capSrc; + } + + public void setCapSrc(Long capSrc) { + this.capSrc = capSrc; + } + + public Long getFeatureNum() { + return featureNum; + } + + public void setFeatureNum(Long featureNum) { + this.featureNum = featureNum; + } + + public List getFeatureList() { + return featureList; + } + + public void setFeatureList(List featureList) { + this.featureList = featureList; + } + + public String getFeatureVersion() { + return featureVersion; + } + + public void setFeatureVersion(String featureVersion) { + this.featureVersion = featureVersion; + } + + public String getFeature() { + return feature; + } + + public void setFeature(String feature) { + this.feature = feature; + } + + public Float getTemperature() { + return temperature; + } + + public void setTemperature(Float temperature) { + this.temperature = temperature; + } + + public Long getMaskFlag() { + return maskFlag; + } + + public void setMaskFlag(Long maskFlag) { + this.maskFlag = maskFlag; + } + + public Object getPanoImage() { + return panoImage; + } + + public void setPanoImage(Object panoImage) { + this.panoImage = panoImage; + } + + public Object getFaceImage() { + return faceImage; + } + + public void setFaceImage(Object faceImage) { + this.faceImage = faceImage; + } + + public Object getFaceArea() { + return faceArea; + } + + public void setFaceArea(Object faceArea) { + this.faceArea = faceArea; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/LibMatInfo.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/LibMatInfo.java new file mode 100644 index 0000000..ce6dd33 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/LibMatInfo.java @@ -0,0 +1,69 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; + +public class LibMatInfo { + @JSONField(name = "ID") + private Long id; + @JSONField(name = "LibID") + private Long libId; + @JSONField(name = "LibType") + private Long libType; + @JSONField(name = "MatchStatus") + private Long matchStatus; + @JSONField(name = "MatchPersonID") + private Long matchPersonId; + @JSONField(name = "MatchFaceID") + private Long matchFaceId; + + // MatchPersonInfo 暂时忽略不用 + + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Long getLibId() { + return libId; + } + + public void setLibId(Long libId) { + this.libId = libId; + } + + public Long getLibType() { + return libType; + } + + public void setLibType(Long libType) { + this.libType = libType; + } + + public Long getMatchStatus() { + return matchStatus; + } + + public void setMatchStatus(Long matchStatus) { + this.matchStatus = matchStatus; + } + + public Long getMatchPersonId() { + return matchPersonId; + } + + public void setMatchPersonId(Long matchPersonId) { + this.matchPersonId = matchPersonId; + } + + public Long getMatchFaceId() { + return matchFaceId; + } + + public void setMatchFaceId(Long matchFaceId) { + this.matchFaceId = matchFaceId; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/PersonResponseData.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/PersonResponseData.java new file mode 100644 index 0000000..186faed --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/PersonResponseData.java @@ -0,0 +1,31 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; +import com.google.gson.annotations.SerializedName; + +import java.util.List; + +public class PersonResponseData { + @JSONField(name = "Num") + @SerializedName("Num") + private int num; + @JSONField(name = "PersonList") + @SerializedName("PersonList") + private List personList; + + public int getNum() { + return num; + } + + public void setNum(int num) { + this.num = num; + } + + public List getPersonList() { + return personList; + } + + public void setPersonList(List personList) { + this.personList = personList; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/PersonResponseInfo.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/PersonResponseInfo.java new file mode 100644 index 0000000..7ba3edc --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/PersonResponseInfo.java @@ -0,0 +1,67 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; +import com.google.gson.annotations.SerializedName; + +import java.util.List; + +public class PersonResponseInfo { + @JSONField(name = "PersonID") + @SerializedName("PersonID") + private Long personId; + @JSONField(name = "FaceNum") + @SerializedName("FaceNum") + private Long faceNum; + @JSONField(name = "FaceList") + @SerializedName("FaceList") + private List faceList; + + public Long getPersonId() { + return personId; + } + + public void setPersonId(Long personId) { + this.personId = personId; + } + + public Long getFaceNum() { + return faceNum; + } + + public void setFaceNum(Long faceNum) { + this.faceNum = faceNum; + } + + public List getFaceList() { + return faceList; + } + + public void setFaceList(List faceList) { + this.faceList = faceList; + } + + public class PersonResponseFace{ + @JSONField(name = "FaceID") + @SerializedName("FaceID") + private Long faceId; + @JSONField(name = "ResultCode") + @SerializedName("ResultCode") + private Long resultCode; + + public Long getFaceId() { + return faceId; + } + + public void setFaceId(Long faceId) { + this.faceId = faceId; + } + + public Long getResultCode() { + return resultCode; + } + + public void setResultCode(Long resultCode) { + this.resultCode = resultCode; + } + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/RecordNotification.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/RecordNotification.java new file mode 100644 index 0000000..ca52d29 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/response/RecordNotification.java @@ -0,0 +1,138 @@ +package com.casic.missiles.modular.system.response; + +import com.alibaba.fastjson.annotation.JSONField; + +import java.util.List; + +public class RecordNotification { + @JSONField(name = "Reference") + private String reference; + @JSONField(name = "Seq") + private int seq; + @JSONField(name = "DeviceCode") + private String deviceCode; + @JSONField(name = "Timestamp") + private Long timestamp; + @JSONField(name = "NotificationType") + private int notificationType; + @JSONField(name = "FaceInfoNum") + private int faceInfoNum; + @JSONField(name = "FaceInfoList") + private List faceInfoList; + @JSONField(name = "CardInfoNum") + private int cardInfoNum; + @JSONField(name = "CardInfoList") + private List cardInfoList; + @JSONField(name = "GateInfoNum") + private int gateInfoNum; + @JSONField(name = "GateInfoList") + private List gateInfoList; + @JSONField(name = "LibMatInfoNum") + private int libMatInfoNum; + @JSONField(name = "LibMatInfoList") + private List libMatInfoList; + + public String getReference() { + return reference; + } + + public void setReference(String reference) { + this.reference = reference; + } + + public int getSeq() { + return seq; + } + + public void setSeq(int seq) { + this.seq = seq; + } + + public String getDeviceCode() { + return deviceCode; + } + + public void setDeviceCode(String deviceCode) { + this.deviceCode = deviceCode; + } + + public Long getTimestamp() { + return timestamp; + } + + public void setTimestamp(Long timestamp) { + this.timestamp = timestamp; + } + + public int getNotificationType() { + return notificationType; + } + + public void setNotificationType(int notificationType) { + this.notificationType = notificationType; + } + + public int getFaceInfoNum() { + return faceInfoNum; + } + + public void setFaceInfoNum(int faceInfoNum) { + this.faceInfoNum = faceInfoNum; + } + + public List getFaceInfoList() { + return faceInfoList; + } + + public void setFaceInfoList(List faceInfoList) { + this.faceInfoList = faceInfoList; + } + + public int getCardInfoNum() { + return cardInfoNum; + } + + public void setCardInfoNum(int cardInfoNum) { + this.cardInfoNum = cardInfoNum; + } + + public List getCardInfoList() { + return cardInfoList; + } + + public void setCardInfoList(List cardInfoList) { + this.cardInfoList = cardInfoList; + } + + public int getGateInfoNum() { + return gateInfoNum; + } + + public void setGateInfoNum(int gateInfoNum) { + this.gateInfoNum = gateInfoNum; + } + + public List getGateInfoList() { + return gateInfoList; + } + + public void setGateInfoList(List gateInfoList) { + this.gateInfoList = gateInfoList; + } + + public int getLibMatInfoNum() { + return libMatInfoNum; + } + + public void setLibMatInfoNum(int libMatInfoNum) { + this.libMatInfoNum = libMatInfoNum; + } + + public List getLibMatInfoList() { + return libMatInfoList; + } + + public void setLibMatInfoList(List libMatInfoList) { + this.libMatInfoList = libMatInfoList; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/runner/InitSubscribeRunner.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/runner/InitSubscribeRunner.java new file mode 100644 index 0000000..c7d0565 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/runner/InitSubscribeRunner.java @@ -0,0 +1,43 @@ +package com.casic.missiles.modular.system.runner; + +import com.casic.missiles.modular.system.model.Device; +import com.casic.missiles.modular.system.service.IDeviceSupportService; +import com.casic.missiles.modular.system.service.IFaceSyncService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.ApplicationArguments; +import org.springframework.boot.ApplicationRunner; +import org.springframework.stereotype.Component; + +import java.util.ArrayList; +import java.util.List; + +@Component +public class InitSubscribeRunner implements ApplicationRunner { + private static Logger logger = LoggerFactory.getLogger(InitSubscribeRunner.class); + + @Value("${iris.face.initSubscribe}") + private String initSubscribe; + @Autowired + private IDeviceSupportService deviceSupportService; + @Autowired + private IFaceSyncService faceSyncService; + + /** + * 启动项目时,根据需要初始化设备订阅信息 + * @param applicationArguments + * @throws Exception + */ + @Override + public void run(ApplicationArguments applicationArguments) throws Exception { + logger.info("==================initSubscribe: "); + if(Boolean.valueOf(initSubscribe)){ + List deviceList = deviceSupportService.selectDeviceByType("5"); + List deviceIds = new ArrayList<>(); + deviceList.forEach(device -> deviceIds.add(Long.valueOf(device.getId()))); + faceSyncService.initSubscription(deviceIds); + } + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFacePersonSyncService.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFacePersonSyncService.java new file mode 100644 index 0000000..6b2461b --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFacePersonSyncService.java @@ -0,0 +1,18 @@ +package com.casic.missiles.modular.system.service; + +import com.casic.missiles.modular.system.model.FacePersonSync; +import com.baomidou.mybatisplus.service.IService; + +/** + *

+ * 服务类 + *

+ * + * @author zyj123 + * @since 2020-07-24 + */ +public interface IFacePersonSyncService extends IService { + Long selectSyncId(Long personId); + Long selectPersonId(Long syncId); + Long getMaxSyncId(Long personId); +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFaceSubscribeService.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFaceSubscribeService.java new file mode 100644 index 0000000..e0461ed --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFaceSubscribeService.java @@ -0,0 +1,24 @@ +package com.casic.missiles.modular.system.service; + +import com.casic.missiles.modular.system.model.FaceSubscribe; +import com.baomidou.mybatisplus.service.IService; + +import java.util.List; + +/** + *

+ * 服务类 + *

+ * + * @author zyj123 + * @since 2020-07-25 + */ +public interface IFaceSubscribeService extends IService { + + List selectSubscribeIdsByDevCode(String devCode); + + boolean deleteByDevCode(String devCode); + + boolean insertSubscribe(Long subscribeId, String devCode); + +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFaceSyncService.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFaceSyncService.java new file mode 100644 index 0000000..effd921 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/IFaceSyncService.java @@ -0,0 +1,21 @@ +package com.casic.missiles.modular.system.service; + +import com.casic.missiles.modular.system.response.RecordNotification; + +import java.util.List; + +public interface IFaceSyncService { + String uploadPerson(List personIds, List deviceIds,String personType); + + String checkPersonPhoto(List personIds); + + void receiveRecord(RecordNotification recordNotification); + + void receiveRecord(String recordNotificationStr); + + String initSubscription(List deviceIds); + + boolean deleteSubscription(String deviceIp, Long subscribeId); + + Long createSubscription(String deviceIp,String ip,String port); +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/Impl/FacePersonSyncServiceImpl.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/Impl/FacePersonSyncServiceImpl.java new file mode 100644 index 0000000..d1d1694 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/Impl/FacePersonSyncServiceImpl.java @@ -0,0 +1,55 @@ +package com.casic.missiles.modular.system.service.Impl; + +import com.baomidou.mybatisplus.mapper.EntityWrapper; +import com.casic.missiles.core.util.ToolUtil; +import com.casic.missiles.modular.system.model.FacePersonSync; +import com.casic.missiles.modular.system.dao.FacePersonSyncMapper; +import com.casic.missiles.modular.system.service.IFacePersonSyncService; +import com.baomidou.mybatisplus.service.impl.ServiceImpl; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +/** + *

+ * 服务实现类 + *

+ * + * @author zyj123 + * @since 2020-07-24 + */ +@Service +public class FacePersonSyncServiceImpl extends ServiceImpl implements IFacePersonSyncService { + + @Override + public Long selectSyncId(Long personId) { + FacePersonSync facePersonSync = this.selectById(personId); + if(ToolUtil.isNotEmpty(facePersonSync)){ + return facePersonSync.getSyncId(); + } + return null; + } + + @Override + public Long selectPersonId(Long syncId) { + EntityWrapper query = new EntityWrapper(); + query.eq("SYNC_ID",syncId); + FacePersonSync facePersonSync = this.selectOne(query); + if(ToolUtil.isNotEmpty(facePersonSync)){ + return facePersonSync.getPersonId(); + } + return null; + } + + @Override + @Transactional + public Long getMaxSyncId(Long personId) { + Long maxId = this.baseMapper.getMaxSyncId(); + if(ToolUtil.isEmpty(maxId)){ + maxId = 1000L; + }else { + maxId = maxId + 1; + } + this.insert(new FacePersonSync(personId,maxId)); + return maxId; + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/Impl/FaceSubscribeServiceImpl.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/Impl/FaceSubscribeServiceImpl.java new file mode 100644 index 0000000..c04302d --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/Impl/FaceSubscribeServiceImpl.java @@ -0,0 +1,52 @@ +package com.casic.missiles.modular.system.service.Impl; + +import com.baomidou.mybatisplus.mapper.EntityWrapper; +import com.casic.missiles.modular.system.model.FaceSubscribe; +import com.casic.missiles.modular.system.dao.FaceSubscribeMapper; +import com.casic.missiles.modular.system.service.IFaceSubscribeService; +import com.baomidou.mybatisplus.service.impl.ServiceImpl; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +/** + *

+ * 服务实现类 + *

+ * + * @author zyj123 + * @since 2020-07-25 + */ +@Service +public class FaceSubscribeServiceImpl extends ServiceImpl implements IFaceSubscribeService { + + @Override + public List selectSubscribeIdsByDevCode(String devCode) { + EntityWrapper query = new EntityWrapper(); + query.eq("DEVICE_CODE",devCode); + List faceSubscribes = this.selectList(query); + List subscribeIds = new ArrayList<>(); + for (FaceSubscribe faceSubscribe : faceSubscribes) { + subscribeIds.add(faceSubscribe.getSubscribeId()); + } + return subscribeIds; + } + + @Override + public boolean deleteByDevCode(String devCode) { + EntityWrapper query = new EntityWrapper(); + query.eq("DEVICE_CODE",devCode); + return this.delete(query); + } + + @Override + public boolean insertSubscribe(Long subscribeId, String devCode) { + FaceSubscribe faceSubscribe = new FaceSubscribe(); + faceSubscribe.setDeviceCode(devCode); + faceSubscribe.setSubscribeId(subscribeId); + faceSubscribe.setUpdateTime(new Date()); + return this.insert(faceSubscribe); + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/Impl/FaceSyncServiceImpl.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/Impl/FaceSyncServiceImpl.java new file mode 100644 index 0000000..8826be5 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/service/Impl/FaceSyncServiceImpl.java @@ -0,0 +1,465 @@ +package com.casic.missiles.modular.system.service.Impl; + +import com.alibaba.fastjson.JSONObject; +import com.casic.missiles.core.common.service.ICommonPersonService; +import com.casic.missiles.core.util.ToolUtil; +import com.casic.missiles.modular.system.model.Device; +import com.casic.missiles.modular.system.model.FacePersonSync; +import com.casic.missiles.modular.system.model.Person; +import com.casic.missiles.modular.system.model.RecognitionRecords; +import com.casic.missiles.modular.system.request.PersonInfo; +import com.casic.missiles.modular.system.response.*; +import com.casic.missiles.modular.system.service.*; +import com.casic.missiles.modular.system.util.HttpClientUtil; +import com.google.gson.*; +import org.apache.commons.lang3.StringUtils; +import org.omg.CORBA.Object; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import com.casic.missiles.modular.system.constant.FaceSyncConst; +import java.net.InetAddress; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +@Service +public class FaceSyncServiceImpl implements IFaceSyncService { + private static final Logger logger = LoggerFactory.getLogger(FaceSyncServiceImpl.class); + + @Autowired + private IFacePersonSyncService personSyncService; + @Autowired + private ICommonPersonService commonPersonService; + @Autowired + private IPersonPhotoSupportService photoSupportService; + @Autowired + private IDeviceSupportService deviceSupportService; + @Autowired + private IRecordSupportService recordSupportService; + @Autowired + private IFaceSubscribeService subscribeService; + @Value("${server.port}") + private String serverPort; + @Value("${iris.face.serverHost}") + private String serverHost; + + @Override + @Transactional + public String uploadPerson(List personIds,List deviceIds,String personType) { + String error = null; + + try{ + List personInfoList = new ArrayList<>(personIds.size()); + for (Long personId : personIds) { + Person person = commonPersonService.getPersonById(personId); + Long syncId = getPersonSyncId(personId); + String photoData = photoSupportService.selectPhotoDataById(personId); + PersonInfo personInfo = convPersonInfo(person,syncId,photoData); + personInfoList.add(personInfo); + } + + + outterLoop : for (Long deviceId : deviceIds) { + Device device = deviceSupportService.selectById(deviceId); + // 批量下发(单次最多6个,分多次下发) + int batchSize = FaceSyncConst.UPLOAD_MAX_PERSON; + int batchNum = (int)Math.ceil((double)personInfoList.size()/batchSize); + for (int i = 0; i < batchNum; i++) { + int fromIndex = i * batchSize; + int toIndex = (i+1) * batchSize <= personInfoList.size() ? (i+1) * batchSize : personInfoList.size(); + List subPersonInfoList = personInfoList.subList(fromIndex,toIndex); + + // 设置上传body对象 + Gson gson = new GsonBuilder().serializeNulls().create(); + JsonObject body = new JsonObject(); + JsonElement person = gson.toJsonTree(subPersonInfoList); + body.addProperty("Num",subPersonInfoList.size()); + body.add("PersonInfoList",person); + String bodyStr = gson.toJson(body); +// logger.info(String.valueOf(subPersonInfoList.size())); + logger.info(bodyStr); + +// 调用接口上传 + String devIp = device.getDevIp(); + String personLib = null; + if("1".equals(personType)){ + personLib = FaceSyncConst.UPLOAD_STAFF_LIB; + }else { + personLib = FaceSyncConst.UPLOAD_VISITOR_LIB; + } + + String url = "http://".concat(devIp).concat(FaceSyncConst.UPLOAD_URL_PREFIX).concat(personLib).concat(FaceSyncConst.UPLOAD_URL_SUFFIX); + String responseContent = HttpClientUtil.sendHttpPost(url,bodyStr); + logger.info(responseContent); + JsonObject obj = gson.fromJson(responseContent, JsonObject.class); + // 解析返回结果 + FaceBaseResponse> response = gson.fromJson(obj.get("Response"),FaceBaseResponse.class); + if(response.getResponseCode() == 0 && response.getStatusCode() == 0){ + PersonResponseData personResponseData = gson.fromJson(gson.toJson(response.getData()),PersonResponseData.class); + List responseInfos = personResponseData.getPersonList(); + for(int j = 0;j < responseInfos.size();j++){ + PersonResponseInfo personResponseInfo = gson.fromJson(gson.toJson(responseInfos.get(j)),PersonResponseInfo.class);; + if(personResponseInfo.getFaceList().get(0).getResultCode() == 0){ + // 成功 + logger.info(String.format("人脸数据下发成功,人员:%s,设备: %s",personResponseInfo.getPersonId(),device.getDevCode())); + }else{ + error = convErrorCode(personResponseInfo.getFaceList().get(0).getResultCode()); + String personName = commonPersonService.getPersonById(personIds.get(i)).getName(); + error = String.format("下发失败,%s %s",personName,error); + logger.error(error); + break outterLoop; + } + } + }else { + if(response.getResponseCode() != 0 ){ + error = String.format("设备%s下发失败: %s",device.getDevCode(),response.getResponseString()); + logger.error(error); + break; + } + if(response.getStatusCode() != 0){ + error = String.format("设备%s下发失败: %s",device.getDevCode(),response.getStatusString()); + logger.error(error); + break; + } + } + } + } + }catch (Exception e){ + e.printStackTrace(); + logger.error(e.getMessage()); + error = "下发失败"; + } + + return error; + } + + private void updatePersonInfoList(List personInfoList,List personIds){ + for (int i = 0; i < personIds.size(); i++) { + Long syncId = personSyncService.selectSyncId(personIds.get(i)); + if(ToolUtil.isNotEmpty(syncId)){ + PersonInfo personInfo = personInfoList.get(i); + personInfo.setPersonID(syncId); + if(ToolUtil.isNotEmpty(personInfo.getImageList())){ + personInfo.getImageList().get(i).setFaceID(syncId); + } + } + } + } + + private Long getPersonSyncId(Long personId){ + Long syncId = personSyncService.selectSyncId(personId); + if(ToolUtil.isEmpty(syncId)){ + syncId = personSyncService.getMaxSyncId(personId); + } + return syncId; + } + + private PersonInfo convPersonInfo(Person person,Long syncId,String photoData){ + PersonInfo personInfo = new PersonInfo(); + if(ToolUtil.isNotEmpty(syncId)){ + personInfo.setPersonID(syncId); + } + if(ToolUtil.isNotEmpty(person.getUpdatetime())){ + personInfo.setLastChange(person.getUpdatetime().getTime()); + } + if(ToolUtil.isNotEmpty(person.getPersonCode()) && person.getPersonCode().length() <= FaceSyncConst.UPLOAD_PERSONCODE_MAXLENGTH){ + personInfo.setPersonCode(person.getPersonCode()); + }else { + personInfo.setPersonCode(String.valueOf(syncId)); + } + if(ToolUtil.isNotEmpty(person.getName())){ + personInfo.setPersonName(person.getName()); + } + if(ToolUtil.isNotEmpty(person.getRemarks()) && person.getRemarks().length() <= FaceSyncConst.UPLOAD_REMARK_MAXLENGTH){ + personInfo.setRemarks(person.getRemarks()); + }else { + personInfo.setRemarks(""); + } + + // 时间模板 + personInfo.setTimeTemplateNum(0); + List timeTemplateList = new ArrayList<>(); + timeTemplateList.add(personInfo.createTimeTemplate(0L,4294967295L,0L)); + personInfo.setTimeTemplateList(timeTemplateList); + + // 证件列表 + if(ToolUtil.isNotEmpty(person.getIdCardNo())){ + personInfo.setIdentificationNum(1); + List identificationInfoList = new ArrayList<>(); + identificationInfoList.add(personInfo.createIdentificationInfo(1,person.getIdCardNo())); + personInfo.setIdentificationList(identificationInfoList); + }else{ + personInfo.setIdentificationNum(0); + } + + // 图片列表 + if(ToolUtil.isNotEmpty(photoData)){ + personInfo.setImageNum(1); + List imageInfoList = new ArrayList<>(); + // 图片base64码 + if(photoData.startsWith("data") || photoData.startsWith("base64")){ + int splitIndex = photoData.indexOf(","); + photoData = photoData.substring(splitIndex+1); + } + imageInfoList.add(personInfo.createImageInfo(syncId,person.getPhoto(),Long.valueOf(photoData.length()),photoData)); + personInfo.setImageList(imageInfoList); + }else { + personInfo.setImageNum(0); + } + return personInfo; + } + + private String convErrorCode(Long errorCode){ + String errorMsg = ""; + switch (errorCode.intValue()){ + case 1000: + errorMsg = "算法初始化失败"; + break; + case 1001: + errorMsg = "人脸检测失败"; + break; + case 1002: + errorMsg = "图片未检测到人脸"; + break; + case 1003: + errorMsg = "jpeg照片解码失败"; + break; + case 1004: + errorMsg = "图片质量分数不满足"; + break; + case 1005: + errorMsg = "图片缩放失败"; + break; + case 1006: + errorMsg = "未启用智能"; + break; + case 1007: + errorMsg = "导入图片过小"; + break; + case 1008: + errorMsg = "导入图片过大"; + break; + case 1009: + errorMsg = "导入图片分辨率超过1920*1080"; + break; + case 1010: + errorMsg = "导入图片不存在"; + break; + case 1011: + errorMsg = "人脸元素个数已达到上限"; + break; + case 1012: + errorMsg = "智能棒算法模型不匹配"; + break; + case 1013: + errorMsg = "人脸导入库成员证件号非法"; + break; + case 1014: + errorMsg = "人脸导入库成员图片格式错误"; + break; + case 1015: + errorMsg = "通道布控已达设备能力上限"; + break; + case 1016: + errorMsg = "其它客户端正在进行操作人脸库"; + break; + case 1017: + errorMsg = "人脸库文件正在更新中"; + break; + case 1018: + errorMsg = "Json反序列化失败"; + break; + case 1019: + errorMsg = "Base64解码失败"; + break; + case 1020: + errorMsg = "人脸照片,编码后的大小和实际接收到的长度不一致,关注Data和Size大小是否正确"; + break; + default: + break; + } + return errorMsg; + + } + + @Override + public String checkPersonPhoto(List personIds) { + String error = null; + for (Long personId : personIds) { + Person person = commonPersonService.getPersonById(personId); + String photoData = photoSupportService.selectPhotoDataById(personId); + if(ToolUtil.isEmpty(photoData)){ + error = String.format("%s 未上传照片",person.getName()); + break; + } + if(photoData.startsWith("data") || photoData.startsWith("base64")){ + int splitIndex = photoData.indexOf(","); + photoData = photoData.substring(splitIndex+1); + } + if(!photoData.startsWith("/9j")){ + error = String.format("%s人员照片不符合要求,必须为jpg格式",person.getName()); + break; + } + + // 找到等号,把等号也去掉 + int equalIndex = photoData.indexOf('='); + if(equalIndex>=0) { + photoData=photoData.substring(0, equalIndex); + } + // 原来的字符流大小,单位为字节 + int strLength=photoData.length(); + // 计算后得到的文件流大小,单位为字节 + int fileLength=Integer.valueOf(strLength-(strLength/8)*2); + if(fileLength / 1024 < 20){ + error = String.format("%s人员照片不符合要求,照片必须大于20Kb",person.getName()); + break; + } + } + return error; + } + + @Override + public void receiveRecord(RecordNotification recordNotification){ +// if(recordNotification.getFaceInfoNum() != recordNotification.getLibMatInfoNum()){ +// logger.error("采集和匹配数据不一致,识别失败"); +// } else { + String deviceCode = recordNotification.getDeviceCode(); + List recordsList = new ArrayList<>(); + for (int i = 0; i < recordNotification.getLibMatInfoNum(); i++) { + //FaceInfo faceInfo = recordNotification.getFaceInfoList().get(i); + LibMatInfo libMatInfo = recordNotification.getLibMatInfoList().get(i); + if(libMatInfo.getMatchStatus() == 1){ + FaceInfo faceInfo = getFaceInfoByMatchId(recordNotification.getFaceInfoList(),libMatInfo.getId()); + Long personId = personSyncService.selectPersonId(libMatInfo.getMatchPersonId()); + if(ToolUtil.isNotEmpty(personId) && ToolUtil.isNotEmpty(faceInfo)){ + RecognitionRecords record = new RecognitionRecords(); + record.setPersonId(personId); + record.setDatetime(new Date(faceInfo.getTimestamp()*1000)); + record.setDevCode(deviceCode); + if(ToolUtil.isNotEmpty(faceInfo.getTemperature())){ + record.setTemperature(String.valueOf(faceInfo.getTemperature())); + } + record.setOriginalId(libMatInfo.getId()); + record.setSyncTime(new Date()); + + Device device = deviceSupportService.selectDeviceByCode(deviceCode); + if(ToolUtil.isNotEmpty(device)){ + if(ToolUtil.isNotEmpty(device.getDevIp())){ + record.setDevIp(device.getDevIp()); + } + } + + recordsList.add(record); + } + } + } + if(ToolUtil.isNotEmpty(recordsList)){ + recordSupportService.insertBatch(recordsList); + } + } + + @Override + public void receiveRecord(String recordNotificationStr) { + RecordNotification recordNotification = JSONObject.parseObject(recordNotificationStr,RecordNotification.class); + receiveRecord(recordNotification); + } + + public FaceInfo getFaceInfoByMatchId(List faceInfoList ,Long id){ + for (FaceInfo faceInfo : faceInfoList) { + if(faceInfo.getId().equals(id)){ + return faceInfo; + } + } + return null; + } + + @Override + public String initSubscription(List deviceIds) { + try { + List error = new ArrayList<>(); + for (Long deviceId : deviceIds) { + Device device = deviceSupportService.selectById(deviceId); + List subscribeIds = subscribeService.selectSubscribeIdsByDevCode(device.getDevCode());; + // 删除所有id + boolean flag = true; + for (Long subscribeId : subscribeIds) { + flag = flag && deleteSubscription(device.getDevIp(),subscribeId); + } + flag = flag && subscribeService.deleteByDevCode(device.getDevCode()); + // 创建订阅 + Long subscribeId = createSubscription(device.getDevIp(),serverHost,serverPort); + flag = flag && ToolUtil.isNotEmpty(subscribeId); + if(ToolUtil.isNotEmpty(subscribeId)){ + flag = flag && subscribeService.insertSubscribe(subscribeId,device.getDevCode()); + } + if(!flag){ + logger.error(String.format("device %s init subsrciption error",device.getDevCode())); + error.add(device.getDevCode()); + } + } + if(ToolUtil.isNotEmpty(error)){ + return StringUtils.join(error,",").concat("订阅失败"); + }else { + return null; + } + }catch (Exception e){ + e.printStackTrace(); + logger.error(e.getMessage()); + return "订阅失败"; + } + + } + + @Override + public boolean deleteSubscription(String deviceIp, Long subscribeId) { + String url = "http://" + deviceIp + FaceSyncConst.SUBSCRIBE_URL + subscribeId; + String responseContent = HttpClientUtil.sendHttpDelete(url); + logger.info(responseContent); + Gson gson = new Gson(); + JsonObject obj = gson.fromJson(responseContent, JsonObject.class); + logger.info(obj.get("Response").toString()); + FaceBaseResponse response = gson.fromJson(obj.get("Response"),FaceBaseResponse.class); + if(response.getResponseCode() == 0 && response.getStatusCode() == 0){ + return true; + }else { + logger.error(String.format("delele subscribe error, device '%s', subscribeId '%s', response '%s', status '%s'",deviceIp,subscribeId,response.getResponseString(),response.getStatusString())); + return false; + } + } + + @Override + public Long createSubscription(String deviceIp, String ip, String port) { + JsonObject request = new JsonObject(); + request.addProperty("AddressType",0); + request.addProperty("IPAddress",ip); + request.addProperty("Port",Long.valueOf(port)); + request.addProperty("Duration",4294967295L); + request.addProperty("Type",1024); + JsonObject subscribePersonCondition = new JsonObject(); + subscribePersonCondition.addProperty("LibIDNum",65535); + subscribePersonCondition.add("LibIDList",new JsonArray()); + request.add("SubscribePersonCondition",subscribePersonCondition); + Gson gson = new Gson(); + String requestStr = gson.toJson(request); + System.out.println(requestStr); + String url = "http://" + deviceIp + FaceSyncConst.SUBSCRIBE_URL ; + String responseContent = HttpClientUtil.sendHttpPostJson(url,requestStr); + logger.info(responseContent); + JsonObject obj = gson.fromJson(responseContent, JsonObject.class); + FaceBaseResponse response = gson.fromJson(obj.get("Response"),FaceBaseResponse.class); + if(response.getResponseCode() == 0 && response.getStatusCode()==0){ + JsonObject data = gson.fromJson(gson.toJson(response.getData()),JsonObject.class); + Long subsrcibeId = data.get("ID").getAsLong(); + logger.info(String.format("create subscribe success, device '%s', subsrcibeId '%s'",deviceIp,subsrcibeId)); + return subsrcibeId; + }else { + logger.error(String.format("create subscribe error, device '%s', response '%s', status '%s'",deviceIp,response.getResponseString(),response.getStatusString())); + return null; + } + } + +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/util/HttpClientUtil.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/util/HttpClientUtil.java new file mode 100644 index 0000000..e258174 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/util/HttpClientUtil.java @@ -0,0 +1,468 @@ +package com.casic.missiles.modular.system.util; + +import java.io.File; +import java.io.IOException; +import java.security.KeyManagementException; +import java.security.KeyStoreException; +import java.security.NoSuchAlgorithmException; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.apache.http.HttpEntity; +import org.apache.http.HttpStatus; +import org.apache.http.client.config.RequestConfig; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpDelete; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.config.Registry; +import org.apache.http.config.RegistryBuilder; +import org.apache.http.conn.socket.ConnectionSocketFactory; +import org.apache.http.conn.socket.PlainConnectionSocketFactory; +import org.apache.http.conn.ssl.SSLConnectionSocketFactory; +import org.apache.http.conn.ssl.SSLContextBuilder; +import org.apache.http.conn.ssl.TrustSelfSignedStrategy; +import org.apache.http.entity.ContentType; +import org.apache.http.entity.StringEntity; +import org.apache.http.entity.mime.MultipartEntityBuilder; +import org.apache.http.entity.mime.content.FileBody; +import org.apache.http.entity.mime.content.StringBody; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.DefaultHttpRequestRetryHandler; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; +import org.apache.http.util.EntityUtils; + +/** + * + * @author H__D + * @date 2016年10月19日 上午11:27:25 + * + */ +public class HttpClientUtil { + + // utf-8字符编码 + public static final String CHARSET_UTF_8 = "utf-8"; + + // HTTP内容类型。 + public static final String CONTENT_TYPE_TEXT_HTML = "text/xml"; + + // HTTP内容类型。相当于form表单的形式,提交数据 + public static final String CONTENT_TYPE_FORM_URL = "application/x-www-form-urlencoded"; + + // HTTP内容类型。相当于form表单的形式,提交数据 + public static final String CONTENT_TYPE_JSON_URL = "application/json;charset=utf-8"; + + + // 连接管理器 + private static PoolingHttpClientConnectionManager pool; + + // 请求配置 + private static RequestConfig requestConfig; + + static { + + try { + //System.out.println("初始化HttpClientTest~~~开始"); + SSLContextBuilder builder = new SSLContextBuilder(); + builder.loadTrustMaterial(null, new TrustSelfSignedStrategy()); + SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory( + builder.build()); + // 配置同时支持 HTTP 和 HTPPS + Registry socketFactoryRegistry = RegistryBuilder. create().register( + "http", PlainConnectionSocketFactory.getSocketFactory()).register( + "https", sslsf).build(); + // 初始化连接管理器 + pool = new PoolingHttpClientConnectionManager( + socketFactoryRegistry); + // 将最大连接数增加到200,实际项目最好从配置文件中读取这个值 + pool.setMaxTotal(200); + // 设置最大路由 + pool.setDefaultMaxPerRoute(2); + // 根据默认超时限制初始化requestConfig + int socketTimeout = 10000; + int connectTimeout = 10000; + int connectionRequestTimeout = 10000; + requestConfig = RequestConfig.custom().setConnectionRequestTimeout( + connectionRequestTimeout).setSocketTimeout(socketTimeout).setConnectTimeout( + connectTimeout).build(); + + //System.out.println("初始化HttpClientTest~~~结束"); + } catch (NoSuchAlgorithmException e) { + e.printStackTrace(); + } catch (KeyStoreException e) { + e.printStackTrace(); + } catch (KeyManagementException e) { + e.printStackTrace(); + } + + + // 设置请求超时时间 + requestConfig = RequestConfig.custom().setSocketTimeout(50000).setConnectTimeout(50000) + .setConnectionRequestTimeout(50000).build(); + } + + public static CloseableHttpClient getHttpClient() { + + CloseableHttpClient httpClient = HttpClients.custom() + // 设置连接池管理 + .setConnectionManager(pool) + // 设置请求配置 + .setDefaultRequestConfig(requestConfig) + // 设置重试次数 + .setRetryHandler(new DefaultHttpRequestRetryHandler(0, false)) + .build(); + + return httpClient; + } + + /** + * 发送Post请求 + * + * @param httpPost + * @return + */ + private static String sendHttpPost(HttpPost httpPost) { + + CloseableHttpClient httpClient = null; + CloseableHttpResponse response = null; + // 响应内容 + String responseContent = null; + try { + // 创建默认的httpClient实例. + httpClient = getHttpClient(); + // 配置请求信息 + httpPost.setConfig(requestConfig); + // 执行请求 + response = httpClient.execute(httpPost); + // 得到响应实例 + HttpEntity entity = response.getEntity(); + + // 可以获得响应头 + // Header[] headers = response.getHeaders(HttpHeaders.CONTENT_TYPE); + // for (Header header : headers) { + // System.out.println(header.getName()); + // } + + // 得到响应类型 + // System.out.println(ContentType.getOrDefault(response.getEntity()).getMimeType()); + + // 判断响应状态 + if (response.getStatusLine().getStatusCode() >= 300) { + throw new Exception( + "HTTP Request is not success, Response code is " + response.getStatusLine().getStatusCode()); + } + + if (HttpStatus.SC_OK == response.getStatusLine().getStatusCode()) { + responseContent = EntityUtils.toString(entity, CHARSET_UTF_8); + EntityUtils.consume(entity); + } + + } catch (Exception e) { + e.printStackTrace(); + } finally { + try { + // 释放资源 + if (response != null) { + response.close(); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + return responseContent; + } + + /** + * 发送Get请求 + * + * @param httpGet + * @return + */ + private static String sendHttpGet(HttpGet httpGet) { + + CloseableHttpClient httpClient = null; + CloseableHttpResponse response = null; + // 响应内容 + String responseContent = null; + try { + // 创建默认的httpClient实例. + httpClient = getHttpClient(); + // 配置请求信息 + httpGet.setConfig(requestConfig); + // 执行请求 + response = httpClient.execute(httpGet); + // 得到响应实例 + HttpEntity entity = response.getEntity(); + + // 可以获得响应头 + // Header[] headers = response.getHeaders(HttpHeaders.CONTENT_TYPE); + // for (Header header : headers) { + // System.out.println(header.getName()); + // } + + // 得到响应类型 + // System.out.println(ContentType.getOrDefault(response.getEntity()).getMimeType()); + + // 判断响应状态 + if (response.getStatusLine().getStatusCode() >= 300) { + throw new Exception( + "HTTP Request is not success, Response code is " + response.getStatusLine().getStatusCode()); + } + + if (HttpStatus.SC_OK == response.getStatusLine().getStatusCode()) { + responseContent = EntityUtils.toString(entity, CHARSET_UTF_8); + EntityUtils.consume(entity); + } + + } catch (Exception e) { + e.printStackTrace(); + } finally { + try { + // 释放资源 + if (response != null) { + response.close(); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + return responseContent; + } + + /** + * 发送Delete请求 + * + * @param httpDelete + * @return + */ + private static String sendHttpDelete(HttpDelete httpDelete) { + + CloseableHttpClient httpClient = null; + CloseableHttpResponse response = null; + // 响应内容 + String responseContent = null; + try { + // 创建默认的httpClient实例. + httpClient = getHttpClient(); + // 配置请求信息 + httpDelete.setConfig(requestConfig); + // 执行请求 + response = httpClient.execute(httpDelete); + // 得到响应实例 + HttpEntity entity = response.getEntity(); + + // 可以获得响应头 + // Header[] headers = response.getHeaders(HttpHeaders.CONTENT_TYPE); + // for (Header header : headers) { + // System.out.println(header.getName()); + // } + + // 得到响应类型 + // System.out.println(ContentType.getOrDefault(response.getEntity()).getMimeType()); + + // 判断响应状态 + if (response.getStatusLine().getStatusCode() >= 300) { + throw new Exception( + "HTTP Request is not success, Response code is " + response.getStatusLine().getStatusCode()); + } + + if (HttpStatus.SC_OK == response.getStatusLine().getStatusCode()) { + responseContent = EntityUtils.toString(entity, CHARSET_UTF_8); + EntityUtils.consume(entity); + } + + } catch (Exception e) { + e.printStackTrace(); + } finally { + try { + // 释放资源 + if (response != null) { + response.close(); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + return responseContent; + } + + + + /** + * 发送 post请求 + * + * @param httpUrl 地址 + */ + public static String sendHttpPost(String httpUrl) { + // 创建httpPost + HttpPost httpPost = new HttpPost(httpUrl); + return sendHttpPost(httpPost); + } + + /** + * 发送 get请求 + * + * @param httpUrl + */ + public static String sendHttpGet(String httpUrl) { + // 创建get请求 + HttpGet httpGet = new HttpGet(httpUrl); + return sendHttpGet(httpGet); + } + + /** + * 发送 DELETE 请求 + * + * @param httpUrl + */ + public static String sendHttpDelete(String httpUrl) { + // 创建delete请求 + HttpDelete httpDelete = new HttpDelete(httpUrl); + return sendHttpDelete(httpDelete); + } + + + + /** + * 发送 post请求(带文件) + * + * @param httpUrl + * 地址 + * @param maps + * 参数 + * @param fileLists + * 附件 + */ + public static String sendHttpPost(String httpUrl, Map maps, List fileLists) { + HttpPost httpPost = new HttpPost(httpUrl);// 创建httpPost + MultipartEntityBuilder meBuilder = MultipartEntityBuilder.create(); + if (maps != null) { + for (String key : maps.keySet()) { + meBuilder.addPart(key, new StringBody(maps.get(key), ContentType.TEXT_PLAIN)); + } + } + if (fileLists != null) { + for (File file : fileLists) { + FileBody fileBody = new FileBody(file); + meBuilder.addPart("files", fileBody); + } + } + HttpEntity reqEntity = meBuilder.build(); + httpPost.setEntity(reqEntity); + return sendHttpPost(httpPost); + } + + /** + * 发送 post请求 + * + * @param httpUrl + * 地址 + * @param params + * 参数(格式:key1=value1&key2=value2) + * + */ + public static String sendHttpPost(String httpUrl, String params) { + HttpPost httpPost = new HttpPost(httpUrl);// 创建httpPost + try { + // 设置参数 + if (params != null && params.trim().length() > 0) { + StringEntity stringEntity = new StringEntity(params, "UTF-8"); + stringEntity.setContentType(CONTENT_TYPE_FORM_URL); + httpPost.setEntity(stringEntity); + } + } catch (Exception e) { + throw e; + } + return sendHttpPost(httpPost); + } + + /** + * 发送 post请求 + * + * @param maps + * 参数 + */ + public static String sendHttpPost(String httpUrl, Map maps) { + String parem = convertStringParamter(maps); + return sendHttpPost(httpUrl, parem); + } + + + + + /** + * 发送 post请求 发送json数据 + * + * @param httpUrl 地址 + * @param paramsJson 参数(格式 json) + * + */ + public static String sendHttpPostJson(String httpUrl, String paramsJson) { + HttpPost httpPost = new HttpPost(httpUrl);// 创建httpPost + try { + // 设置参数 + if (paramsJson != null && paramsJson.trim().length() > 0) { + StringEntity stringEntity = new StringEntity(paramsJson, "UTF-8"); + stringEntity.setContentType(CONTENT_TYPE_JSON_URL); + httpPost.setEntity(stringEntity); + } + } catch (Exception e) { + e.printStackTrace(); + } + return sendHttpPost(httpPost); + } + + /** + * 发送 post请求 发送xml数据 + * + * @param httpUrl 地址 + * @param paramsXml 参数(格式 Xml) + * + */ + public static String sendHttpPostXml(String httpUrl, String paramsXml) { + HttpPost httpPost = new HttpPost(httpUrl);// 创建httpPost + try { + // 设置参数 + if (paramsXml != null && paramsXml.trim().length() > 0) { + StringEntity stringEntity = new StringEntity(paramsXml, "UTF-8"); + stringEntity.setContentType(CONTENT_TYPE_TEXT_HTML); + httpPost.setEntity(stringEntity); + } + } catch (Exception e) { + e.printStackTrace(); + } + return sendHttpPost(httpPost); + } + + + /** + * 将map集合的键值对转化成:key1=value1&key2=value2 的形式 + * + * @param parameterMap 需要转化的键值对集合 + * @return 字符串 + */ + public static String convertStringParamter(Map parameterMap) { + StringBuffer parameterBuffer = new StringBuffer(); + if (parameterMap != null) { + Iterator iterator = parameterMap.keySet().iterator(); + String key = null; + String value = null; + while (iterator.hasNext()) { + key = (String) iterator.next(); + if (parameterMap.get(key) != null) { + value = (String) parameterMap.get(key); + } else { + value = ""; + } + parameterBuffer.append(key).append("=").append(value); + if (iterator.hasNext()) { + parameterBuffer.append("&"); + } + } + } + return parameterBuffer.toString(); + } + +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/util/ImageUtil.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/util/ImageUtil.java new file mode 100644 index 0000000..4586ad1 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/util/ImageUtil.java @@ -0,0 +1,30 @@ +package com.casic.missiles.modular.system.util; + +import javax.imageio.ImageIO; +import java.awt.*; +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.IOException; + +public class ImageUtil { + public static void main(String[] args) { + BufferedImage bufferedImage; + try { + // read image file + bufferedImage = ImageIO.read(new File("C:\\Users\\zhang\\Desktop\\test.png")); + // create a blank, RGB, same width and height, and a white + // background + BufferedImage newBufferedImage = new BufferedImage( + bufferedImage.getWidth(), bufferedImage.getHeight(), + BufferedImage.TYPE_INT_RGB); + // TYPE_INT_RGB:创建一个RBG图像,24位深度,成功将32位图转化成24位 + newBufferedImage.createGraphics().drawImage(bufferedImage, 0, 0, + Color.WHITE, null); + // write to jpeg file + ImageIO.write(newBufferedImage, "jpg", new File("C:\\Users\\zhang\\Desktop\\test.jpg")); + System.out.println("Done"); + } catch (IOException e) { + e.printStackTrace(); + } + } +} diff --git a/casic-face-sync/src/main/java/com/casic/missiles/modular/system/util/LocalHostUtil.java b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/util/LocalHostUtil.java new file mode 100644 index 0000000..1f6c639 --- /dev/null +++ b/casic-face-sync/src/main/java/com/casic/missiles/modular/system/util/LocalHostUtil.java @@ -0,0 +1,111 @@ +package com.casic.missiles.modular.system.util; + +import java.net.InetAddress; +import java.net.NetworkInterface; +import java.net.SocketException; +import java.net.UnknownHostException; +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.List; + +/** + * 本地主机工具类 + * + * @author zhi + * @since 2019年11月13日09:04:36 + * + */ +public class LocalHostUtil { + + /** + * 获取主机名称 + * + * @return + * @throws UnknownHostException + */ + public static String getHostName() throws UnknownHostException { + return InetAddress.getLocalHost().getHostName(); + } + + /** + * 获取系统首选IP + * + * @return + * @throws UnknownHostException + */ + public static String getLocalIP() throws UnknownHostException { + return InetAddress.getLocalHost().getHostAddress(); + } + + /** + * 获取所有网卡IP,排除回文地址、虚拟地址 + * + * @return + * @throws SocketException + */ + public static String[] getLocalIPs() throws SocketException { + List list = new ArrayList<>(); + Enumeration enumeration = NetworkInterface.getNetworkInterfaces(); + while (enumeration.hasMoreElements()) { + NetworkInterface intf = enumeration.nextElement(); + if (intf.isLoopback() || intf.isVirtual()) { // + continue; + } + Enumeration inets = intf.getInetAddresses(); + while (inets.hasMoreElements()) { + InetAddress addr = inets.nextElement(); + if (addr.isLoopbackAddress() || !addr.isSiteLocalAddress() || addr.isAnyLocalAddress()) { + continue; + } + list.add(addr.getHostAddress()); + } + } + return list.toArray(new String[0]); + } + + /** + * 判断操作系统是否是Windows + * + * @return + */ + public static boolean isWindowsOS() { + boolean isWindowsOS = false; + String osName = System.getProperty("os.name"); + if (osName.toLowerCase().indexOf("windows") > -1) { + isWindowsOS = true; + } + return isWindowsOS; + } + + public static void main(String[] args) { +// try { +// System.out.println("主机是否为Windows系统:" + LocalHostUtil.isWindowsOS()); +// System.out.println("主机名称:" + LocalHostUtil.getHostName()); +// System.out.println("系统首选IP:" + LocalHostUtil.getLocalIP()); +// System.out.println("系统所有IP:" + String.join(",", LocalHostUtil.getLocalIPs())); +// } catch (UnknownHostException e) { +// } catch (Exception e) { +// e.printStackTrace(); +// } + try { + Enumeration faces = NetworkInterface.getNetworkInterfaces(); + while (faces.hasMoreElements()) { // 遍历网络接口 + NetworkInterface face = faces.nextElement(); + if (face.isLoopback() || face.isVirtual() || !face.isUp()) { + continue; + } + System.out.print("网络接口名:" + face.getDisplayName() + ",地址:"); + Enumeration address = face.getInetAddresses(); + while (address.hasMoreElements()) { // 遍历网络地址 + InetAddress addr = address.nextElement(); + if (!addr.isLoopbackAddress() && addr.isSiteLocalAddress() && !addr.isAnyLocalAddress()) { + System.out.print(addr.getHostAddress() + " "); + } + } + System.out.println(""); + } + } catch (SocketException e) { + e.printStackTrace(); + } + } +} diff --git a/casic-iris-register/src/main/java/com/casic/missiles/modular/register/dao/mapping/IrisPersonMapper.xml b/casic-iris-register/src/main/java/com/casic/missiles/modular/register/dao/mapping/IrisPersonMapper.xml new file mode 100644 index 0000000..c974147 --- /dev/null +++ b/casic-iris-register/src/main/java/com/casic/missiles/modular/register/dao/mapping/IrisPersonMapper.xml @@ -0,0 +1,20 @@ + + + + + + + diff --git a/casic-iris-support/src/main/java/com/casic/missiles/modular/system/model/RecognitionRecords.java b/casic-iris-support/src/main/java/com/casic/missiles/modular/system/model/RecognitionRecords.java new file mode 100644 index 0000000..3729383 --- /dev/null +++ b/casic-iris-support/src/main/java/com/casic/missiles/modular/system/model/RecognitionRecords.java @@ -0,0 +1,93 @@ +package com.casic.missiles.modular.system.model; + +import com.baomidou.mybatisplus.activerecord.Model; +import com.baomidou.mybatisplus.annotations.TableField; +import com.baomidou.mybatisplus.annotations.TableId; +import com.baomidou.mybatisplus.annotations.TableName; +import com.baomidou.mybatisplus.enums.IdType; +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +/** + *

+ * + *

+ * + * @author 123 + * @since 2019-12-02 + */ +@Data +@TableName("recognition_records") +public class RecognitionRecords extends Model { + + private static final long serialVersionUID = 1L; + + /** + * 主键 + */ + @TableId(value = "ID", type = IdType.AUTO) + private Long id; + /** + * 原始记录id + */ + @TableField("ORIGINAL_ID") + private Long originalId; + /** + * 对应person表主键 + */ + @TableField("PERSON_ID") + private Long personId; + /** + * 识别时间 + */ + @TableField("DATETIME") + private Date datetime; + /** + * 设备业务编码 + */ + @TableField("DEV_CODE") + private String devCode; + + /** + * 门编码 + */ + @TableField("DOOR_CODE") + private String doorCode; + + /** + * 进出标记 + */ + @TableField("INOUT_TYPE") + private String inoutType; + + @TableField("TEMPERATURE") + private String temperature; + + @TableField("DEV_IP") + private String devIp; + + @TableField("SYNC_TIME") + private Date syncTime; + + @Override + protected Serializable pkVal() { + return this.id; + } + + @Override + public String toString() { + return "RecognitionRecords{" + + "id=" + id + + ", originalId=" + originalId + + ", personId=" + personId + + ", datetime=" + datetime + + ", devCode=" + devCode + + ", doorCode=" + doorCode + + ", inoutType=" + inoutType + + ", devIp=" + devIp + + ", syncTime=" + syncTime + + "}"; + } +} diff --git a/casic-iris-support/src/main/java/com/casic/missiles/modular/system/service/IIrisPersonSupportService.java b/casic-iris-support/src/main/java/com/casic/missiles/modular/system/service/IIrisPersonSupportService.java new file mode 100644 index 0000000..a433b09 --- /dev/null +++ b/casic-iris-support/src/main/java/com/casic/missiles/modular/system/service/IIrisPersonSupportService.java @@ -0,0 +1,9 @@ +package com.casic.missiles.modular.system.service; + +import com.casic.missiles.core.datascope.DataScope; + +import java.util.List; + +public interface IIrisPersonSupportService { + List listIdsByType(DataScope dataScope, String personType); +} diff --git a/casic-iris-support/src/main/java/com/casic/missiles/modular/system/service/IPersonPhotoSupportService.java b/casic-iris-support/src/main/java/com/casic/missiles/modular/system/service/IPersonPhotoSupportService.java new file mode 100644 index 0000000..9205c92 --- /dev/null +++ b/casic-iris-support/src/main/java/com/casic/missiles/modular/system/service/IPersonPhotoSupportService.java @@ -0,0 +1,5 @@ +package com.casic.missiles.modular.system.service; + +public interface IPersonPhotoSupportService { + String selectPhotoDataById(Long personId); +}